使用RT-Thread Studio,点亮软件IIC,
保存后编译,会出现报错,这是因为我们还需要修改board.h,
/*-------------------------- I2C CONFIG BEGIN --------------------------*/
/** if you want to use i2c bus(soft simulate) you can use the following instructions.
*
* STEP 1, open i2c driver framework(soft simulate) support in the RT-Thread Settings file
*
* STEP 2, define macro related to the i2c bus
* such as #define BSP_USING_I2C1
*
* STEP 3, according to the corresponding pin of i2c port, modify the related i2c port and pin information
* such as #define BSP_I2C1_SCL_PIN GET_PIN(port, pin) -> GET_PIN(C, 11)
* #define BSP_I2C1_SDA_PIN GET_PIN(port, pin) -> GET_PIN(C, 12)
*/
/*#define BSP_USING_I2C1*/
#define BSP_USING_I2C1
#ifdef BSP_USING_I2C1
#define BSP_I2C1_SCL_PIN GET_PIN(B, 6)
#define BSP_I2C1_SDA_PIN GET_PIN(B, 7)
#endif
/*#define BSP_USING_I2C2*/
#ifdef BSP_USING_I2C2
#define BSP_I2C2_SCL_PIN GET_PIN(port, pin)
#define BSP_I2C2_SDA_PIN GET_PIN(port, pin)
#endif
如上,需要在board.h中打开 BSP_USING_I2C1(根据项目需求打开对应的I2C宏定义),然后通过修改 BSP_I2C1_SCL_PIN和BSP_I2C1_SDA_PIN来指定I2C使用具体引脚,此时再次编译就不会报错。
下载后,在Finsh中使用list_device命令,可以看到I2C设备已经检测到,