I'm a little bit confused with the behavior of the I2C of DS3231. Watching the SQW pin at the oscilloscope and firing an alarm it does what is expected to (pulled low and high again). If I remove it from the controller after a while it goes permanently low. Also the same thing happens if the controller goes to power down. I have tried dozens of libraries with the same result. Am I missing something here ? My programming skills are limited I believe, so any help would be appreciated. Lucas
-
What powers the DS3231 when the controller goes to power down?– VE7JROMar 17 at 21:10
-
Hi VE7JRO,I have tried both usb power from pc and external power supply as well.– lucasbMar 17 at 22:11
-
Please let me simplify this. Can DS3231 run a s standalone device ? Will SQW be activated as stand alone ? Any links that might help ?– lucasbMar 17 at 22:22
-
RE: "Please let me simplify this. Can DS3231 run a s standalone device" - you did not answer my question. How is the stand alone device powered? Do you have a picture of it? How a bout a link to the product description? How about a schematic?– VE7JROMar 18 at 1:33
1 Answer
Your observations in your initial post are puzzling, especially "Watching the SQW pin at the oscilloscope and firing an alarm it does what is expected to (pulled low and high again). If I remove it from the controller after a while it goes permanently low. Also the same thing happens if the controller goes to power down.
I think I can address your two subsequent questions...Can DS3231 run as standalone device ? Will SQW be activated as stand alone ?
The answer is "yes, but" to both.
When you have properly configured the DS3231 such that the INT/SQW pin will "fire" when there is a match between the alarm(s) and time registers. It will fire with nothing else connected as long as it has power.
The INT, is open-drain and active low - it requires a pull up resistor tied to a +v in order to do anything with it. So, the chip and the pull up connected to the INT pin need to have power.
I answered "yes, but" and here is the "but". In order to turn the alarm off, you need to communicate with the chip using the I2C interface. You have to clear the A1F or A2F flags in order to de-assert the INT signal. Once an alarm occurs, the INT pin is asserted and it stays asserted until the appropriate flag (A1F or A2f is cleared) or the chip has no power - primary or backup.
I have used DS3231 alarms (e.g., occurring once every 24 hours), using the INT pin and a P-channel MOSFET, to turn power on to an embedded controller [including I2C pull ups resistors], that was programmed to do some thing, and then to shut the alarm off (through I2C), which shut power off to the controller...until an alarm occurred again.
The data sheet requires a good bit of study, at least it did for me, but the information is there.
Edit to address subsequent comment:
So if I understand correct this module cannot work as a standalone device because you can reset it only from the i2c bus ?
You don't reset the device using the I2C bus. The device has an RST pin and you can read about hooking that up to a push button in the data sheet.
You do reset the alarm flags by writing to the device using I2C, as specified, to de-assert the alarm - that is, to shut it off.
It is an I2C device and is not designed to be a stand-alone device as I think you mean.
It is meant to work with and for a microprocessor. Sometimes, RTCs like the DS3231 are refereed to as "stand-alone" as distinguished from embedded MCU RTCs see https://www.powerelectronicsnews.com/when-to-use-a-standalone-rtc-ic-instead-of-an-mcu-embedded-rtc-in-low-power-iot-devices/ for example.
-
Thank you , this is very clear to me. I'm very sorry that I was not clear my self. From the hardware side I am ok since the module board has pull up resistors built in. May be the problem is at my code (in which line of the code I reset the alarm). I will try some modifications and come back to you. Thank you very much Lucas– lucasbMar 18 at 10:48
-
I ade a few modifications at my code and it works fine now (thank you DrG). So if I understand correct this module cannot work as a standalone device because you can reset it only from the i2c bus ?– lucasbMar 19 at 6:19