I am interfacing DS1307 RTC
with PIC32MX795F512L
. I am using I2C1
for DS1307 RTC
and then using UART2
to send the RTC value to the terminal. I have written the code but don't know why I am not getting data.
In my code I am using
OpenI2C2 to open the i2c channel.
StartI2C2() to start the communication
StopI2C2() to stop the communication
MasterWriteI2C() to write the data
MasterReadI2C() to read the data
These are included in plib.h file.
Updated CODE:
OpenI2C2(I2C_EN, 163); // I2C channel Configuration
StartI2C2();
IdleI2C2();
n = MasterWriteI2C2(0xD0); //device address
IdleI2C2();
MasterWriteI2C2(0x07);
IdleI2C2();
MasterWriteI2C2(0x00);
IdleI2C2();
StopI2C2();
StartI2C2();
IdleI2C2();
MasterWriteI2C2(0xD0);
IdleI2C2();
MasterWriteI2C2(0x01);
IdleI2C2();
MasterWriteI2C2(0b00010011);
IdleI2C2();
StopI2C2();
StartI2C2();
IdleI2C2();
MasterWriteI2C2(0xD0);
IdleI2C2();
MasterWriteI2C2(0x01);
IdleI2C2();
StopI2C2();
StartI2C2();
IdleI2C2();
MasterWriteI2C2(0xD1);
IdleI2C2();
**res = MasterReadI2C2();**
IdleI2C2();
NotAckI2C2();
IdleI2C2();
StopI2C2();
I am using 163 ((33000000/2/100000)-2)
as BRG value for I2C communication. I am debugging the code and can see all the values in I2C registers are correct but at res = MasterReadI2C2()
, nothing shows up in I2C2RCV
register which holds the received value and even nothing showing up in the res
variable. I also used a variable n
to check if the values are actually transmitting or not. So I received 0x00
as the value of n and according to document, 0 means transmission successful.
I don't know where I am missing the point.
No comments:
Post a Comment