micropython-Chinese-Community / mpy-lib

HTS221, LPS22, LIS2DW12, LIS2MDL, LSM6DSO, STTS751, si7051, bme280, bmp280, APDS9930, TM1650, TM1637, LCD1602, GNSS, all kinds of micropython drives, examples, libs
MIT License
170 stars 73 forks source link

Voltage on SQW #12

Open PaoloFanta opened 2 years ago

PaoloFanta commented 2 years ago

Hello. I state that I am not a programmer. I am using your library and thank you for sharing it. I use it with an ESP32 that I would like to awaken from a deep sleep with a DS3231. The DS3231 is connected to ESP32 with SDA on pin 22 and SCL on pin 23. The SQW pin of the DS3231 to pin 32 of the ESP32. On the DS3231 I was able to correctly set both the time and the alarm for waking up. When ESP32 goes into deep sleep, a problem arises that prevents it from restarting at the time programmed on DS3231. It happens that when ESP32 goes into deep sleep the voltage goes from 0V to 3.28V and immediately reactivates ESP32 in a continuous loop and I cannot understand why. The DS3231 is powered directly from the 3.3v pin of the ESP32 which continues to supply current even when it goes into dormancy. This is my code.

import machine from machine import Pin, I2C, RTC, lightsleep, wake_reason, idle import utime import time import DS3231

i2c = I2C(sda = Pin(22), scl=Pin(23)) ds = DS3231.DS3231(i2c)

led = Pin (18, Pin.OUT) led.value(1) rtc = RTC()

import esp32 from time import sleep sleep(10)

btn1 = Pin(32, Pin.IN, Pin.PULL_DOWN) # Normally low, high when pressed esp32.wake_on_ext0(pin = btn1, level = esp32.WAKEUP_ANY_HIGH) machine.deepsleep()

What could be the problem?

I thank you in advance.

shaoziyang commented 2 years ago

Do you enable alarm interrupt or Square-Wave Output? You can try to set Control Register (0Eh) to 0x1C (default value) to disable SQW, and clear A1F/A2F (Alarm Flag) before enter deepsleep mode.

PaoloFanta commented 2 years ago

thanks for your kind reply. As I explained to you, I am not a programmer, I managed to get here only thanks to what I found on the internet. I'm sorry but I'm unable to go any further on my own.

shaoziyang commented 2 years ago

use ds.setReg(DS3231_REG_CTRL, 0x1C) to disable SQW, and ds.ClearALARM() to clear alarm.

PaoloFanta commented 2 years ago

By adding ds.setReg(DS3231_REG_CTRL, 0x1C)

gives me the following error:

File "main.py", line 27, in NameError: name 'DS3231_REG_CTRL' isn't defined

shaoziyang commented 2 years ago

use ds.setReg(DS3231.DS3231_REG_CTRL, 0x1C)

PaoloFanta commented 2 years ago

The command does not give an error but the SQW pin always remains high.