RTCDS3231 setting Year

Hi to all,
I need a little help about year setup on RTC DS3231. I 'm using DS3232RTC Library
// GitHub - JChristensen/DS3232RTC: Arduino Library for Maxim Integrated DS3232 and DS3231 Real-Time Clocks.

I see on DS3231datasheet that Bit4, Bit5, Bit6, Bit7 should be the responsable bits for 10 year. I can set the Bit4 and Bit5 so I can obtain : 10 year(Bit4=1,Bit5=0) , 20 year ( Bit 4=0, Bit5=1) and 30 year (Bit4=1,Bit5=1) but How I can obtain 40 year? I mean the fourth decade or fifth and so on. I think I must use Bit 6 and Bit7 but doesn't works. What's wrong in my thinking ?


thanks

Posting your code would help here so we don't have to guess what you are trying to do .....

You mention setting bits, so I assume that you are using the writeRTC() function in the library, instead of the set() function? Any particular reason for this?

Does the SetSerial.ino example not do what you want?

HI Markd833,

thanks to your reply I checked once again the code and i found the error ... i was missed an "1" in the bitwise & (see bold line) . I put 0b00000011 instead of 0b00000111

Wire.beginTransmission(deviceAddress); //START, Roll Cal
Wire.write(0x00); //SEC Register address in Address Counter of RTC
Wire.write(0x00); //data for SEC Register (23 sec = 0010 0011)
Wire.write(0x00); //data for MIN Register (54 Min = 0101 0100)
Wire.write(0x00); //data for HRS Register for 12 hour clock time format 12:54:27
Wire.write(0x02); //Monday
Wire.write(0x20); //0001 1001
Wire.write (0x08); //Month : August
Wire.write (0x21); //year: 0001 1001 = 21---> 2021
Wire.endTransmission(); //Execute the above Tasks, ACK STOP
}

void loop()
{
showTimeOnLCD();
}

void showTimeOnLCD()
{
Wire.beginTransmission(deviceAddress); //START, Roll Cal
Wire.write(0x00); //set SEC Register address
Wire.endTransmission(); //Execute the above queued data, ACK, STOP

Wire.requestFrom(deviceAddress, 7); //SEC, MIN, and HRS to read from RTC as BCD
byte bcdSeconds = Wire.read();
byte bcdMinutes = Wire.read();
byte bcdHours = Wire.read();
bcdDay = Wire.read();
byte bcdDate = Wire.read();
byte bcdMon = Wire.read();
byte bcdYr = Wire.read();

//---show Time on LCD---------------
lcd.print("Time:");
lcd.print(bcdHours >> 4 & 0b00000001); lcd.print(bcdHours & 0x0F); lcd.print(':');
lcd.print(bcdMinutes >> 4); lcd.print(bcdMinutes & 0x0F); lcd.print(':');
lcd.print(bcdSeconds >> 4); lcd.print(bcdSeconds & 0x0F);
if (bitRead(bcdHours, 5) == HIGH)
{
lcd.print(" AM");
}
else
{
lcd.print(" PM");
}

{
//---show: day/month/year----
lcd.setCursor(0, 1);
lcd.print("Date:");
getDay(bcdDay);
lcd.print(dayOftheWeek);
lcd.print(" :");
lcd.print(bcdDate >> 4 & 0b00000011); lcd.print(bcdDate & 0x0F); lcd.print('/');
lcd.print(bcdMon >> 4 & 0b00000001); lcd.print(bcdMon & 0x0F); lcd.print('/');
lcd.print("20"); lcd.print(bcdYr >> 4 & 0b00000111); lcd.print(bcdYr & 0x0F);

}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.