2094 views|4 replies

1455

Posts

1

Resources
The OP
 

【AT-START-F425 Review】+ ERTC and the implementation of electronic clock [Copy link]

 

The AT32 F425 is equipped with an RTC timer, which can be used in conjunction with the corresponding functions to realize the RTC timing and timing functions. The operating effect is shown in Figure 1.

Figure 1 Operation effect

If RTC is combined with OLED screen, the function of electronic clock can be easily realized.

Based on the OLED screen display driver introduced above, the main program to achieve the timing effect in Figure 2 is:

int main(void)
{
 exint_init_type exint_init_struct;
 ertc_time_type time;
 uint32_t temp = 0;
 system_clock_config();
  nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
 at32_board_init();
  crm_periph_clock_enable(CRM_PWC_PERIPH_CLOCK, TRUE);
 pwc_battery_powered_domain_access(TRUE);
 if (ertc_bpr_data_read(ERTC_DT1) != 0x1234)
 {
 ertc_config(); // 设置时间值函数,添加按键参数设置功能!
 }
 else
 {
 ertc_wait_update();
 ertc_flag_clear(ERTC_ALAF_FLAG);
 exint_flag_clear(EXINT_LINE_17);
 }
 exint_default_para_init(&exint_init_struct);
 exint_init_struct.line_enable = TRUE;
 exint_init_struct.line_mode = EXINT_LINE_INTERRUPUT;
 exint_init_struct.line_select = EXINT_LINE_17;
 exint_init_struct.line_polarity = EXINT_TRIGGER_RISING_EDGE;
 exint_init(&exint_init_struct);
 nvic_irq_enable(ERTC_IRQn, 0, 1);
 app_oled_init();
 app_oled_init();
 OLED_Init();
 OLED_Clear();
 OLED_ShowString(8,0,"AT32F425",16);
 OLED_ShowString(8,2,"OLED & RTC",16);
 while(1)
 {
 ertc_calendar_get(&time);
 if(temp != time.sec)
 {
 temp = time.sec;
  sprintf(da_buf,"20%02d-%02d-%02d ",time.year, time.month, time.day);
 OLED_ShowString(8,4,da_buf,16);
   sprintf(da_buf,"%02d:%02d:%02d",time.hour, time.min, time.sec);
  OLED_ShowString(8,6,da_buf,16);
 }
 }
}

The processing flow of the program is:

First, the RTC is initialized, and then the flag variable is identified. If the initial timing value is not set, the initial value in the program is read to count. Otherwise, the timing is processed based on the existing timing value.

Figure 2 Display effect

The initial value of RTC is set in the function ertc_config, and its content is:

hh =12;
nn=0;
ss=0;
void ertc_config(void)
{
 crm_periph_clock_enable(CRM_PWC_PERIPH_CLOCK, TRUE);
 pwc_battery_powered_domain_access(TRUE);
 crm_battery_powered_domain_reset(TRUE);
 crm_battery_powered_domain_reset(FALSE);
#if defined (ERTC_CLOCK_SOURCE_LICK)
 crm_clock_source_enable(CRM_CLOCK_SOURCE_LICK, TRUE);
 while(crm_flag_get(CRM_LICK_STABLE_FLAG) == RESET)
 {
 }
 crm_ertc_clock_select(CRM_ERTC_CLOCK_LICK);
 ertc_clk_div_b = 255;
 ertc_clk_div_a = 127;
#elif defined (ERTC_CLOCK_SOURCE_LEXT)
 crm_clock_source_enable(CRM_CLOCK_SOURCE_LEXT, TRUE);
 while(crm_flag_get(CRM_LEXT_STABLE_FLAG) == RESET)
 {
 }
 crm_ertc_clock_select(CRM_ERTC_CLOCK_LEXT);
 ertc_clk_div_b = 255;
 ertc_clk_div_a = 127;
#endif
 crm_ertc_clock_enable(TRUE);
 ertc_reset();
 ertc_wait_update();
 ertc_divider_set(ertc_clk_div_a, ertc_clk_div_b);
 ertc_hour_mode_set(ERTC_HOUR_MODE_24);
 ertc_date_set(22, 3, 2, 3);
 ertc_time_set(hh ,nn ,ss, ERTC_AM);
 ertc_alarm_mask_set(ERTC_ALA, ERTC_ALARM_MASK_DATE_WEEK);
 ertc_alarm_week_date_select(ERTC_ALA, ERTC_SLECT_DATE);
 ertc_flag_clear(ERTC_ALAF_FLAG);
 ertc_bpr_data_write(ERTC_DT1, 0x1234);
}

To facilitate time synchronization, you can add a key processing function to set parameters.

Since there is only one user key on the development board, it is not convenient for parameter setting, so a membrane key is configured for it, and 3 of the keys can be used. The "1" key is used for -1, the "2" key is used for +1, and the "3" key is used for confirmation.

The connection relationship between the button and the development board is:

key1---PB5

key2---PB3

key3---PA10

GND---PB10

Figure 3 Arduino interface

#define key1 gpio_input_data_bit_read(GPIOB, GPIO_PINS_5)

#define key2 gpio_input_data_bit_read(GPIOB, GPIO_PINS_4)

#define key3 gpio_input_data_bit_read(GPIOA, GPIO_PINS_10)

The corresponding time setting function is:

void time_set(void)
{
 int8_t i=0,n;
 n=hh;
 i=0;
 while (i<3)
 {
 if(key1==0)
 {
 n--;
 }
 if(key2==0)
 {
 n++;
 }
 if(key3==0)
  {
 if(i==0)
 {
 n=mm;
 }
  if(i==1)
 {
 n=ss;
 }
 i++;
  while(key3==0);
 }
 if(i==0)
 {
 hh=n;
 OLED_ShowNum(8,6,hh,2,16);
 }
 if(i==1)
 {
 mm=n;
 OLED_ShowNum(32,6,mm,2,16);
 }
 if(i==2)
 {
 ss=n;
 OLED_ShowNum(56,6,ss,2,16);
 }
 delay_ms(200);
 }
}

Among them, the variable hh stores the time value, the variable mm stores the minute value, and the variable ss stores the second value.

The date setting function can be similar.

This post is from Domestic Chip Exchange

Latest reply

This E always feels external.   Details Published on 2022-4-7 09:35
 
 

6788

Posts

2

Resources
2
 

ERTC is internal RTC?

This post is from Domestic Chip Exchange

Comments

yes  Details Published on 2022-4-7 00:10
 
 
 

1455

Posts

1

Resources
3
 
wangerxian posted on 2022-4-6 16:02 Is ERTC an internal RTC?

yes

This post is from Domestic Chip Exchange

Comments

This E always feels external.  Details Published on 2022-4-7 09:35
 
 
 

6788

Posts

2

Resources
4
 

This E always feels external.

This post is from Domestic Chip Exchange

Comments

That makes sense, but it may be to distinguish it from the so-called soft RTC now!  Details Published on 2022-4-7 11:05
 
 
 

1455

Posts

1

Resources
5
 
wangerxian posted on 2022-4-7 09:35 This E always feels external

That makes sense, but it may be to distinguish it from the so-called soft RTC now!

This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list