Hello,
I need to program two alarms to trigger the INT/SQW pin LOW and then HIGH for a certain duration. What I need:
-keep INT/SQW LOW during at least 30ms (and maximum 2s) and then HIGH
-keep INT/SQW LOW more than 2s and then HIGH
I'm a little lost with the DS3231 datasheet and registers management. If somebody can help. Thx
the INT/SQW pin is driven by the DS3231 based on some register's configuration (Control register @ address 0x0E)
You can set different modes for that pin, Adafruit's RTClib for example would provide these modes that you can setup through a simple method call (writeSqwPinMode())
Thank you Jackson,
My arduino is powered by a battery charger PCB that has a special pin to turn power on/off.
If the pin is LOW for at least 30ms (and maximum 2s) then the charger PCB turns on
If the pin is LOW for more than 2s then the charger PCB turns off
So I want to connect the DS3231 to this pin in order to turn my Arduino on/off at a certain time.
Square wave frequencies seems two low bc I would need at least 30KHz to 2000KHz
Maybe use play with the 32KHz pin?
sorry because this question is beyond the scope of your topic but which model of these your PCB battery charger?
If possible a link.
Thanks in advance,
I feel like you're not going to want to try to force the DS3231 to conform to this spec but rather your code.
Your code should wake the Arduino upon a low-level on, say, INT0 and should then monitor the INT0 input to see how long it's low. If it's low for at least 30mS then stay awake.
Your program would them monitor the same pin while running and if it sees the pin transition from high to low and stay low for at least 2-seconds then go to sleep.
What's the connection between the DS3231 RTC and this external battery charger?
My understanding is that the Arduino has no power and will be woken up only when power will be triggered. May be I got that wrong though.
The pin ( _INT or SQW) has two purposes: either you get a constant square wave at various frequency you can set (1Hz, 1kHz, 4kHz or 8kHz) or it's used as a pin going low when a specific alarm time is matched.
So if you turn off the square wave and just set up an Alarm for a given second on your DS3231 then you don't get the square wave and the INT pin will get LOW (Active-Low Interrupt) at the selected time.
It is my understanding that this Alarm would get cleared at the next second since there is no longer a match. (there is no way to really clear an alarm but your Arduino could disable the alarms)
The alarm output is open-drain, so it can be connected in parallel with other open-drain outputs.
Use the DS3231 to turn on the power.
Use a transistor (mosfet) driven by the arduino to turn off the power.
You are right Jackson, the Arduino has no power and will be woken up only when power will be triggered.
To clarify, I need to implement the following scenarios A and B:
A) turn on the Arduino:
1)At alarm, DS3231/_INT turns LOW and then HIGH in the window time [50ms, 2s]. This is like pushing a button at least 50ms but no longer than 2s.
2)the Battery PCB power-up the Arduino
=>I don't see how to turns DS3231/_INT LOW and then HIGH in the window time [50ms, 2s]?
B)turn off the Arduino:
1)At alarm, DS3231/_INT turns LOW at least 2s. This is like pushing a button more than 2s.
2)the Battery PCB power-down the Arduino
=> ok: "just" turn DS3231/_INT LOW more than 2s
David_2018: I want to avoid extra electronics if possible
I don't see how to turns DS3231/_INT LOW and then HIGH in the window time [50ms, 2s]?
An alarm indication remains active until the flag is cleared, not until the next second:
"A logic 1 in the alarm 2 flag
bit indicates that the time matched the alarm 2 regis-
ters. If the A2IE bit is logic 1 and the INTCN bit is set to
logic 1, the INT/SQW pin is also asserted. A2F is
cleared when written to logic 0."
Thus turn on is easy, just clear the flag at boot up. If I'm not mistaken, your problem is that when you turn off by means of an alarm, the processor is no longer available to clear the flag?
Use alarm to turn off power, but have a capacitor large enough to maintain power on the arduino so that it can turn the alarm output off after at least two seconds have elapsed.
I told you how to turn it on. The INT/SQW goes low on an alarm. It will stay low until the CPU resets it. So there is nothing special you need to do, just clear the alarm when you wake.