我的程序如下:
unsigned int test = 0;
dataToSlave[0] = 0x55;
dataToSlave[1] = 0x11;
dataToSlave[3] = 0x56;
//管脚复用配置
I2CPinMuxSetup(0);
//复位模块
I2CMasterDisable(SOC_I2C_0_REGS);
//时钟配置Configure i2c bus speed to 100khz
I2CMasterInitExpClk(SOC_I2C_0_REGS, 24000000, 8000000, 100000);
//Set i2c slave address
I2CMasterSlaveAddrSet(SOC_I2C_0_REGS, I2C_SLAVE_ADDR);
I2CMasterEnable(SOC_I2C_0_REGS);
//写数据
I2CSetDataCount(SOC_I2C_0_REGS, 3);
I2CMasterControl(SOC_I2C_0_REGS, I2C_CFG_MST_TX | I2C_CFG_STOP);
I2CMasterIntEnableEx(SOC_I2C_0_REGS, I2C_INT_TRANSMIT_READY|I2C_INT_DATA_READY|I2C_INT_STOP_CONDITION);
// Generate start condition on i2c bus
I2CMasterStart(SOC_I2C_0_REGS);
while(!(I2CMasterIntStatus(SOC_I2C_0_REGS)&I2C_ICSTR_ICXRDY)){};
I2CMasterDataPut(SOC_I2C_0_REGS, dataToSlave[0]); //地址
while(!(I2CMasterIntStatus(SOC_I2C_0_REGS)&I2C_ICSTR_ICXRDY)){};
I2CMasterDataPut(SOC_I2C_0_REGS, dataToSlave[1]); //地址
while(!(I2CMasterIntStatus(SOC_I2C_0_REGS)&I2C_ICSTR_ICXRDY)){};
I2CMasterDataPut(SOC_I2C_0_REGS, dataToSlave[3]);//数据
I2CStatusClear(SOC_I2C_0_REGS, (I2C_CLEAR_DATA_READY | I2C_CLEAR_TRANSMIT_READY | I2C_CLEAR_STOP_CONDITION));
//读数据
while(I2CMasterBusBusy(SOC_I2C_0_REGS));
I2CMasterControl(SOC_I2C_0_REGS, I2C_CFG_MST_TX);
I2CMasterIntEnableEx(SOC_I2C_0_REGS, I2C_INT_TRANSMIT_READY|I2C_INT_DATA_READY);
I2CMasterStart(SOC_I2C_0_REGS);
while(!(I2CMasterIntStatus(SOC_I2C_0_REGS)&I2C_ICSTR_ICXRDY)){};
I2CMasterDataPut(SOC_I2C_0_REGS, dataToSlave[0]);
while(!(I2CMasterIntStatus(SOC_I2C_0_REGS)&I2C_ICSTR_ICXRDY)){};
I2CMasterDataPut(SOC_I2C_0_REGS, dataToSlave[1]);
//以上是写入要读取的地址
while(!(I2CMasterIntStatus(SOC_I2C_0_REGS)&I2C_ICSTR_ICXRDY)){};
I2CSetDataCount(SOC_I2C_0_REGS, 1);
I2CMasterControl(SOC_I2C_0_REGS, I2C_CFG_MST_RX | I2C_CFG_STOP);
I2CMasterIntEnableEx(SOC_I2C_0_REGS, I2C_INT_DATA_READY | I2C_INT_STOP_CONDITION );
I2CMasterStart(SOC_I2C_0_REGS);
while(!(I2CMasterIntStatus(SOC_I2C_0_REGS)&I2C_ICSTR_ICRRDY)){};
test = I2CMasterDataGet(SOC_I2C_0_REGS);
while(I2CMasterBusBusy(SOC_I2C_0_REGS));
////////////////////////////////////////////////////////
说明:我没有用中断的方式来读写数据。
我的I2C存储器的地址是17位的,所以我要分三次发,利用7位地址的这种协议发的
我的存储器的资料如下:
然后就发现,我的读写是不正常的,会卡在某个状态上
请问有没有不用中断的读写I2C的例子,或者我这个程序配置有什么问题?


