Closed donsenilo1968 closed 6 months ago
Thanks for the issue. Might take some time before I can investigate.
What platform do you use? What is the output of DS3232_demo_read.ino? Do you have pull up resistors? What is the wire length?
Arduino Nano Date and Time No Max. 3cm
So date and time works but not weekdays ....
Need a code / datasheet check as day of week is iirc the only read only register..
Yep. Weekdays are always 0. This is the only Datasheet I could found.
Datasheet from the manufacturer of the device:
Registers:
Register 3 is Day of week - 1..7
uint8_t DS3232::weekDay() { return _reg[3]; }
the register 3 is filled in read() and not masked or so. The bcd2dec() function that converts the BCD values from the registers is not needed for weekday as it does not change the value.
Can you add a print statement into the read function in ds3232.cpp (line 61) ? Please post what is read from the registers.
int DS3232::read()
{
_wire->beginTransmission(_address);
_wire->write(DS3232_SECONDS);
_rv = _wire->endTransmission();
if (_rv != 0) return DS3232_ERROR_I2C;
if (Wire.requestFrom(_address, (uint8_t)7) != 7)
{
return DS3232_ERROR_I2C;
}
for (int i = 0; i < 7; i++)
{
uint8_t tmp = _wire->read(); // << changed
Serial.println(tmp, HEX); // << changed
_reg[i] = bcd2dec(tmp); // << changed
}
_reg[0] &= 0x7F;
_reg[2] &= 0x3F;
_lastRead = millis();
return DS3232_OK;
}
I get this:
16031 24-4-5 11:40:2 1 4 40 11 1 5 4 24 18033 24-4-5 11:40:4 1 6 40 11 1 5 4 24
Adding the registers / meaning
| register | meaning | value |
|:--------:|:-------------|:-----:|
| 0 | seconds | 4 |
| 1 | minutes | 40 |
| 2 | hours | 11 |
| 3 | dayofweek | 1 |
| 4 | day of month | 5 |
| 5 | month | 4 |
| 6 | year | 24 |
18033 24-4-5 11:40:4
Datasheet states The day-of-week register increments at midnight. Values that correspond to the day of week are user defined but must be sequential (i.e., if 1 equals Sunday, then 2 equals Monday, and so on). Illogical time and date entries result in undefined operation.
The day of week is 1 where we would expect 5 or 6 (?) As the value is now 1, I assume the RTC started yesterday with a value 0 and it was updated last midnight.
That would mean I need to check the library if the DOW is set.
That would mean I need to check the library if the DOW is set.
Has no setWeekDay() so ==> BUG
@donsenilo1968 Created a develop branch that adds setWeekDay() (and some minor edits) If you have time, can you verify if it works?
update - valid values seem to be 1..7
With the Develop Branch
Before demo_write: 212216 24-4-5 20:12:25 1 214219 24-4-5 20:12:27 1
After demo_write: 144150 24-4-5 20:15:50 5 146152 24-4-5 20:15:53 5
If I understand it correctly, once the Weekday is set it increments at midnight and starts again on Mondays with 1.
But (in my Case) I use Udp NTP Client to get the actual Date and Time and it seems there is no Way to get the Weekday.
That is what I understand too. Please let me know the weekday tomorrow to be sure. Then I can merge the new code.
Thanks for testing!
I found here an interesting Part about getting the Weekday. If this is true, the Output for the Weekday was correct (1 = Friday).
I found here an interesting Part about getting the Weekday. If this is true, the Output for the Weekday was correct (1 = Friday).
Then it could automatically update it to 2 tomorrow.
Indeed an interesting find
@donsenilo1968 Added a note about the Thursday == 0 weekday in the readme.md
Hi Rob
It seems like it works.
I read the Date and Time via NTP, add the Timezone and calculate the Weekday from the epoch. Then I write all to the Clock (Date and Time at the Bottom of the Display). This happens when the Arduino starts and every Monday. The Date, Time and Weekday at the Top are the Data getting from the Clock.
Thank you very much for your Help and updating the Code. Best Regards from Vienna, Markus
Thanks for the photo, looks good!
The NTP time is the moment of the last sync I assume? Or is there another reason for the 5 minutes difference?
Are there other things missing in the library? (I am thinking about adding EEPROM support)
The NTP time is the moment of the last sync I assume? Yes, exactly.
I use this Lib because it's minimalistic and I don't need any other Functions for my Project. Is adding more Functions necessary ? It's your Baby, so it's your Decision.
My plan is to create a derived extended class DS3232-EXT Which has the additional functions. Exactly because that keeps the base class minimalistic.
Another option I consider is to have a 2nd class DS3232EE that only handles the EEPROM part of the device. Not derived, complete disjunct as there is no reason to have it merged in one object afaik. (except convenience) It could be in same library though
Other functionality like alarms etc would be logically more related to the time keeping. These should therefor be in the EXT class.
Merged develop into master and released 0.4.0 version,
Hi
Even in your Example (with added weekDay) it always returns 0.