Thursday, 29 January 2015

pic - Error interfacing DS1307 RTC with PIC32


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

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...