2016-04-29 07:10 AM
I am trying to configure the RTC using for date & time purpose. But the following RTC configuration is not working,when i debug the code it is hanging at R TC.RTCCNT.B.RTCCNT .How to use RTC is timer counter for date & time.
SPCSetPeripheralClockMode(91, SPC5_ME_PCTL_RUN(1) | SPC5_ME_PCTL_LP(1)); /*configure RTC module as autonomous periodic interrupt to generate internal wakeup event*/ RTC.RTCC.B.CNTEN =0 ; //counter reset and stop RTC.RTCSUPV.B.SUPV =0 ; //counter reset and stop RTC.RTCC.B.CLKSEL = 0x01 ; //set SIRC as source clock for API RTC.RTCC.B.DIV32EN= 0; //Divide clock for 32 is not used RTC.RTCC.B.DIV512EN = 1; //divide clock for 512 RTC.RTCC.B.APIVAL = 512/4; //set API timer to 2 Seconds RTC.RTCCNT.B.RTCCNT =5678327; RTC.RTCS.R=0xFFFFFFFF; RTC.RTCC.B.CNTEN =1 ; //counter reset and stop #spc56 #rtc #!colorado2016-04-29 08:11 AM
Hi,
debug is hanging when writing RTCCNT because this is a Read Only Register.A sample code for RTC could be the following: SPCSetPeripheralClockMode(91, SPC5_ME_PCTL_RUN(1) | SPC5_ME_PCTL_LP(1)); /*configure RTC module */ RTC.RTCC.B.CNTEN =0 ; //counter reset and stop RTC.RTCSUPV.B.SUPV =0 ; //counter reset and stop RTC.RTCC.B.CLKSEL = 0x01 ; //set SIRC (128KHZ) as source clock for RTC RTC.RTCC.B.DIV32EN= 0; //Divide clock for 32 is not used RTC.RTCC.B.DIV512EN = 1; //divide clock for 512 RTC.RTCC.B.CNTEN =1 ; //counter reset and stop after the last command, RTC starts from 0 with a frequency of (128khz / 512) = 250Hz that means counter will be incremented by 1 each 4 milliseconds Regards, Procolo2016-05-12 07:09 PM
2016-05-13 04:21 AM
Hi,
a solution could be the following: set the RCT with SIRC as source and 32 divider on. counter will increse then each 1ms.The 32bit RTC counter register will give you an autonomy of about 1 month and half.If you need more , you can set an RTC interrupt each second and increment a 32bit variable each time (about 136 years of time).Regards,Procolo