请列出STM32F103的I2C发送与接收函数与STM32F072的I2C发送与接受函数的不同点
时间: 2024-06-04 18:08:13 浏览: 13
STM32F103的I2C发送与接收函数是基于标准库的,常用的函数有:
- `void I2C_Init(I2C_TypeDef* I2Cx, uint32_t ClockSpeed, uint16_t OwnAddress, uint16_t OwnAddressSize, uint16_t AddressingMode, uint16_t DualAddressMode, uint16_t GeneralCallMode, uint16_t NOSTRETCH_MODE)`
- `void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState)`
- `void I2C_GenerateSTART(I2C_TypeDef* I2Cx, FunctionalState NewState)`
- `void I2C_SendData(I2C_TypeDef* I2Cx, uint8_t Data)`
- `uint8_t I2C_ReceiveData(I2C_TypeDef* I2Cx)`
- `void I2C_AcknowledgeConfig(I2C_TypeDef* I2Cx, FunctionalState NewState)`
- `void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState)`
其中,`I2C_Init`函数用于初始化I2C总线,`I2C_Cmd`函数用于使能或禁止I2C总线,`I2C_GenerateSTART`函数用于产生起始信号,`I2C_SendData`函数用于发送数据,`I2C_ReceiveData`函数用于接收数据,`I2C_AcknowledgeConfig`函数用于配置应答位,`I2C_GenerateSTOP`函数用于产生停止信号。
STM32F072的I2C发送与接收函数也是基于标准库的,但是与STM32F103的函数有所不同,常用的函数有:
- `void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c)`
- `HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout)`
- `HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout)`
- `HAL_StatusTypeDef HAL_I2C_Slave_Transmit(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout)`
- `HAL_StatusTypeDef HAL_I2C_Slave_Receive(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout)`
其中,`HAL_I2C_MspInit`函数用于初始化I2C总线,`HAL_I2C_Master_Transmit`函数用于主机发送数据,`HAL_I2C_Master_Receive`函数用于主机接收数据,`HAL_I2C_Slave_Transmit`函数用于从机发送数据,`HAL_I2C_Slave_Receive`函数用于从机接收数据。此外,这些函数还具有超时机制,以及更加高级的错误处理和回调机制。
因此,STM32F103的I2C发送与接收函数与STM32F072的I2C发送与接收函数的不同点在于函数名称、参数及其实现方式。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)