Using the DS3231.h library

I'm looking for basic information on the DS3231.h library, the above helps, but there are soo many more functions (GitHub - NorthernWidget/DS3231: Communicates between Arduino-programmed AVR and Maxim DS3231 RTC: splice of Ayars' (http://hacks.ayars.org/2011/04/ds3231-real-time-clock.html) and Jeelabs/Ladyada's (https://github.com/adafruit/RTClib) libraries) in this library that I cannot find straight forward how-to information and examples.
In my situation I'm am using the basic code "Arduino-Nano-33-IoT-Ultimate-Guide/src/PowerOnTimer/PowerOnTimer.ino at master · ostaquet/Arduino-Nano-33-IoT-Ultimate-Guide · GitHub" and circuit "Arduino-Nano-33-IoT-Ultimate-Guide/images/WakeOnTime_schem.png at master · ostaquet/Arduino-Nano-33-IoT-Ultimate-Guide · GitHub". I've got the software and hardware to work, but I need to make changes to the alarm intervals and to understand the SQW pin change with respect to the function calls in the code.
Specific questions are:
(1) When the DS3231 is powered-up, what is the logic status of SQW, from my read it is HIGH?
(2) What is the logical status of SQW when the call to "Clock.turnOnAlarm(1);" executes, is it still HIGH?
* Does this call start the one minute timer?
* Or does it just get the DS3232 ready for Alarm 1 to be started?
(3) Why are the parameters to the call "Clock.setA1Time(1, 2, 3, 4, 0b1110, false, false, false);" set as is,
* The first three parameters "1,2,3" are not even used as I understand it,
* The fourth "4" means that the Alarm "1" is triggered the fourth second of each minute?
* The "false, false, false" indicates that since we are triggering the alarm every minute, the first/second/third parameters are ignore?
* How do I set the alarm for every three minutes or every 45 seconds?
(4) When "Clock.checkIfAlarm(1);" is executed,
* Does SWQ go HIGH or LOW?
* Does this call initiate the "one minute count down" until the Alarm "1" causes the SWQ to go from HIGH to LOW,
* Or does it assume that Alarm "1" has already triggered SWQ to go from HIGH to LOW and now resets SQW to HIGH?
I apologize for such basic questions, but the I really haven't found a good easy to understand resource for this library. Thank you for your help.

Which of the several dozen that exist?

1 Like

Many of these questions are answered in the DS3231 data sheet, online at Maxim.

1 Like

You can gain a lot if you open the library and read the .cpp and .h files. Many of your questions are answered. Not all libraries are the same this is library dependent. You can empirically answer many of your questions by working with one.

Ok, i'll have a go!

The library header comment says:

void turnOnAlarm(byte Alarm);
// Enables alarm 1 or 2 and the external interrupt pin.
// If Alarm != 1, it assumes Alarm == 2.

If interrupts are enabled, the SQW pin becomes the interrupt out pin - active low. Therefore it should start high and stay high until the alarm time is reached.

No. The 1 refers to Alarm #1.

Yes.

From the library header:


		void getA1Time(byte& A1Day, byte& A1Hour, byte& A1Minute, byte& A1Second, byte& AlarmBits, bool& A1Dy, bool& A1h12, bool& A1PM); 
/* Retrieves everything you could want to know about alarm
 * one. 
 * A1Dy true makes the alarm go on A1Day = Day of Week,
 * A1Dy false makes the alarm go on A1Day = Date of month.
 *
 * byte AlarmBits sets the behavior of the alarms:
 *	Dy	A1M4	A1M3	A1M2	A1M1	Rate
 *	X	1		1		1		1		Once per second
 *	X	1		1		1		0		Alarm when seconds match
 *	X	1		1		0		0		Alarm when min, sec match
 *	X	1		0		0		0		Alarm when hour, min, sec match
 *	0	0		0		0		0		Alarm when date, h, m, s match
 *	1	0		0		0		0		Alarm when DoW, h, m, s match
 *
 *	Dy	A2M4	A2M3	A2M2	Rate
 *	X	1		1		1		Once per minute (at seconds = 00)
 *	X	1		1		0		Alarm when minutes match
 *	X	1		0		0		Alarm when hours and minutes match
 *	0	0		0		0		Alarm when date, hour, min match
 *	1	0		0		0		Alarm when DoW, hour, min match
 */
		void getA2Time(byte& A2Day, byte& A2Hour, byte& A2Minute, byte& AlarmBits, bool& A2Dy, bool& A2h12, bool& A2PM); 
			// Same as getA1Time();, but A2 only goes on seconds == 00.
		void setA1Time(byte A1Day, byte A1Hour, byte A1Minute, byte A1Second, byte AlarmBits, bool A1Dy, bool A1h12, bool A1PM); 
			// Set the details for Alarm 1

That tells you what the parameters are.

The library header says:

bool checkIfAlarm(byte Alarm); 
			// Checks whether the indicated alarm (1 or 2, 2 default);
			// has been activated.

It returns true or false to reflect the active status of an alarm.

I'm running this code under the Arduino Cloud IoT. It must be the default DS3231.h library for the Nano 33 IoT since I didn't import any library.

Never the less, the entire library must be hosted somewhere, so you can show us where that is. You can usually find a URL somewhere in the header file. What did you import?

Thank you for the information. So what function call starts the DS3231 timer count down? How do I specify a different timer interval instead of the every minute used in this code, such as every five minutes or every 45 seconds?

The DS3231 does not have any timer. If there is one, it is in your code or in some library that you've used.

It does have alarms. Is that what you mean?

I keep pointing you to DS3231 library because that is where you will see some example sketches to show how those functions work.

    #include <Wire.h>
    #include <DS3231.h>
    #include <SPI.h>
    #include <WiFiNINA.h>

This is what I specified in the Cloud IoT sketch.

But when you installed the support you need for your program, what libraries did you install? Please go to your libraries folder and find the DS3231 library folder, look in there and read the header file in order to identify it.

You can't learn very much from a single #include line.

You said you needed to understand the timer control functions, that is where you should go for that. Again, there are alarm example sketches you can learn from there.

Actually, those examples should be visible now, in your examples tab in the IDE. Without any folder navigation.

The main reason I want you to clearly identify your library, is that documentation would also be available where it is hosted.

Yes, the alarms. How do I initiate the alarm. The code I specified above is set for every minute intervals. The circuit powers down the Nano 33 completely, the DS3231 is powered continuously from another source. When the DS3231 alarms triggers, it returns the power to the Nano 33 and the DS3231 is reinitialized. In summery, when the SQW is HIGH, the Nano is OFF. When SQW is LOW (alarm triggered) Nano is powered up.

Please stop begging for canned answers and go do some footwork.

It's unique that you happen to be using the alarm as a wake up, however the CPU functions have no bearing on that, so it's a pure RTC library question..

You only need to know how to control SQW, the library examples and documentation make it abundantly clear. They have to, because it's such a common need.

Excuse me? I've spent days looking at examples, but as stated above, there are multiple DS3231.h libraries that exist and I have been unable to find clear documentation for my level of knowledge. I thought this forum was a source for helping Arduino developers tackle issues? If you don't want to help at least don't be insulting, just don't reply!

That is precisely what I have been telling you. You need to identify the one you have.

I am trying very hard to help you. If you don't want help, don't come here.

This is not developed under the Arduino IDE, I'm using the Arduino Cloud IoT platform. I did not have to install any libraries.

Now you tell us... the implications of your reply #6 are not clear to anyone who has not used Cloud IoT...

To make any progress, you still need to identify the library. I suspect it does reside somewhere on your setup, I'm not familiar with the topology of Cloud as installed, but I also suspect that either the examples are there, or can be found by identifying the library and going to its source...

My bad, thought I had mentioned it the Arduino Cloud IoT.

As I said, merely dropping the name here doesn't explain much unless you already know it. It's not really necessary to know it to answer the RTC questions, too.

Finding the actual library source and documentation is sure to answer your questions. Much better than could be answered by any forum member, probably.

When you do find it, people (even myself) will be more than happy to help you understand any specific issues or knowledge gaps that you encounter. Someone took a stab at it, above, but it was a gamble without knowing the exact library. Also, it was necessarily an incomplete answer.

So please do due diligence and identify the library for us so we can really help.

I will try to find the Default IoT Cloud library code used. The few that I've seen are poorly documented though, deciphering the code was a nightmare, and no one specified the SQW logic levels correlation with the functions. The DS3231 data sheet does not refer to any specific library. I will look for the Cloud IoT library code. Thank you.