stm32f103 RTC periodic standby wake-up (I)

Publisher:Chunjie2022Latest update time:2019-03-29 Source: eefocusKeywords:stm32f103  RTC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I have been working on a low-power device for several days, but the program has been stuck in one place (see the picture below). Today I finally found out where the problem lies. I will summarize the problems of standby wakeup (only for the problems I encountered, the other parts are available on the Internet, based on stm32f103)



1. Solve the problems I encountered

       My RTC initialization part has a "judgment of whether the RTC flag stored in the backup register has been configured". If it has been configured, it will enter the else part, but this else part does not have the configuration statements "to enable the power clock, enable the backup clock, and cancel the write protection of the backup area". After the standby wakes up, the program will execute from the main function and will execute to the else part. Because there are no such configuration statements, the alarm clock will not be assigned again and it will be stuck there. (Those configuration statements are in the clock_ini function, with comments)


2. Whether to add extiline17 event in standby mode

If the service program of the alarm interrupt is placed in void RTC_IRQHandler(void) for processing, the extiline17 event is not required to wake up (tested). If the service program of the alarm interrupt is placed in void RTCAlarm_IRQHandler(void) for processing, the extiline17 event is required


3. RTCAlarm_IRQn and RTC_IRQn priority

I saw on the Internet that the priority of RTCAlarm_IRQn should be set higher than that of RTC_IRQn, but if the service program of the alarm interrupt is placed in void RTC_IRQHandler(void), it is not necessary to set it this way. If the service program of the alarm interrupt is placed in void RTCAlarm_IRQHandler(void), it is necessary to set the priority. It is best to solve the priority problem according to the situation.


