DS3231SN alarm setting

hi to all,

i am using DS3231SN RTC with arduino UNO board.I want to set an alarm and wants to wake up the arduino. but i am not able to setting the alarm.i go through datasheet as well as tryin to find on google but still i am not able to get anything for ds3231sn.

can anybody suggest me by sample program that how to set the value in ds3231sn register for setting the time a well as alarm?

Is there any way that we can directly set the system time in RTC using any function????

If anybody knws anything please guide me....

Hello,

I recommend this library: GitHub - JChristensen/DS3232RTC: Arduino Library for Maxim Integrated DS3232 and DS3231 Real-Time Clocks

yes that i know already.

What i have done yet is,i connected the RTC(DS3231SN) interrupt pin to external interrupt 1(pin 3 of UNO board) of arduino uno.Now i want to take some action by programetically when the alarm is occur.For that i also made the ISR of interrupt1.

The problem is i set the regester value as mention in datasheet.How to set the time and how to make an alarm all.

so i need some working code example for refferance that how to set the time in ds3231sn and

how to put an alarm in it?and

at which mode i have to put the external interrupt of atmega so i could get the interrupt.

Also one more doubt that there is one bit in 0Eh reg named INTCN .they mention in datasheet that it is already set at 1 when we powerup the circuit.So do i need to set that perticalar bit programetically or i have to leave as it is.

You say you already know about the DS3231 library.
You don't say if you are actually using it.

There are functions in the library for both setting the time and setting alarms:-

RTC.set(t);
RTC.setAlarm(alarmType, seconds, minutes, hours, dayOrDate);

I have no idea if the alarm generates an interrupt, I haven't used this chip/library, but those functions look like good starting points.

Edit: Correction, after reading a little more of the DS3231 library documentation, I see that an interrupt is generated:-

There are examples of using these functions in the library documentation.

You have to first clear the alarm flag, because if the flag is already set, the alarm will not be triggered.

Using an interrupt in this case is only useful if your arduino is sleeping. And your interrupt handler must be as fast as possible.

So if you put your arduino to sleep and want to wake up with the RTC, here is example code:

In setup:

pinMode( rtcAlarmPin, INPUT_PULLUP );
attachInterrupt( digitalPinToInterrupt( rtcAlarmPin ), NULL, FALLING );

RTC.alarm( ALARM_1 ); // clear alarm1 flag if needed..
RTC.alarmInterrupt( ALARM_1, true ); // enable alarm1 interrupt..
RTC.setAlarm( ALM1_EVERY_SECOND, 0, 0, 0, 0 ); // set alarm1 every seconds..

In loop():

if ( RTC.alarm( ALARM_1 ) ) // if alarm1 flag was set, clear it and...
{
    doSomethingEverySeconds();
}

If you don't want to use that library then at least look at it and copy/paste what you need.

Last thing, if you have problems getting the alarm to work when the RTC is running on battery, and if you are using RTC module breakout board "ZS-042", read this topic. Near the end is the solution :wink: