internal real time clock

General discussion on mikroBasic PRO for ARM.
Post Reply
Author
Message
dorro
Posts: 13
Joined: 16 Sep 2012 02:28

internal real time clock

#1 Post by dorro » 17 Sep 2012 21:02

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.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: internal real time clock

#2 Post by filip » 18 Sep 2012 08:54

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.

dorro
Posts: 13
Joined: 16 Sep 2012 02:28

Re: internal real time clock

#3 Post by dorro » 18 Sep 2012 09:23

Hi Filip,

Thank you very much for your help, i will give it a try later when i return from work.



cheers,

Ian

dorro
Posts: 13
Joined: 16 Sep 2012 02:28

Re: internal real time clock

#4 Post by dorro » 23 Sep 2012 01:11

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

hIMANSh
Posts: 158
Joined: 01 Jan 2011 17:48

Re: internal real time clock

#5 Post by hIMANSh » 29 Mar 2014 05:28

Hi,

How to update date and time on RTC.

Post Reply

Return to “mikroBasic PRO for ARM General”