Zanduino / DS3231M

Access the DS3231M I2C Realtime Clock
GNU General Public License v3.0
15 stars 7 forks source link

DS3231 vs DS3231M #18

Closed lagg070988 closed 2 years ago

lagg070988 commented 2 years ago

Hello, I realize that I have in my possession a DS3231, and it has some features that the DS3231M does not have. One of them is the ability of the DS3231 to produce a frequency of 1hz, 1khz, 4khz or 8khz. while the DS3231M only produces 1hz. here is a small explanation, although I am guided by the data sheets. I am fairly new to github, I "fork" your library and made some add-ons (some lines of code) to support this feature. and it has worked fine on arduino uno, nano and some boards that I assemble as data logger. since this library appears in arduino ide, I wonder: would it be wise to include these changes and expand the support for DS3231?

SV-Zanshin commented 2 years ago

I have made a some changes to the code which make this pull request a bit of a chore to integrate, so I am going to add your code to my branch and integrate that..

SV-Zanshin commented 2 years ago

I've added the changes, having changed the code just a little bit to stay backwards-compatible. I'll draft a new 1.0.7 release that will include this additional functionality as well. Thanks!

lagg070988 commented 2 years ago

thanks for you! I believe that writeByte(DS3231M_CONTROL, readByte(DS3231M_CONTROL) & ~B00111000); line 528 should be writeByte(DS3231M_CONTROL, readByte(DS3231M_CONTROL) & ~B00011100);

in writeByte(DS3231M_CONTROL, (readByte(DS3231M_CONTROL) & ~B00111000) | (rate | B00000011) << 3); line 540 should be writeByte(DS3231M_CONTROL, (readByte(DS3231M_CONTROL) & ~B00011100) | (rate & B00000011) << 3); in the next few days I will prove this.

SV-Zanshin commented 2 years ago

You are correct, I don't know how that slipped by me!

lagg070988 commented 2 years ago

I forgot to highlight the change between the "or" and "and" in the previous comment, line 540, otherwise the output would always be 8khz sorry

lagg070988 commented 2 years ago

I have tested today on arduino nano and it works as expected pinSquareWave () and pinSquareWave (const uint8_t rate) . thanks!

SV-Zanshin commented 2 years ago

That's great news - I'm glad we could make the library work better.