This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

XC161CJ and I2C bus

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

0