// state: 0 -> LED on, 1 -> LED off
void i2c0_write_pin(uint8_t reg, uint8_t read_data, uint8_t pin, uint8_t state)
{
if (state)
{
read_data |= (1 << pin);
}
else
{
read_data &= (~(1 << pin));
}
I2C_START(I2C0);
I2C_WAIT_READY(I2C0);
I2C_SET_DATA(I2C0, TCA6424A_IIC_ADDR << 1 | 0);
I2C_SET_CONTROL_REG(I2C0, I2C_I2CON_SI);
I2C_WAIT_READY(I2C0);
I2C_SET_DATA(I2C0, reg);
I2C_SET_CONTROL_REG(I2C0, I2C_I2CON_SI);
I2C_WAIT_READY(I2C0);
I2C_SET_DATA(I2C0, read_data);
I2C_SET_CONTROL_REG(I2C0, I2C_I2CON_SI);
I2C_WAIT_READY(I2C0);
I2C_STOP(I2C0);
}
参考的github上的一个例子
https://github.com/hoangvanthinh/TULA_ROM_auto_MCU/blob/master/Library/NuMakerLib/Source/I2Cdev.c
但是这个写函数无法将tca6424a的扩展io口led灯点亮,如果使用软件模拟i2c,则可以点亮led灯,请问我的写程序错在哪里呢? |