I'm trying to write a library for internal RTC in Micropython on Rp2. And I've found a problem I can't deal with.
To setup the time I use a code:
Code: Select all
import uctypes
RTC_BASE = 0x4005c000
RTC_SETUP_0 = 0x04 # RTC setup register 0
RTC_SETUP_1 = 0x08 # RTC setup register 1
RTC_CTRL = 0x0c # RTC Control and status
def setTimeDate(year, month, day, dow, hours, mins, secs=0):
ctrl = uctypes.bytearray_at(RTC_BASE + RTC_CTRL, 1)
ctrl[0] = 0 # stop RTC
setup_0 = uctypes.bytearray_at(RTC_BASE + RTC_SETUP_0, 4)
setup_0[0] = day # 1..31
setup_0[1] = month + ((year<<4) & 0xF0)
setup_0[2] = year >> 4
setup_1 = uctypes.bytearray_at(RTC_BASE + RTC_SETUP_1, 4)
setup_1[0] = secs
setup_1[1] = mins
setup_1[2] = hours
setup_1[3] = dow
ctrl[0] = 0x13 # load RTC registers, start RTC
I can't wite different values for every byte. For example, I want to set time to Monday, 12:30:00:
Code: Select all
setup_1 = uctypes.bytearray_at(RTC_BASE + RTC_SETUP_1, 4)
setup_1[0] = 00
setup_1[1] = 30
setup_1[2] = 12
setup_1[3] = 1
The last value I've written to SETUP_1 is setup_1[3] = 1.
Could someone help me?
Regards, kjk