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

Parents
  • 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

Reply
  • 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

Children
No data