|
本帖最后由 68336016 于 2016-11-30 12:52 编辑
MCP3421是个模数转换芯片,最早我是看论坛老杨做的表头上用过,觉得挺不错的,刚好自己这次做板就用上了。
使用起来很简单,就是I2C总线而已,找个以前代码修修改改就行,所以没任何技术含量,仅供入门新手偷懒参考一下
修改文件开头的宏,将SCK,SDA引脚设置正确就行,我的STM32 48MHZ,模拟I2C时钟大概100KHZ。
调用MCP3421_Init()初始化,
调用MCP3421_WriteByte(u8 WriteAddr, u8 data)配置,
调用 MCP3421_ReadBytes(u8* pBuffer, u8 ReadAddr, u16 NumByteToRead)读取AD值。
- /*******************************************************************************
- * 文件名 : mcp3421.h
- * 作 者 :
- * 版 本 :
- * 日 期 : 2016-11-17
- * 描 述 : mcp3421函数
- *******************************************************************************/
- /* Define to prevent recursive inclusion -------------------------------------*/
- #ifndef __MCP3421_H
- #define __MCP3421_H
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f10x_lib.h"
- /* Exported types ------------------------------------------------------------*/
- /* Exported variables --------------------------------------------------------*/
- /* Exported constants --------------------------------------------------------*/
- /* Exported macro ------------------------------------------------------------*/
- /* Exported functions ------------------------------------------------------- */
- void MCP3421_Init(void);
- void I2C_StartBit(void);
- void I2C_StopBit(void);
- void I2C_SendBit(u8);
- u8 I2C_SendByte(u8);
- u8 I2C_ReceiveBit(void);
- u8 I2C_ReceiveByte(u8);
- void I2C_Delay(u16);
- void I2C_Config(void);
- bool MCP3421_WriteByte(u8 WriteAddr, u8 data);
- bool MCP3421_ReadBytes(u8* pBuffer, u8 ReadAddr, u16 NumByteToRead);
- #endif
- /*********************************END OF FILE*********************************/
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
月入3000的是反美的。收入3万是亲美的。收入30万是移民美国的。收入300万是取得绿卡后回国,教唆那些3000来反美的!
|