ch32v003低功耗问题


功耗太高了,没有外围设备4Ma,耗电太快了,得加低功耗功能,代码很简单,就是main里进入待机(睡眠功耗也高),中断触发一次,main里继续待机,但是 中断只触了一次,一直在串口显示一直在中断,好奇怪,下面是在例程里改的


/********************************** (C) COPYRIGHT *******************************
 * File Name          : main.c
 * Author             : WCH
 * Version            : V1.0.0
 * Date               : 2023/12/25
 * Description        : Main program body.
 *********************************************************************************
 * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
 * Attention: This software (modified or not) and binary are used for
 * microcontroller manufactured by Nanjing Qinheng Microelectronics.
 *******************************************************************************/

/*
 *@Note
 *low power, sleep mode routine:
 *EXTI_Line0(PD0)
 *This routine demonstrates that WFI enters the sleep mode, and the PD0 pin input
 *low level triggers the external interrupt EXTI_Line0 to exit the sleep mode,
 *Program execution continues after wake-up.
 *
 */

#include "debug.h"

/* Global define */

/* Global Variable */

/*********************************************************************
 * @fn      EXTI0_INT_INIT
 *
 * @brief   Initializes EXTI0 collection.
 *
 * @return  none
 */
void EXTI0_INT_INIT(void)
{
    GPIO_InitTypeDef GPIO_InitStructure = {0};
    EXTI_InitTypeDef EXTI_InitStructure = {0};
    NVIC_InitTypeDef NVIC_InitStructure = {0};

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOC, ENABLE);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    /* GPIOA.0 ----> EXTI_Line0 */
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource1);
    EXTI_InitStructure.EXTI_Line = EXTI_Line1;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);

    NVIC_InitStructure.NVIC_IRQChannel = EXTI7_0_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
}


/*********************************************************************
 * @fn      main
 *
 * @brief   Main program.
 *
 * @return  none
 */
int main(void)
{
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
    SystemCoreClockUpdate();
    Delay_Init();
    Delay_Ms(1000);
    Delay_Ms(1000);
#if (SDI_PRINT == SDI_PR_OPEN)
    SDI_Printf_Enable();
#else
    USART_Printf_Init(115200);
#endif
    printf("SystemClk:%d\r\n", SystemCoreClock);
    printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );

    printf("Sleep Mode Test\r\n");
    EXTI0_INT_INIT();

    printf("\r\n ********** \r\n");
    __WFE();
    printf("\r\n ########## \r\n");

    while(1)
    {
        Delay_Ms(1000);
        printf("Run in PWR_STANDBYEntry_WFI  main\r\n");
        PWR_EnterSTANDBYMode(PWR_STANDBYEntry_WFE);
    }
}


void EXTI7_0_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));

/*********************************************************************
 * @fn      EXTI0_IRQHandler
 *
 * @brief   This function handles EXTI0 Handler.
 *
 * @return  none
 */
void EXTI7_0_IRQHandler(void)
{
    if(EXTI_GetITStatus(EXTI_Line1)!=RESET)
    {
        printf("EXTI7_0_IRQHandler EXTI0 Wake_up\r\n");
        EXTI_ClearITPendingBit(EXTI_Line0);     /* Clear Flag */
//        Delay_Ms(2000);
//        PWR_EnterSTANDBYMode(PWR_STANDBYEntry_WFI);


//        __WFE();

    }
}


{3861-x-151767689362759}.png

刚才在研究ch32v003fun里面的例子时,找到了一个问题EXTI_Line0没改EXTI_Line1,测试ok了,

EXTI_ClearITPendingBit(EXTI_Line0);

 功耗问题还是不理想,正常工作4ma,我用了测试了这四个写法,电流最低在1ma左右,还能不能降?还有什么写法推荐一下

int main(void)
{
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
    SystemCoreClockUpdate();
    Delay_Init();
    Delay_Ms(1000);
    Delay_Ms(1000);
#if (SDI_PRINT == SDI_PR_OPEN)
    SDI_Printf_Enable();
#else
    USART_Printf_Init(115200);
#endif
    printf("SystemClk:%d\r\n", SystemCoreClock);
    printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );

    printf("Sleep Mode Test\r\n");
    EXTI0_INT_INIT();

    printf("\r\n ********** \r\n");
//    __WFI();
//    __WFE();
//    PWR_EnterSTANDBYMode(PWR_STANDBYEntry_WFI);
    PWR_EnterSTANDBYMode(PWR_STANDBYEntry_WFE);
    printf("\r\n ########## \r\n");

    while(1)
    {
        Delay_Ms(1000);
        printf("Run in PWR_STANDBYEntry_WFI  main\r\n");

//        __WFI();
//        __WFE();
//        PWR_EnterSTANDBYMode(PWR_STANDBYEntry_WFI);
        PWR_EnterSTANDBYMode(PWR_STANDBYEntry_WFE);
    }
}



你好,功耗高可参考此篇博客:https://www.cnblogs.com/wchmcu/p/17091766.html 


只有PWR_EnterSTANDBYMode,

PWR_EnterSTOPMode已经没有了

{3861-x-325119210231189}.png


您好,CH32V003的低功耗模式只有睡眠模式和待机模式,没有停止模式,具体可看CH32V003应用手册,如下图,手册下载链接如下:

https://www.wch.cn/downloads/CH32V003RM_PDF.html

image.png


我想问的是最低功耗是多少?
功耗问题还是不理想,正常工作4ma,2楼我测试了这四个写法,电流最低在1ma左右,还能不能降?还有什么写法推荐一下


只有登录才能回复,可以选择微信账号登录