Fix alarm registers, time masks, 32kHz output mask, and add NULL pointer checks - #3
Open
CupoMeridio wants to merge 2 commits into
Open
Fix alarm registers, time masks, 32kHz output mask, and add NULL pointer checks#3CupoMeridio wants to merge 2 commits into
CupoMeridio wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi @eepj,
I've been using this library in some projects and found a few minor bugs and hardware register collisions.
Some of these fixes were identified and provided by my university, and then I consolidated them with
additional safety checks to improve the library's overall robustness.
Here is a summary of the improvements:
In DS3231_SetAlarm2Mode(), the code was reading Alarm 1 registers (DS3231_A1_...) instead of Alarm 2
registers (DS3231_A2_...). This was corrupting Alarm 1 configuration when setting up Alarm 2. Corrected
them to reference the proper Alarm 2 registers.
Updated the BCD encoding mask from 0x3f to 0x7f in DS3231_SetAlarm2Minute(), DS3231_SetAlarm1Second(), and
DS3231_SetAlarm1Minute(). The previous 0x3f mask was stripping away the 6th bit (worth 40 in BCD format),
preventing alarms from being set for any time value greater than 39 minutes/seconds.
In DS3231_Enable32kHzOutput(), updated the status register masking from 0xfb to 0xf7. The old mask was
clearing the BSY bit (bit 2) instead of preparing the EN32KHZ bit (bit 3).
Added a defensive check if (!_ds3231_ui2c) inside DS3231_SetRegByte and DS3231_GetRegByte. This prevents
sudden microcontrollor crashes (HardFaults) if any driver function is called before DS3231_Init().
These changes are fully backward-compatible and do not break the existing examples.
Thanks for the library!