本帖最后由 rbc285426369 于 2013-10-30 11:35 编辑
这几天在调试28335的I2C,发现了个很恶心的问题,i2c设置为主设备发模式,发一个0x1e的指令,外部什么都没有接,却在i2c的接受寄存器中收到了数据,就是我刚发的1E,这是怎么回事呀?跪求大神指导~!!
void I2CA_Init(void)
{
// Initialize I2C
I2caRegs.I2CMDR.bit.IRS =0;
I2caRegs.I2CSAR = 0x00; // Slave address
I2caRegs.I2CPSC.all = 14;//9; // Prescaler - need 7-12 Mhz on module clk
I2caRegs.I2CCLKL = 10;//15; // NOTE: must be non zero
I2caRegs.I2CCLKH =5;//15; //Fi2c=Fp/((I2CCLKL+d)+(I2CCLKH+d))
I2caRegs.I2CIER.all = 0x00; // Enable SCD & ARDY interrupts
I2caRegs.I2CMDR.bit.IRS = 1; // Take I2C out of reset
// Stop I2C when suspended
}
Uint16 WriteData(Uint16 CMD)
{
Uint16 i;
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
while(!I2C_xrdy());
I2caRegs.I2CSAR = 0x00;
I2caRegs.I2CCNT = 1;
I2caRegs.I2CDXR = CMD;
I2caRegs.I2CMDR.all = 0x6E20;
if (I2caRegs.I2CSTR.bit.NACK == 1)
return I2C_BUS_BUSY_ERROR;
return I2C_SUCCESS;
}
我在主程序中调用WriteData(0X1E),单步跟随调试发现I2caRegs.I2CDRR = 0x1E,怎么回事呀?
|