I am struggling with the I2C module of XC161CJ to talk with a real-time clock RTC 8564. In my code, I am doing following sequence to send a DeviceID and an address. But it won't work. 1. while( I2C_uwGetStatus() & I2C_BB ); // wait for bus idle 2. I2C_vWriteData(ClkID); // slave address in Write mode 3. I2C_vGenStartCond(); // start condition 4. while( !(I2C_uwGetStatus() & I2C_IRQD) ); // wait for byte sent out 5. while( I2C_uwGetStatus() & I2C_LRB ); // wait for ACK 6. I2C_vWriteData(0x02 ); // seconds' address 7. while( !(I2C_uwGetStatus() & I2C_IRQD) ); // wait for byte sent out 8. while( I2C_uwGetStatus() & I2C_LRB ); // wait for ACK What I saw from the scope is just ClkID has been sent out, and without ACK feedback. My questions are, 1. How to start a transmission? 2. How do I know it's been sent out? 3. How to check the ACK? 4. How to send another byte? Could somebody tell me what is wrong? Or please send me a piece of your code about IIC operation. my email address is: dzh1234@yahoo.com Thanks a lot. David
Thank you, Mr.Shang. Yes, I solved this problem by switching transmit to receive. Well, my new problem are, 1. How can I know if a byte has been sent out to bus? 2. How can I know a byte has been received to the buffer? 3. How can I know a start condition or a stop condition has been done? David Zhang
How could I keep the master's clock working as long as the slave send message back? or do I have to change the transfer direction? How to do that?
While, now my XC161CJ can transmit and get ACK from slave. But my new problem is, once the master stops transmitting, it stops the SCL also. How could I keep the master's clock working as long as the slave send message back? or do I have to change the transfer direction? How to do that? Thanks.
View all questions in Keil forum