RTC Not Saving Time and Date Information

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RTC Not Saving Time and Date Information

Jump to solution
1,459 Views
arun07
Contributor III

Hello Everyone

I am using RTC PCF2131 in one of my project, the problem is whenever I am writing some data i.e. seconds, hours, minutes, days, weekdays, year information into the RTC, it looks everything is fine, but whenever I am reading back the data, it returns something else.

The following is the capture of I2C Bus using a Logic Analyzer.

write to 0x53 ack data: 0x07 0x00 0x05 0x00 0x01 0x02 0x01 0x13 
write to 0x53 ack data: 0x07 
read to 0x53 ack data: 0x34 0x54 0x00 0x01 0x01 0x01 0x01
write to 0x53 ack data: 0x07 0x00 0x05 0x00 0x01 0x02 0x01 0x13 
write to 0x53 ack data: 0x07 
read to 0x53 ack data: 0x49 0x56 0x00 0x01 0x01 0x01 0x01

As seen above, 0x53 is the 7-bit slave address of the device, and 0x07 is Address of the SECONDS register.

I write, Seconds = 0 seconds, Minutes = 5 Minutes, Hours = 0 Hours i.e. 12 AM (24 hour format), Day = 1st Day, Weekday = Tuesday, Month =  January and Year is 13 (which for me means 2013).

I write this data and based on I2C Communication, it looks Okay, but when I read back, I received, 34 seconds, 54 minutes, 0 Hours, 1st Date, 1st Weekday (Monday), Month January, and year 01 for me it is 2001. I really don't understand why this is happening. Am I missing something??
Can someone please help me in understanding this point?

The following are the screenshots from the Logic Analyzer.

Writing Data

Writing DataWriting Data

 

Reading Data

Reading DataReading Data

 

Thanks in advance.

#PCF2131

Tags (1)
0 Kudos
1 Solution
1,457 Views
arun07
Contributor III

I think I found the issue, will try it tomorrow.

As per section 7.9.9 Setting and reading the time of the datasheet

arunsharma_0-1659828137331.png

So it looks like that, I have to implement this, then only I can update the time in RTC as it is protected.

Suggestions comments are most welcomed.

View solution in original post

0 Kudos
5 Replies
1,458 Views
arun07
Contributor III

I think I found the issue, will try it tomorrow.

As per section 7.9.9 Setting and reading the time of the datasheet

arunsharma_0-1659828137331.png

So it looks like that, I have to implement this, then only I can update the time in RTC as it is protected.

Suggestions comments are most welcomed.

0 Kudos
1,445 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Arun,

Yes, the STOP must be set before setting the time in time and date registers.

Please let us know if this completely solves the issue.

Best regards,

Tomas

0 Kudos
1,441 Views
arun07
Contributor III

Thanks Tomas for your response.

This is working but I have a problem (which can be fixed by changing the logic little bit, bit let we know if you have some comments).

To update the time I did following steps in the software.

  • I2C Start, Select Control Register and Set Stop Bit, I2C Stop
  • I2C Start, Select Software Reset Register, Set CPR to Logic-1, followed by write to 100th second Register, Seconds and So on till Years and finally I2C Stop
  • I2C Start, Select Control Register and Clear Stop Bit, I2C Stop

I sent this data without any delay in the software, and what happen is Time and Date are set but STOP bit was not cleared and hence RTC was not running, but if I give some delay, let's say 100ms between step 2 and 3, it works fine. Should I proceed like this or do you have some better suggestion.

0 Kudos
1,431 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Arun,

I have not heard about such a problem before. Please double check if below are done correctly .

  • I2C Start, Select Control Register and Set Stop Bit, I2C Stop

    Reg[0x00] |= BIT_05;

  • I2C Start, Select Software Reset Register, Set CPR to Logic-1, followed by write to 100th second Register, Seconds and So on till Years and finally I2C Stop

    Reg[0x05] = 0xa4;  -> did you write 0xa4 here? Please double check.

    Reg[0x06] = new_time...

  • I2C Start, Select Control Register and Clear Stop Bit, I2C Stop

    Reg[0x00] &= ~BIT_05;

 

Best regards,

Tomas

0 Kudos
1,369 Views
arun07
Contributor III

Hi @TomasVaverka 

Sorry for delayed response, somehow I missed this post.

For me it was working after giving some delay (100ms), between the three points mentioned in your post.

But I am not writing the 0xA4 in the Software Reset Register, instead of that I am writing 0x80.

I understood why you have mentioned 0xA4 because as per datasheet bit 2 and bit 5 are always 1, but I am writing 0x80 and it works fine (with some delay of 100ms between individual steps). Do you some issue with this approach?

I2C Logs from Logic Analyzer

write to 0x53 ack data: 0x00 0x20 
write to 0x53 ack data: 0x05 0x80 0x00 0x00 0x49 0x23 0x01 0x02 0x01 0x13
write to 0x53 ack data: 0x00 0x00

Just to check I will revert my code and try with 0xA4 as per datasheet without delay and see if this will work or not, and will update here.

Updated
I tried with 0xA4 for Software and Reset Register, and it works sometimes and sometimes not. I understand this is due to fast I2C communication, so it's better to give some delay in between two commands, and that is working for me. (I2C speed is 400KHz)

0 Kudos