Post
by vahithosan » Sat Aug 05, 2017 10:40 pm
I am confused when working with ds3231. I dont understand how the alarm works. I want an alarm every minute.
I can not see changes in 0E and 0F.
[code]
import network
import utime
import machine
import urtc
import ustruct
import network, time
from ntptime import settime
from machine import I2C, Pin
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('SSID', 'PASSWD')
sta_if.ifconfig()
i2c = I2C(scl=Pin(5), sda=Pin(4))
rtc = urtc.DS3231(i2c)
settime()
tampon1=utime.time()
tampon2=tampon1+10800
datetime = urtc.seconds2tuple(tampon2)
rtc.datetime(datetime)
rtc.datetime()
rtc.alarm_time((None,None,None,None,None,None,55))
[/code]
[code]
def liste():
s=rtc.datetime()
al=rtc.alarm_time()
print("Time : ",s.year,s.month,s.day,s.hour,s.minute,s.second,sep=" | ")
print("Alarm : ",s.year,s.month,s.day,s.hour,s.minute,al.second,sep=" | ")
print("Is alarm set ? ",rtc.alarm())
print("#"*36)
for i in range(0,19):
a = i2c.readfrom_mem(104,i,1)
b = ustruct.unpack('<h',a)
c = '{:08b}'.format(b[0])
print("{:0{}x}".format(i,2),c[0],c[1],c[2],c[3],c[4],c[5],c[6],c[7],sep=" | ",end="")
print(" | ")
print("-"*36)
return
[/code]
>>> liste()
Time : | 2017 | 8 | 6 | 1 | 19 | 34
Alarm : | 2017 | 8 | 6 | 1 | 19 | 55
Is alarm set ? True
####################################
------------------------------------
0e | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
------------------------------------
0f | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 |
------------------------------------
>>> liste()
Time : | 2017 | 8 | 6 | 1 | 19 | 55
Alarm : | 2017 | 8 | 6 | 1 | 19 | 55
Is alarm set ? True
####################################
------------------------------------
0e | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
------------------------------------
0f | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 |
------------------------------------
>>> liste()
Time : | 2017 | 8 | 6 | 1 | 19 | 56
Alarm : | 2017 | 8 | 6 | 1 | 19 | 55
Is alarm set ? True
####################################
------------------------------------
0e | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
------------------------------------
0f | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 |
------------------------------------
Thanks.