STM32 standby mode test

Publisher:SereneHarmonyLatest update time:2016-12-19 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

environment:

Host: XP

Development environment: MDK4.10

Microcontroller: STM32F103C8


Function:

Turn on the RTC alarm, then enter standby mode, wake up with the alarm and exit.


illustrate:

1. When the RTC alarm wake-up event occurs, the alarm interrupt is entered at the same time, and must be associated with the external interrupt line 17 during initialization

2. If you only want to exit standby mode, the RTC alarm event is sufficient and does not need to be associated with external interrupt line 17

3. After exiting standby mode, the following process is similar to pressing the reset button, and the program will start from the beginning


source code:

Initialize the clock, configure the clock to the internal clock LSI, configure the RTC alarm wake-up and external interrupt line 17


  1. void RTC_Configuration(void)  

  2. {  

  3.     //Define the interrupt structure  

  4.     NVIC_InitTypeDef NVIC_InitStructure;  

  5.     EXTI_InitTypeDef EXTI_InitStructure;  

  6.     //Interrupt clock enable  

  7.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);  

  8.   

  9.     //Interrupt priority configuration  

  10.     NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);  

  11.     //Set up RTC alarm interrupt  

  12.     NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn;  

  13.     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;  

  14.     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;  

  15.     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;  

  16.     NVIC_Init(&NVIC_InitStructure);  

  17.   

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

  19.     EXTI_ClearITPendingBit(EXTI_Line17);  

  20.     EXTI_InitStructure.EXTI_Line = EXTI_Line17;  

  21.     EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;  

  22.     EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  

  23.     EXTI_InitStructure.EXTI_LineCmd = ENABLE;  

  24.     EXTI_Init(&EXTI_InitStructure);  

  25.   

  26.     //PWR_WakeUpPinCmd(DISABLE);    

  27.   

  28.     //Power management part clock is turned on  

  29.     RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);  

  30.     // Enable backup register access  

  31.     PWR_BackupAccessCmd(ENABLE);  

  32.     BKP_ClearFlag();  

  33.     BKP_DeInit();  

  34.     // Enable LSI  

  35.     RCC_LSICmd(ENABLE);  

  36.     //Wait for the crystal to start  

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

  38.     {}  

  39.     //Set the clock to the internal crystal oscillator  

  40.     RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);    

  41.     RCC_RTCCLKCmd(ENABLE);  

  42.     //Wait for the RSF bit (register synchronization flag) in the RTC_CTL register to be set to 1 by hardware  

  43.     RTC_WaitForSynchro();  

  44.     RTC_WaitForLastTask();  

  45.     // Enable alarm interrupt  

  46.     RTC_ITConfig(RTC_IT_ALR, ENABLE);  

  47.     RTC_WaitForLastTask();  

  48.     //Frequency division coefficient  

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

  50.     RTC_WaitForLastTask();  

  51.     //Initial count value  

  52.     RTC_SetCounter(0);  

  53.     RTC_WaitForLastTask();  

  54.     //Set the alarm time  

  55.     RTC_SetAlarm(2);  

  56.     RTC_WaitForLastTask();  

  57. }  


Alarm wake-up interrupt code:


  1. void RTCAlarm_IRQHandler(void)  

  2. {                 

  3.     //Wait for the RSF bit (register synchronization flag) in the RTC_CTL register to be set to 1 by hardware  

  4.     RTC_WaitForSynchro();  

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

  6.   {  

  7.     USART_SendData(USART1,'d'); //Send data  

  8.     while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET){} //Wait for sending to end  

  9.     USART_SendData(USART1,'i'); //Send data  

  10.     while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET){} //Wait for sending to end  

  11.   

  12.     // Clear EXTI_Line17 suspend bit  

  13.     EXTI_ClearITPendingBit(EXTI_Line17);  

  14.     // Check if the wakeup flag is set  

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

  16.     {  

  17.         // Clear the wake-up flag  

  18.         PWR_ClearFlag(PWR_FLAG_WU);  

  19.     }  

  20.   

  21.     /* Clear the RTC Second interrupt */  

  22.     RTC_SetCounter(0);  

  23.     RTC_WaitForLastTask();  

  24.     RTC_ClearITPendingBit(RTC_IT_ALR);  

  25.     RTC_WaitForLastTask();  

  26.     //RTC_SetAlarm(2);  

  27.     //RTC_WaitForLastTask();  

  28.   }  

  29.   

  30.   return;  

  31. }  


