-
不错,谢谢分享
-
单独运行你的接收函数,发现程序停留在
while(I2caRegs.I2CSTR.bit.XRDY == 0){}; 处。
不知原因为何?
-
我在采用该程序的时候发现这样的问题:
采用先写,延时,在读出。发现这样的问题:
写入数据函数->延时->断点-->读函数->延时,程序运行正常,结果正确;
如采用这样的步骤:
写入数据函数->延时-->读函数->延时,程序不正确:程序停留在:
while(I2caRegs.I2CSTR.bit.XRDY == 0){}; 处。
I2caRegs.I2CSAR = I2C_SLAVE_ADDR; //Set slave address
I2caRegs.I2CCNT = 2; //Set count to 2 address bytes
I2caRegs.I2CDXR = I2C_EEPROM_HIGH_ADDR;
I2caRegs.I2CMDR.bit.TRX = 1; //Set to Transmit mode
I2caRegs.I2CMDR.bit.MST = 1; //Set to Master mode
I2caRegs.I2CMDR.bit.FREE = 1; //Run in FREE mode
I2caRegs.I2CMDR.bit.STP = 0; //Dont release the bus after Tx
I2caRegs.I2CMDR.bit.STT = 1; //Send the start bit, transmission will follow
while(I2caRegs.I2CSTR.bit.XRDY == 0){}; //Do nothing till data is shifted out
I2caRegs.I2CDXR = I2C_EEPROM_LOW_ADDR;
-
我在采用该程序的时候发现这样的问题:
采用先写,延时,在读出。发现这样的问题:
写入数据函数->延时->断点-->读函数->延时,程序运行正常,结果正确;
如采用这样的步骤:
写入数据函数->延时-->读函数->延时,程序不正确:程序停留在:
while(I2caRegs.I2CSTR.bit.XRDY == 0){}; 处。
I2caRegs.I2CSAR = I2C_SLAVE_ADDR; //Set slave address
I2caRegs.I2CCNT = 2; //Set count to 2 address bytes
I2caRegs.I2CDXR = I2C_EEPROM_HIGH_ADDR;
I2caRegs.I2CMDR.bit.TRX = 1; //Set to Transmit mode
I2caRegs.I2CMDR.bit.MST = 1; //Set to Master mode
I2caRegs.I2CMDR.bit.FREE = 1; //Run in FREE mode
I2caRegs.I2CMDR.bit.STP = 0; //Dont release the bus after Tx
I2caRegs.I2CMDR.bit.STT = 1; //Send the start bit, transmission will follow
while(I2caRegs.I2CSTR.bit.XRDY == 0){}; //Do nothing till data is shifted out
I2caRegs.I2CDXR = I2C_EEPROM_LOW_ADDR;