cancel
Showing results for 
Search instead for 
Did you mean: 

SPC560BL1-RTC Configuration

baskar
Associate II
Posted on April 29, 2016 at 16:10

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 #!colorado
3 REPLIES 3
procolo
Senior
Posted on April 29, 2016 at 17:11

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,

Procolo

baskar
Associate II
Posted on May 13, 2016 at 04:09

We need RTC for calender purpose,is it possible to configure the RTC with real date & Time

procolo
Senior
Posted on May 13, 2016 at 13:21

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