-1

I need to send a pulse to an Arduino at every one hour. I don't need day, month, year etc. I just want a pulse from DS3231 at every 1 hour through the square wave pin.

https://github.com/NorthernWidget/DS3231
I have included this library but I can't anyhow understand how to generate an pulse at each hour using this library. Is it possible?

My requirement is simple. I need a pulse at my Arduino interrupt pin at each hour.

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

void setup()
{
  Wire.begin();
  EICRA |= 0b00000011;
  EIMSK |= 0b00000001;
  sei();
 // No clue on how to setup DS3231 for getting a pulse at each hour
}
ISR(INT0_vect)
{
  // This function will be executed in each hour
}
void loop(){}
3
  • Look at the documentation that you've reference and see the turnOnAlarm() function. I didn't dig into it but that should get you started.
    – jwh20
    Dec 17 '20 at 15:07
  • I checked that too. The example was too complicated. But as far as I have understood from the example that I have to check the alarm status through I2C. Dec 17 '20 at 15:17
  • 2
    In that case let me suggest that you try some simple exercises before diving into a relatively complex device like the DTC3231. If you just learn about how to set and read the time that would be a good start.
    – jwh20
    Dec 17 '20 at 15:47
2

DS3231 address is 104. Instead of using that large complicated header, send simple frame.

For 1 sec pulse the frame will be : S 208 A 14 A 0 P

N.B. Here address is 7 bit value 104. And a extra bit for R/W operation.

In the Arduino wire library, you don’t need to include the R/W bit. So,just write 104. For hourly Alam set the INT bit of control register and send simple frame like this. Don't make things complicated using the header.

0

See the documentation at:

DTC3231 Library Documentation

Where there is the section on alarm bits and setting alarms:

        // Alarm functions
        
        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
        void setA2Time(byte A2Day, byte A2Hour, byte A2Minute, byte AlarmBits, bool A2Dy, bool A2h12, bool A2PM); 
            // Set the details for Alarm 2
        void turnOnAlarm(byte Alarm); 
            // Enables alarm 1 or 2 and the external interrupt pin.
            // If Alarm != 1, it assumes Alarm == 2.
        void turnOffAlarm(byte Alarm); 
            // Disables alarm 1 or 2 (default is 2 if Alarm != 1);
            // and leaves the interrupt pin alone.
        bool checkAlarmEnabled(byte Alarm); 
            // Returns T/F to indicate whether the requested alarm is
            // enabled. Defaults to 2 if Alarm != 1.
        bool checkIfAlarm(byte Alarm); 
            // Checks whether the indicated alarm (1 or 2, 2 default);
            // has been activated.

UPDATE:

Based on your comment:

I checked that too. The example was too complicated.

You need to spend some time gaining a familiarity with some of the basic Arduino and AVR functions. To make this work you're going to not only need to understand how to talk to the RTC via I2C but also how to enable and respond to a pin interrupt in the AVR. You have the ISR function there but you have not done anything to enable any interrupt source.

1
  • Trust me, I know how to enable external interrupt (also pin change interrupt of ATMEGA328p). EICRA |= 0b00000011; EIMSK |= 0b00000001;sei(); You are asking for this. Isn't it? I didn't included these as the question is about RTC instead of ISR function. Dec 17 '20 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.