I'm looking to use the RTC allarms to activate at a certain HR:MM two relays and after a certain time (20-40 minutes ) deactivate.
I've started reading the AN3371 documents about the usage of RTC in STM32F4 MCU and then the RM0090 Datasheet to understand which register were involved and whic sequence use to set the allarms.
Looking page 11 of AN3371 I found this clear table that explain how proceed to set the allarms
and in the below part of code I think to have implemented what required to set the Allarm A every day at 23:00
Code: Select all
class BkpRAM(object):
BKPSRAM = 0x40024000
def __init__(self):
stm.mem32[stm.RCC + stm.RCC_APB1ENR] |= 0x10000000 # PWREN bit
stm.mem32[stm.PWR + stm.PWR_CR] |= 0x100 # Set the DBP bit in the PWR power control register
stm.mem32[stm.RCC +stm.RCC_AHB1ENR]|= 0x40000 # enable BKPSRAMEN
stm.mem32[stm.PWR + stm.PWR_CSR] |= 0x200 # BRE backup register enable bit
def __getitem__(self, idx):
assert idx >= 0 and idx <= 0x3ff, "Index must be between 0 and 1023"
return stm.mem32[self.BKPSRAM + idx * 4]
def __setitem__(self, idx, val):
assert idx >= 0 and idx <= 0x3ff, "Index must be between 0 and 1023"
stm.mem32[self.BKPSRAM + idx * 4] = val
class RTC_SETALA(object): #VEDI PDF USO RTC E DATASHEET CPU PER DEFINIRE COME USARE ALLARMI RTC INTEGRATO NELLA CPU.
def __init__(self):
stm.mem32[stm.RTC + stm.RTC_WPR] |= 0x000000CA #pag 11 an3371
stm.mem32[stm.RTC + stm.RTC_WPR] |= 0x00000053
stm.mem32[stm.RTC + stm.RTC_CR] = 0x00000000
pyb.delay(5)
if stm.mem32[stm.RTC + stm.RTC_ISR] &0x0001 == 0x0001 : #test ALRAWF IN RTC_ISR
stm.mem32[stm.RTC + stm.RTC_ALRMAR] |= 0x86230000 #set allarm A @ 23:00 of every day
stm.mem32[stm.RTC+stm.RTC_CR] |= 0x00000010
stm.mem32[stm.RTC + stm.RTC_WPR] = 0x000000FF
Where I'm wrong this time ?
