-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checkifalarm issue #9
Comments
Hi @Bepsy, Another way to prevent the describes issue is to switch over to an interrupt based coding scheme. In that case, you can call Best regards, Jacob |
Hello @Bepsy, I agree with @jnuernberg that an interrupt-driven approach makes a lot of sense. However, maybe you prefer to check the alarm directly, as you described. As the saying goes, "There is more than one way to do it." I can think of two things you might try in a "polling" approach, like your own code. In fact, you might combine them. First, capture the return value of the
The function does report the value that it finds for the flag, false or true (0 or 1) before it clears the flag. You can test it after each time you call the function, like this:
Second, it sounds like you suspect a so-called "race condition", where your code checks the alarm so fast that the DS3231 never gets a chance to signal an alarm at all! Solution: slow down your code! Think about it. The DS3231 advances its time internally at one-second intervals. it does no good to check the alarm more frequently than once per second. So, put the call to
My best to you, IowaDave |
Not a Bug?For what it's worth my view is that clearing an alarm flag bit in the DS3231 is a deliberate side effect of the
Workable tools reward the effort invested to learn them. |
Hi @Bepsy, I added a bool DS3231::checkIfAlarm(byte Alarm, bool clearflag) I did not manage to test it yet, so I refrained from opening a pull-request. I hope to manage that soon, Cheers, Jacob |
Optional clear flag in checkIfAlarm() / #9
Closing after merging PR #58 with thanks to @jnuernberg and possible extreme patience from @Bepsy. |
I encountered a problem when using the checkifalarm function. This function gives some issues, since my arduino code is only checking the alarms constantly and not doing anything else,
In the function the flags are red and then reset to 0, even when the flag isn't 1. This is problematic, since my code is nearly all of the time in the checkifalarm function. First the controlbyte is red out in this function, and the flag can be red as zero. In the meanwhile the flag can be set to 1 by the chip, but the code will still set the flag to zero. So the alarm is never triggered. This can easily be solved by the following code change:
I don't know if this is the right place to put it, I am just new on Github. But please take a close look at it.
The text was updated successfully, but these errors were encountered: