- 打开框架层支持
- board.h中打开宏定义,并根据原理图设定IO口
#define BSP_USING_I2C1
#ifdef BSP_USING_I2C1
#define BSP_I2C1_SCL_PIN 22 //PB6
#define BSP_I2C1_SDA_PIN 23 //PB7
#endif
- 完成,编译下载
- 因为I2C驱动中带有历程,可以通过msh进行下测试,注意第一步要抽象at24cxx为块设备,之后再进行读写操作
msh />list_device
device type ref count
-------- -------------------- ----------
w25q128 Block Device 0
spi20 SPI Device 0
spi2 SPI Bus 0
i2c1 I2C Bus 0
uart1 Character Device 2
pin Miscellaneous Device 0
msh />
msh />
msh />at24cxx probe i2c1
msh />at24cxx write
write ok
msh />at24cxx read
read at24cxx : WELCOM TO RTT
msh />
- 添加at24cxx软件包
- 修改头文件,对应芯片
注意:
AT24Cxx芯片进行数据写入操作时,尽量使用页写(连续写入)函数,使用字节写入时,写入时间过长,修改延时会导致写入数据错误。