1522 views|2 replies

6060

Posts

6

Resources
The OP
 

【AT32WB415 Review】05 RTC Test + Adding Electronic Clock Interface [Copy link]

Preface

In order to enrich the test content and further understand the Arteli development board, this chapter mainly familiarizes you with the content of RTC and adds a test interface;

Target

Be familiar with the basic configuration and basic operation of RTC;

Added RTC test interface;

accomplish

1. Understand the RTC function of the Jie Yatli development board

The RTC of the Arteli development board is also called ERTC. Its function is to provide calendar management. Because its counting logic acts in the battery-powered domain, as long as there is power in the battery-powered domain, ERTC will not be affected by system reset and VDD power failure.

ERTC's ck_b is used to update the calendar. The development board contains an external 32.768kHz clock, which is preferably obtained through LEXT through divider A and divider B. ck_b=LEXT/(divA+1)/(divB+1). For example, the 32.768K clock is obtained through divider A 127 and divider B 255 to obtain a frequency of 1Hz.

After power-on reset, all ERTC registers are in write-protected state. Be sure to remove the write protection before erasing. This part is basically the same as the configuration process of most MCUs, remove the write protection - write configuration - write protection. Some registers need to enter the initialization mode to be changed.

The time register and date register of ERTC are the registers that need to be accessed frequently. Updating the calendar is to directly update these two registers. This is slightly different from the GD microcontroller. GD is actually a 64-bit register that only stores an auto-increment number. The specific time setting needs to be designed by yourself. Here you can directly access the time-related registers, which is more like an external real-time clock mode. You can directly obtain the year, month, day, hour, minute, and second. However, the statistical time range of ERTC is not given, and there is no introduction to the leap year mechanism. The year in the register only has tens and digits.

2. ERTC initialization

Combined with the technical manual and demo, design the ERTC initialization program:

void ertc_config(void)
{
  /* allow access to ertc */
  pwc_battery_powered_domain_access(TRUE);
  /* reset ertc domain */
  crm_battery_powered_domain_reset(TRUE);
  crm_battery_powered_domain_reset(FALSE);
  /* enable the lext osc */
  crm_clock_source_enable(CRM_CLOCK_SOURCE_LEXT, TRUE);
  /* wait till lext is ready */
  while(crm_flag_get(CRM_LEXT_STABLE_FLAG) == RESET)
  {
  }
  /* select the ertc clock source */
  crm_ertc_clock_select(CRM_ERTC_CLOCK_LEXT);
  /* enable the ertc clock */
  crm_ertc_clock_enable(TRUE);

  /* deinitializes the ertc registers */
  ertc_reset();
  /* wait for ertc apb registers update */
  ertc_wait_update();
  
  /* configure the ertc divider */
  /* ertc second(1hz) = ertc_clk / (div_a + 1) * (div_b + 1) */
  ertc_divider_set(127, 255);
  /* configure the ertc hour mode */
  ertc_hour_mode_set(ERTC_HOUR_MODE_24);

  eRTC_set.year     = 22;
  eRTC_set.month    = 8;
  eRTC_set.day      = 18;
  eRTC_set.hour     = 8;
  eRTC_set.min      = 0;
  eRTC_set.sec      = 0;
  eRTC_set.week     = 4;
  Set_Time(&eRTC_set);
}

void Set_Time(ertc_time_type* time)
{
  /* set date  */
  ertc_date_set(time->year,time->month,time->day,time->week);
  /* set time*/
  ertc_time_set(time->hour,time->min,time->sec,ERTC_AM);
}

uint32_t bpr_reg_get(uint8_t index)
{
  if(index >= ERTC_BPR_DT_NUMBER)
  {
    index = 0;
  }
  return ertc_bpr_data_read(bpr_addr_tab[index]);
}

void bpr_reg_write(uint8_t index,uint32_t DT_data)
{
  ertc_bpr_data_write(bpr_addr_tab[index],DT_data);
}

Initialize the application after each battery domain reset. You can use the battery power data register (RTC_BPRx) to store the identification code. The manual says there are 76 registers in total, but there are only 20 in the demo, which is enough. The data register is 0x00000000 after reset. If it is not a custom identification code, it means that an abnormality has occurred and it is necessary to initialize the ERTC.

The inspection program code is as follows:

void port_RTC_init(void)
{
  /* enable the pwc clock interface */
  crm_periph_clock_enable(CRM_PWC_PERIPH_CLOCK, TRUE);
  /* allow access to bpr domain */
  pwc_battery_powered_domain_access(TRUE);
  /* check data from bpr dt register */
  if(bpr_reg_get(0) != ERTC_BPR_DT1)
  {
    /* ertc configuration */
    ertc_config();
    /* write to ertc bpr data registers */
    bpr_reg_write(0,ERTC_BPR_DT1);
  }
  else
  {
    /* wait for ertc registers update */
    ertc_wait_update();
  }
  
}

3. Interface design

"RTC Test" is added to the main menu. In the "RTC Test" interface, "RTC Display", "Electronic Stopwatch (Reserved)" and "Time Setting" are initially added. However, due to the limited buttons, "Time Setting" is difficult to implement and will not be implemented for the time being. It will be set through serial port commands during the serial port communication test. As for whether the electronic stopwatch is more suitable to be implemented based on RTC or timer, it will not be implemented as an expansion for the time being. In the end, only the "RTC Display" interface is designed, and other functions are reserved.

The final effect is as follows:

WeChat_20220822215951

This post is from RF/Wirelessly

Latest reply

The RTC of the Arteli development board is also called ERTC. Its function is to provide calendar management. Because its counting logic acts in the battery-powered domain, as long as there is power in the battery-powered domain, ERTC will not be affected by system reset and VDD power failure. It is enough for daily time management.   Details Published on 2022-8-23 11:22
Personal signature

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 

6841

Posts

11

Resources
2
 

The RTC of the Arteli development board is also called ERTC. Its function is to provide calendar management. Because its counting logic acts in the battery-powered domain, as long as there is power in the battery-powered domain, ERTC will not be affected by system reset and VDD power failure.

It is enough for daily time management.

This post is from RF/Wirelessly

Comments

Mutual efforts  Details Published on 2022-8-23 15:39
 
 

6060

Posts

6

Resources
3
 
lugl4313820 published on 2022-8-23 11:22 The RTC of the Arteli development board is also known as ERTC. Its function is to provide calendar management. Because its counting logic acts in the battery power domain, as long as the battery...

Mutual efforts

This post is from RF/Wirelessly
 
 
 

Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>
快速回复 返回顶部 Return list