4. Here are some of my codes

 

 

  1. void Clock_ini(void)

  2. {

  3. if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) //Judge whether the RTC flag stored in the backup register has been configured

  4. {

  5. printf("\r\n\n RTC not yet configured....");

  6. RTC_Configuration(); //RTC initialization

  7. printf("\r\n RTC configured....");

  8. Time_Adjust(); //Set RTC clock parameters

  9. BKP_WriteBackupRegister(BKP_DR1, 0xA5A5); //After RTC is set, write the configured flag to the backup data register

  10. }

  11. else

  12. {

  13. if(RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) //Check whether power is off and restarted

  14. {

  15. printf("\r\n\n Power On Reset occurred....");

  16. }

  17. else if(RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) //Check if reset is set

  18. {

  19. printf("\r\n\n External Reset occurred....");

  20. }

  21. printf("\r\n No need to configure RTC....");

  22. /***Newly added, test, after waking up from standby, the program does not go through the above if part, so there are no these three steps (two statements), so the program will get stuck, so add it, sure enough***/

  23. RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  24. /* Allow access to BKP area */

  25. PWR_BackupAccessCmd(ENABLE);

  26.  

  27. RTC_WaitForSynchro(); //Wait for the RTC register to be synchronized

  28. RTC_ITConfig(RTC_IT_SEC, ENABLE); //Enable second interrupt

  29. RTC_WaitForLastTask();

  30. RTC_ITConfig(RTC_IT_ALR, ENABLE); //naozhong

  31. RTC_WaitForLastTask(); //Wait for writing to complete

  32. }

  33. RCC_ClearFlag(); //Clear reset flag

 
  1. void NVIC_Configuration(void)

  2. {

  3. NVIC_InitTypeDef NVIC_InitStructure;

  4. EXTI_InitTypeDef EXTI_InitStructure;

  5.  

  6. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

  7.  

  8. /* Enable the RTC Interrupt */

  9. NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; //Configure external interrupt source (second interrupt)

  10. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

  11. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 7;

  12. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  13. NVIC_Init(&NVIC_InitStructure);

  14.  

  15. /* Enable the RTC Alarm Interrupt */

  16. NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn; //Configure external interrupt source (alarm interrupt)

  17. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

  18. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;

  19. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  20. NVIC_Init(&NVIC_InitStructure);

  21.  

  22. //The alarm interrupt is connected to the 17th line external interrupt

  23. EXTI_ClearITPendingBit(EXTI_Line17);

  24. EXTI_InitStructure.EXTI_Line = EXTI_Line17;

  25. EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

  26. EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;

  27. EXTI_InitStructure.EXTI_LineCmd = ENABLE;

  28. EXTI_Init(&EXTI_InitStructure);

  29. }

 
  1. void RTC_Configuration(void)

  2. {

  3. /* Enable PWR and BKP clocks */

  4. RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  5. /* Allow access to BKP area */

  6. PWR_BackupAccessCmd(ENABLE);

  7. /* Reset BKP */

  8. BKP_DeInit();

  9. #ifdef RTCClockSource_LSI

  10. /* Enable internal RTC clock */

  11. RCC_LSICmd(ENABLE);

  12. /* Wait for the RTC internal clock to be ready*/

  13. while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)

  14. {

  15. }

  16. /* Select RTC internal clock as RTC clock */

  17. RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);

  18. #elif defined RTCClockSource_LSE

  19. /* Enable RTC external clock */

  20. RCC_LSEConfig(RCC_LSE_ON);

  21. /* Wait for RTC external clock to be ready*/

  22. while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)

  23. {

  24. }

  25. /* Select RTC external clock as RTC clock */

  26. RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

  27. #endif

  28. /* Enable RTC clock */

  29. RCC_RTCCLKCmd(ENABLE);

  30.  

  31.  

  32. #ifdef RTCClockOutput_Enable

  33. /* Disable the Tamper Pin */

  34. BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper

  35. functionality must be disabled */

  36.  

  37. /* Enable RTC clock output on TAMPER pin */

  38. BKP_RTCCalibrationClockOutputCmd(ENABLE);

  39. #endif

  40.  

  41. /* Wait for RTC register synchronization */

  42. RTC_WaitForSynchro();

  43.  

  44. /* Wait for writing RTC register to complete */

  45. RTC_WaitForLastTask();

  46.  

  47. /* Enable RTC naozhong interrupt */

  48. RTC_ITConfig(RTC_IT_ALR, ENABLE);

  49.  

  50. /* Wait for writing RTC register to complete */

  51. RTC_WaitForLastTask();

  52.  

  53. /* Enable RTC seconds interrupt */

  54. RTC_ITConfig(RTC_IT_SEC, ENABLE);

  55.  

  56. /* Wait for writing RTC register to complete */

  57. RTC_WaitForLastTask();

  58.  

  59. /* Set RTC prescaler */

  60. #ifdef RTCClockSource_LSI

  61. RTC_SetPrescaler(31999); /* RTC period = RTCCLK/RTC_PR = (32.000 KHz)/(31999+1) */

  62. #elif defined RTCClockSource_LSE

  63. RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */

  64. #endif

  65.  

  66. /* Wait for writing RTC register to complete */

  67. RTC_WaitForLastTask();

  68. }

 
  1. void RTCAlarm_IRQHandler(void)

  2. {

  3. RTC_WaitForSynchro();

  4. if(RTC_GetITStatus(RTC_IT_ALR) != RESET)

  5. {

  6. //printf("mmmmmm");

  7. EXTI_ClearITPendingBit(EXTI_Line17);

  8. RTC_WaitForLastTask();

  9. if(PWR_GetFlagStatus(PWR_FLAG_WU) != RESET)

  10. {

  11. // Clear the wake-up flag

  12. PWR_ClearFlag(PWR_FLAG_WU);

  13. RTC_WaitForLastTask();

  14. }

  15. RTC_ClearITPendingBit(RTC_IT_ALR);

  16. RTC_WaitForLastTask();

  17. printf("\nIt will wake up after %ds\n",standbytime);

  18. RTC_Enter_StandbyMode(standbytime); //Wake up after standbytime seconds

  19. }

  20. }

 
  1. void RTC_Enter_StandbyMode(u32 s)

  2. {

  3. RTC_WaitForLastTask();

  4. RTC_SetAlarm(RTC_GetCounter()+s);

  5. RTC_WaitForLastTask();

  6. // Enter standby mode, at this time all 1.8V domain clocks are turned off, HIS and HSE oscillators are turned off, and voltage regulators are turned off.

  7. // Only WKUP pin rising edge, RTC warning event, NRST pin external reset, IWDG reset.

  8. /* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */

  9. PWR_EnterSTANDBYMode();

  10. }

