nuvoton - M451 Real Time Clock

RTC 的特性

  • 1 組 RTC counter
Register
Description
Value
TLR
Time Counter
0x00144422
PM 02:44:22
CLR
Calendar Counter
0x00200203
2020/02/03
DWR
Day of the Week Counter
0x00000001
Monday
LIR
Leap Year Indication
0x00000001
Leap year
TAR
Time Alarm Value
0x00150000
PM 03:00:00
CAR
Calendar Alarm Value
0x00200204
2020/02/04
  • 支援 Alarm 和 time tick 中斷
  • 支援 Wake-up
  • 32 KHz 頻率校正
  • 80 Bytes RTC register 來儲存資料

RTC 的 Block Diagram


RTC 模組內部一個計數器,可以運用來做時間的計時器,也可以運用來當鬧鐘,在設定的時間產生中斷,喚醒 MCU。RTC 模組不一樣的部分,不需要再設定 clock source,只需要 Enable 模組。

RTC Coding Flow

  • Enable Clock for RTC module
  • CLK_EnableModuleClock(RTC_MODULE);
    
  • Open RTC module and start couting
  • S_RTC_TIME_DATA_T sWriteRTC;
    
     sWriteRTC.u32Year       = 2020;
     sWriteRTC.u32Month      = 1;
     sWriteRTC.u32Day        = 21;
     sWriteRTC.u32DayOfWeek  = RTC_TUESDAY;
     sWriteRTC.u32Hour       = 15;
     sWriteRTC.u32Minute     = 30;
     sWriteRTC.u32Second     = 30;
     sWriteRTC.u32TimeScale  = RTC_CLOCK_24;
     RTC_Open(&sWriteRTC);
    
  • Enable RTC interrupt
  • NVIC_EnableIRQ(RTC_IRQn);
    
    RTC_EnableInt(RTC_INTEN_TICKIEN_Msk);
    RTC_SetTickPeriod(RTC_TICK_1_4_SEC);
    
  • Timer #0 Interrupt Service
  • void RTC_IRQHandler(void)
    {
        /* To check if RTC tick interrupt occurred */
        if(RTC_GET_TICK_INT_FLAG() == 1)
        {
            /* Clear RTC tick interrupt flag */
            RTC_CLEAR_TICK_INT_FLAG();
        }
    }
    
範例程式 :
在 FreeRTOS 中,加入一個 Task 來完成 RTC 中斷比較耗時的工作,平常 Task 位於 Suspend 的狀態,在 1/4 秒會產生中斷,喚醒 Task 做時間的計時,並每秒顯示在 UART console.


範例程式位於 Github 的 nuvotoon-M451-Sample 的 FreeRTOS-RTC-Sample branch

Reference document :

  • nuvoton NuMicro-M451-Series-Training-Material
  • nuvoton TRM_M451_Series_EN_Rev2.08 

留言

這個網誌中的熱門文章

EC 所需知識 - SMBUS

EC 所需知識 - LPC

EC 所需知識 - KBC