- void usart1_wakeup_config(void)
- {
- exint_init_type exint_init_struct;
-
- /* keep usart work when deepsleep */
- usart_deep_sleep_mode_enable(USART1, TRUE);
-
- /* low power wakeup method is receive data buffer full */
- usart_low_power_wakeup_set(USART1, USART_WAKEUP_METHOD_RDBF);
-
- usart_interrupt_enable(USART1, USART_LPWUF_INT, TRUE);
-
- /* config the exint line of the usart1 */
- exint_init_struct.line_select = EXINT_LINE_25;
- exint_init_struct.line_enable = TRUE;
- exint_init_struct.line_mode = EXINT_LINE_INTERRUPT;
- exint_init_struct.line_polarity = EXINT_TRIGGER_RISING_EDGE;
- exint_init(&exint_init_struct);
- }
5、编写ERTC中断和串口中断处理函数
ERTC中断和串口处理函数
- void ERTC_IRQHandler(void)
- {
- /* add user code begin ERTC_IRQ 0 */
- if(ertc_interrupt_flag_get(ERTC_WATF_FLAG) != RESET)
- {
- /* clear ertc alarm flag */
- ertc_flag_clear(ERTC_WATF_FLAG);
- wakeUpFalg = ERTC_WAKE_UP;
- g_exitLowPower = 1;
- /* toggle led */
- }
- if(exint_interrupt_flag_get(EXINT_LINE_20) != RESET)
- {
- /* clear exint line flag */
- exint_flag_clear(EXINT_LINE_20);
- }
- /* add user code end ERTC_IRQ 0 */
- /* add user code begin ERTC_IRQ 1 */
- /* add user code end ERTC_IRQ 1 */
- }
- void USART1_IRQHandler(void)
- {
- /* add user code begin USART1_IRQ 0 */
- if(usart_flag_get(USART1, USART_RDBF_FLAG) != RESET)
- {
- /* clear rdbf flag */
- usart1RxBuf[usart1RxIndex++] = usart_data_receive(USART1);
- g_exitLowPower = 1;
-
- }
- if(usart_interrupt_flag_get(USART1, USART_LPWUF_FLAG) != RESET)
- {
- usart_flag_clear(USART1, USART_LPWUF_FLAG);
- }
- if(exint_interrupt_flag_get(EXINT_LINE_25) != RESET)
- {
- exint_flag_clear(EXINT_LINE_25);
- }
- /* add user code end USART1_IRQ 0 */
- /* add user code begin USART1_IRQ 1 */
- /* add user code end USART1_IRQ 1 */
- }
6、编写主函数
- int main(void)
- {
- /* add user code begin 1 */
- pwc_ldo_output_voltage_set(PWC_LDO_OUTPUT_1V2);
- /* add user code end 1 */
- /* system clock config. */
- wk_system_clock_config();
- /* config periph clock. */
- wk_periph_clock_config();
- /* nvic config. */
- wk_nvic_config();
- /* timebase config. */
- wk_timebase_init();
- /* usart1 already supports printf. */
- /* init usart1 function. */
- wk_usart1_init();
- /* init ertc function. */
- wk_ertc_init();
- /* init gpio function. */
- wk_gpio_config();
- /* add user code begin 2 */
- gpio_bits_set(GPIOB,GPIO_PINS_11);
- wk_delay_ms(5000);
- /* add user code end 2 */
- while(1)
- {
- /* add user code begin 3 */
- if (g_enterLowPower) {
- g_enterLowPower = 0;
- enter_lower_power_mode();
- }
-
- if (g_exitLowPower) {
- g_exitLowPower = 0;
- exit_lower_power_mode();
- /*这里放置相关处理函数,处理完就进入低功耗模式*/
- g_enterLowPower = 1;
- }
- gpio_bits_toggle(GPIOB,GPIO_PINS_11);
- /* add user code end 3 */
- }
- }
四、最后下载验证即可。
代码,如下:
LPFrame.zip
(2.42 MB, 下载次数: 3)