I2C(Inter-Integrated Circuit)总线是一种
两线式串行总线,用于连接微控制器
及其外围设备。和SPI一样,也是一种常用的串行通信方式。
STM32微控制器提供硬件I2C,对它进行相应配置就可以用来进行多个设备之间的通信。
使用步骤:
1. Enable peripheral clock
2. Enable SDA, SCL and SMBA (when used) GPIO clocks
3. Peripherals alternate function: Call GPIO_Init() function.
4. Program the Mode, Timing , Own address, Ack and Acknowledged Address using the I2C_Init() function.
5. Enable the NVIC and the corresponding interrupt
if you need to use interrupt mode.
7. When using the DMA mode Configure the DMA
8. Enable the I2C using the I2C_Cmd() function.
9. Enable the DMA when using DMA mode in the transfers.
基于STM32F3discovery开发板
MCU:STM32F303VC作为主机
从机”LSM303DL

最低0.47元/天 解锁文章
814





