Hi,
Can anyone out there shed a little light on the implementation of stm32 internal real time clock??
please have a look at my test example and (when you have stopped laughing) help me out....please???
program stm32
'device = stm32f101vb
'hsi 8.0 mhz
dim i as word
main:
GPIO_Clk_Enable(@GPIOd_BASE)
GPIO_Digital_Output(@GPIOD_BASE, _GPIO_PINMASK_all)
'rtc with extrnal 32khz crystal
PWREN_bit=1 'enable clock for Power interface
BKPEN_bit=1 'and backup interface clock
DBP_bit=1 'enable access to RTC, BDC registers
RTCSEL0_bit=1 'select hse clock 32.7khz
RTCSEL1_bit=0 'as above
lseon_bit=1 'enable low speed external clock
lserdy_bit=0
while lserdy_bit=0
wend 'Wait for LSERDY = 1 (LSE is ready)
RTCEN_bit=1 ' set RTC clock source, enable RTC clock
rsf_bit=0 'reset Registers Synchronized Flag
while rsf_bit=0
wend 'wait until registers are synchronized
CNF_bit=1 'enter configuration mode
RTC_PRLL=0x7FFF
RTC_CNTH=0
RTC_CNTL=0
CNF_bit=0 'exit configuration mode
DBP_bit=0 'disable access to RTC, BDC registers
i=0
while TRUE
i = i+1
delay_ms 1000
gpiod_odr.10=1
delay_ms 1000
gpiod_odr.10=0
if i compile the above and rem out the while/wend parts of the configuration i get an output on d14.
if i use the debug watch the rtc variable do not change.
Any help would be great.
Many thanks for taking the time to read and or help.
Ian
wend
end.
internal real time clock
Re: internal real time clock
Hi,
Please find the RTC example on the following links :
http://www.mikroe.com/forum/viewtopic.php?f=178&t=50510
http://www.mikroe.com/forum/viewtopic.php?f=178&t=49563
The examples are written in C, but you can use it as a starting point in your project.
Regards,
Filip.
Please find the RTC example on the following links :
http://www.mikroe.com/forum/viewtopic.php?f=178&t=50510
http://www.mikroe.com/forum/viewtopic.php?f=178&t=49563
The examples are written in C, but you can use it as a starting point in your project.
Regards,
Filip.
Re: internal real time clock
Hi Filip,
Thank you very much for your help, i will give it a try later when i return from work.
cheers,
Ian
Thank you very much for your help, i will give it a try later when i return from work.
cheers,
Ian
Re: internal real time clock
Hi Filip,
Thank you very much,
now i have a clock in my project
structure TimeStructure
dim ss as byte ' seconds
dim mn as byte ' minutes
dim hh as byte ' hours
dim md as byte ' day in month, from 1 to 31
dim wd as byte ' day in week, monday=0, tuesday=1, .... sunday=6
dim mo as byte ' month number, from 1 to 12 (and not from 0 to 11 as with unix C time !)
dim yy as word ' year Y2K compliant, from 1892 to 2038
end structure
dim time1, time2 as TimeStructure
'Init power and clock for RTC
RCC_APB1ENR.BKPEN = 1'Backup interface clock enable
RCC_APB1ENR.PWREN = 1'Power interface clock enable
PWR_CR.DBP = 1 'enable access
RCC_BDCR.RTCSEL0 = 1 '01: LSE oscillator clock used as RTC
RCC_BDCR.RTCSEL1 = 0 '01: LSE oscillator clock used as RTC
RCC_BDCR.RTCEN = 1 'RTC clock enable
RCC_BDCR.LSEON = 1 'External 32 kHz oscillator ON
PWR_CR.DBP = 0 'Schreibschutz der BackupDomainRegister einschalten
'RTC-Register sycned?
RTC_CRL.RSF = 0
while RTC_CRL.RSF =0
wend
'Config RTC
while RTC_CRL.RTOFF =0
wend
'// Configmode on
RTC_PRLL = 32768 '// RTC-clock-prescaler
RTC_CRL.CNF = 0 '// Configmode off
'while RTC_CRL.RTOFF =0
'wend
while TRUE
loword(epoch) = rtc_cntl + loword(date)
hiword(epoch) = rtc_cnth + hiword(date)
Time_epochToDate(epoch,@time2)
sec = time2.ss
min = time2.mn
hour = time2.hh
day = time2.wd
delay_ms 500
wend
Many thanks for your help
ian
Thank you very much,
now i have a clock in my project
structure TimeStructure
dim ss as byte ' seconds
dim mn as byte ' minutes
dim hh as byte ' hours
dim md as byte ' day in month, from 1 to 31
dim wd as byte ' day in week, monday=0, tuesday=1, .... sunday=6
dim mo as byte ' month number, from 1 to 12 (and not from 0 to 11 as with unix C time !)
dim yy as word ' year Y2K compliant, from 1892 to 2038
end structure
dim time1, time2 as TimeStructure
'Init power and clock for RTC
RCC_APB1ENR.BKPEN = 1'Backup interface clock enable
RCC_APB1ENR.PWREN = 1'Power interface clock enable
PWR_CR.DBP = 1 'enable access
RCC_BDCR.RTCSEL0 = 1 '01: LSE oscillator clock used as RTC
RCC_BDCR.RTCSEL1 = 0 '01: LSE oscillator clock used as RTC
RCC_BDCR.RTCEN = 1 'RTC clock enable
RCC_BDCR.LSEON = 1 'External 32 kHz oscillator ON
PWR_CR.DBP = 0 'Schreibschutz der BackupDomainRegister einschalten
'RTC-Register sycned?
RTC_CRL.RSF = 0
while RTC_CRL.RSF =0
wend
'Config RTC
while RTC_CRL.RTOFF =0
wend
'// Configmode on
RTC_PRLL = 32768 '// RTC-clock-prescaler
RTC_CRL.CNF = 0 '// Configmode off
'while RTC_CRL.RTOFF =0
'wend
while TRUE
loword(epoch) = rtc_cntl + loword(date)
hiword(epoch) = rtc_cnth + hiword(date)
Time_epochToDate(epoch,@time2)
sec = time2.ss
min = time2.mn
hour = time2.hh
day = time2.wd
delay_ms 500
wend
Many thanks for your help
ian
Re: internal real time clock
Hi,
How to update date and time on RTC.
How to update date and time on RTC.