Test code: (This is part of the project and contains some irrelevant code)



  1. int main(void)  

  2. {  

  3.     struct _match_string_header match_string_header;  

  4.     struct _match_string_tail match_string_tail;  

  5.     unsigned char buffer[LEN_BUF];  

  6.     unsigned char buffer1[LEN_BUF];  

  7.     int len ​​= 0;  

  8.     int i = 0;  

  9.     int j = 0;  

  10.     int flag = 0;  

  11.     int flag2 = 0;  

  12.     int flag3 = 0;  

  13.     int baud = 0;  

  14.     unsigned short temp = 0;   

  15.   

  16.     // Initialize the system  

  17.     heat();  

  18.     // Initialize Bluetooth  

  19.     //Read the baud rate in flash  

  20.     //write_baud(&edit_flash,9600);  

  21.     //baud = read_baud(&edit_flash);  

  22.     //Read valid  

  23.     if (baud > 0)  

  24.     {  

  25.         set_uart_baud(1,baud);  

  26.         set_uart_baud(2,baud);  

  27.     }  

  28.     else  

  29.     {  

  30.         //Set the default baud rate  

  31.         set_uart_baud(1,DEFAULT_BAUD);  

  32.         set_uart_baud(2,DEFAULT_BAUD);  

  33.     }  

  34.   

  35.     //Set the default baud rate  

  36.     //Delay(10);  

  37.     init_blue(DEFAULT_BAUD);  

  38.     set_uart_baud(1,DEFAULT_BAUD);  

  39.     set_uart_baud(2,DEFAULT_BAUD);  

  40.     //Delay(500);  

  41.     init_blue(DEFAULT_BAUD);  

  42.     set_uart_baud(1,DEFAULT_BAUD);  

  43.     set_uart_baud(2,DEFAULT_BAUD);  

  44.   

  45.     // Initialize matching characters  

  46.     init_match_string_header(&match_string_header,"AT+BAUD");  

  47.     init_match_string_tail(&match_string_tail,"END",8);  

  48.   

  49.     //Read the value in backup register 2  

  50.     temp = BKP_ReadBackupRegister(BKP_DR2);  

  51.     if (temp == 0xabcd)  

  52.     {  

  53.         USART_SendData(USART1,'j'); //Send data  

  54.         while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET){} //Wait for sending to end  

  55.         USART_SendData(USART1,'d'); //Send data  

  56.         while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET){} //Wait for sending to end  

  57.         USART_SendData(USART1,'h'); //Send data  

  58.         while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET){} //Wait for sending to end  

  59.     }  

  60.     else  

  61.     {  

  62.         //Write to backup register 2  

  63.         BKP_WriteBackupRegister(BKP_DR2,0xabcd);  

  64.         USART_SendData(USART1,'9'); //Send data  

  65.         while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET){} //Wait for sending to end  

  66.         USART_SendData(USART1,'9'); //Send data  

  67.         while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET){} //Wait for sending to end  

  68.     }  

  69.   

  70.     //Test low power consumption: standby mode  

  71.     for (i = 0;i < 30000;i++)  

  72.     {  

  73.         for (j = 0;j < 500;j++)  

  74.         {  

  75.              __nop();  

  76.         }  

  77.     }  

  78.     PWR_EnterSTANDBYMode();  

  79.   

  80.     while (1);}  




Keywords:STM32 Reference address:STM32 standby mode test

Previous article:STM32 external interrupt test
Next article:STM32F103 and STM32F407 pin compatibility issues

Recommended ReadingLatest update time:2024-11-17 02:36

STM32 Series Part 8 - Serial Port Configuration Steps
//Initialize serial port 1 void My_USART1_Init(void) { GPIO_InitTypeDef GPIO_InitStrue; USART_InitTypeDef USART_InitStrue; NVIC_InitTypeDef NVIC_InitStrue; //Serial port clock enable, GPIO clock enable RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE); //GPIO por
[Microcontroller]
Understanding of STM32
Now let's talk about some simple knowledge about single-chip microcomputers and the advantages of STM32 compared with other single-chip microcomputers. The minimum system of single-chip microcomputers needs a crystal oscillator circuit, a reset circuit, a power supply and grounding. In simple terms, a single-chip micr
[Microcontroller]
STM32 series microcontroller development tools and applications - keil
The STM32 microprocessor is based on the ARM core, so many ARM-based embedded development environments can be used for the STM32 development platform. All development tools can be used for STM32 development. Choosing a suitable development environment can speed up development progress and save development costs. This c
[Microcontroller]
STM32 series microcontroller development tools and applications - keil
STM32 DAC
The DAC module (digital/analog conversion module) of STM32 is a 12-bit digital input, voltage output DAC. The DAC can be configured in 8-bit or 12-bit mode, and can also be used in conjunction with a DMA controller. When the DAC works in 12-bit mode, the data can be set to left-aligned or right-aligned. The DAC module
[Microcontroller]
STM32 clock tree notes
1 STM32 has five clock sources: HSI, HSE, LSI, LSE, PLL 1.1  HSI: high-speed internal clock, RC oscillator, frequency is 8MHz, clock accuracy is poor, can be used as a backup clock source (clock safety system CSS). 1.2  HSE: high-speed external clock, can connect external crystal/ceramic resonator (4MHz~16MHz) or ex
[Microcontroller]
Explanation of the code for configuring the system clock of STM32
By default, ST configures the system clock to 72MHZ.  The following seven steps are the function of setting the system clock, which is taken from the library file system_stm32f10x.c. The interconnection-related code is deleted for easy analysis and numbered. There are seven steps in total. This order is also the syste
[Microcontroller]
Pay attention to the problem of RCC opening when configuring stm32 peripherals
The full name of RCC is Reset and Clock Control  There is no need to talk about reset, as it has little to do with actual programming. The clock must be understood, otherwise the program will not run as designed. For example: GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;   GPIO_InitStructure.GPIO_Mode = GPIO_Mo
[Microcontroller]
STM32 system understanding (EXTI) and slot-type photoelectric switch tp850 circuit research
Interrupts and Events 1 Nested Vectored Interrupt Controller   characteristic: ● 68 maskable interrupt channels (excluding the 16 interrupt lines of Cortex™-M3); ● 16 programmable priority levels (using 4-bit interrupt priority); ● Low-latency exception and interrupt processing; ● Power management control; ● Implemen
[Microcontroller]
STM32 system understanding (EXTI) and slot-type photoelectric switch tp850 circuit research
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号