5. In the next few days, I will study the shutdown mode and power consumption issues.


Keywords:stm32f103  RTC Reference address:stm32f103 RTC periodic standby wake-up (I)

Previous article:STM32 sleep and wake-up
Next article:STM32 enters low power mode and wakes up (RTC+interrupt)

Recommended ReadingLatest update time:2024-11-16 15:30

Five-point correction algorithm for STM32f103 resistive touch screen
Since the resistive touch screen is a sensor, it uses pressure sensing for control and converts the physical position of the touch point (X, Y) in the rectangular area into a voltage representing the X coordinate and the Y coordinate. Here we first introduce two concepts, physical coordinates and logical coordinates.
[Microcontroller]
Five-point correction algorithm for STM32f103 resistive touch screen
Internal peripheral resources of different stm32f103 chips
As can be seen from the table, the peripheral resources inside the chip are not only related to the first letter after stm32f103, but also to the size of the flash. The above table only contains part of it. For details, please refer to the chip model selection section of Keil. Here are the resources of stm32f103c8t6:
[Microcontroller]
Internal peripheral resources of different stm32f103 chips
Design and implementation of intelligent mailbox system based on STM32F103VE
introduction In order to solve the problems of traditional mailboxes, such as blocked locks, lost keys, lost letters, wasted space, junk advertisements, etc., and to protect the safety and effectiveness of letters, we designed an intelligent mailbox system. It adopts closed management and storage concepts o
[Microcontroller]
Design and implementation of intelligent mailbox system based on STM32F103VE
STM32F103 realizes LED light, button and timer programming
#include "delay.h" #include "sys.h" #include "LED.h" #include "key.h" #include "timer2.h"   /* Program function: When KEY0 is pressed, LED0 flashes once per second; at the same time, LED1 goes out (LED0 flashes slowly).           When KEY1 is pressed, LED1 flashes twice per second; at the same time, LED0
[Microcontroller]
Connection between MAX6900 RTC and 8051-bit controller
illustrate This application note describes the connection between the MAX6900 I²C-compatible RTC (real-time clock) and an 8051 microcontroller (µC) and provides program code for the basic interface. The microcontroller used in this example is DS2250, and the software is written in C language. Operation process This
[Microcontroller]
Connection between MAX6900 RTC and 8051-bit controller
STM32F103 controls ADS1115 to collect analog signals
The procedure has been passed 0. Define channels #define TongDao0 0xc2e3        #define TongDao1 0xd2e3 #define TongDao2 0xe2e3 #define TongDao3 0xf2e3 1. Initialization of IIC port of STM32F103 void ads1115_io_init(void) { GPIO_InitTypeDef GPIO_InitStruct; // RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE); RC
[Microcontroller]
STM32 Embedded Learning Introduction (3) - STM32F103 key input control LED light
The button is a very important input device on the microcontroller and is also easy to master. As long as you understand the most basic use of the IO port, you can operate the button. Our goal is to control the three buttons on the development board to turn the two LED lights on the development board on or off (the
[Microcontroller]
STM32 Embedded Learning Introduction (3) - STM32F103 key input control LED light
STM32F103ZET6 Clock (2) - Code
Based on the clock strategy of the specific development board: The multiplication/division coefficients need to be configured before enabling the PLL, so all system clock divider coefficients and PLL multiplication coefficients need to be configured before opening the PLL. The entire clock configuration process is a
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号