[技术问答] NUC029LAN的低功耗问题

[复制链接]
3265|11
 楼主| 云龙起舞 发表于 2018-3-10 16:43 | 显示全部楼层 |阅读模式
请问NUC029LAN如何才能做到微安级静态电流,我把所有都关了,但电流还是有2.7mA, 我的程序如下:
#include <stdio.h>
#include "NUC029xAN.h"

/*---------------------------------------------------------------------------------------------------------*/
/* Global variables                                                                                        */
/*---------------------------------------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------------------------------------*/
/* Define functions prototype                                                                              */
/*---------------------------------------------------------------------------------------------------------*/
int32_t main(void);

void PowerDownFunction(void)
{
    SCB->SCR = 4;

    CLK->PWRCON = (CLK->PWRCON & ~(CLK_PWRCON_PWR_DOWN_EN_Msk | CLK_PWRCON_PD_WAIT_CPU_Msk)) |
                  CLK_PWRCON_PD_WAIT_CPU_Msk | CLK_PWRCON_PD_WU_INT_EN_Msk;
    CLK->PWRCON |= CLK_PWRCON_PWR_DOWN_EN_Msk;

    __WFI();
}

void GPIOP0P1_IRQHandler(void)
{
    P0->ISRC = P0->ISRC;
    P1->ISRC = P1->ISRC;
}

void SYS_Init(void)
{
    //---------------------------------------------------------------------------------------------------------
    // Init System Clock                                                                                       
    //---------------------------------------------------------------------------------------------------------
    // Enable external XTAL 12MHz clock
    CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk);

    // Waiting for external XTAL clock ready
    CLK_WaitClockReady(CLK_CLKSTATUS_XTL12M_STB_Msk);

    // Switch HCLK clock source to Internal RC and HCLK source divide 1
    CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HXT, CLK_CLKDIV_HCLK(1));

        //CLK_DisableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);
        //CLK_DisableXtalRC(CLK_PWRCON_OSC10K_EN_Msk);

    /* Update System Core Clock */
    /* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
    SystemCoreClockUpdate();
}

/*---------------------------------------------------------------------------------------------------------*/
/* MAIN function                                                                                           */
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
        uint8_t i;
       
    GPIO_SetMode(P1, BIT6, GPIO_PMD_OUTPUT);
    P16 = 0;

        /* Unlock protected registers */
    SYS_UnlockReg();

    /* Init System, IP clock and multi-function I/O */
    SYS_Init();

    /* Lock protected registers */
    SYS_LockReg();

    GPIO_SetMode(P1, BIT5, GPIO_PMD_INPUT);
    GPIO_EnableInt(P1, 5, GPIO_INT_FALLING);
    NVIC_EnableIRQ(GPIO_P0P1_IRQn);

    GPIO_SetMode(P1, BIT0, GPIO_PMD_OUTPUT);
    P10 = 0;
    GPIO_SetMode(P1, BIT1, GPIO_PMD_OUTPUT);
    P11 = 0;
    GPIO_SetMode(P1, BIT2, GPIO_PMD_OUTPUT);
    P12 = 0;
    GPIO_SetMode(P1, BIT3, GPIO_PMD_OUTPUT);
    P13 = 0;
    GPIO_SetMode(P1, BIT4, GPIO_PMD_OUTPUT);
    P14 = 0;
    GPIO_SetMode(P1, BIT6, GPIO_PMD_OUTPUT);
    P16 = 0;
    GPIO_SetMode(P1, BIT7, GPIO_PMD_OUTPUT);
    P17 = 0;

    //GPIO_SetMode(P3, BIT0, GPIO_PMD_OUTPUT);
    P30 = 1;
    GPIO_SetMode(P3, BIT1, GPIO_PMD_OUTPUT);
    P31 = 0;
    GPIO_SetMode(P3, BIT2, GPIO_PMD_OUTPUT);
    P32 = 0;
    GPIO_SetMode(P3, BIT3, GPIO_PMD_OUTPUT);
    P33 = 0;
    GPIO_SetMode(P3, BIT4, GPIO_PMD_OUTPUT);
    P34 = 0;
    GPIO_SetMode(P3, BIT5, GPIO_PMD_OUTPUT);
    P35 = 0;
    GPIO_SetMode(P3, BIT6, GPIO_PMD_OUTPUT);
    P36 = 0;
    GPIO_SetMode(P3, BIT7, GPIO_PMD_OUTPUT);
    P37 = 0;

    GPIO_SetMode(P0, BIT0, GPIO_PMD_OUTPUT);
    P00 = 0;
    GPIO_SetMode(P0, BIT1, GPIO_PMD_OUTPUT);
    P01 = 0;
    GPIO_SetMode(P0, BIT2, GPIO_PMD_OUTPUT);
    P02 = 0;
    GPIO_SetMode(P0, BIT3, GPIO_PMD_OUTPUT);
    P03 = 0;
    GPIO_SetMode(P0, BIT4, GPIO_PMD_OUTPUT);
    P04 = 0;
    GPIO_SetMode(P0, BIT5, GPIO_PMD_OUTPUT);
    P05 = 0;
    GPIO_SetMode(P0, BIT6, GPIO_PMD_OUTPUT);
    P06 = 0;
    GPIO_SetMode(P0, BIT7, GPIO_PMD_OUTPUT);
    P07 = 0;

    GPIO_SetMode(P2, BIT0, GPIO_PMD_OUTPUT);
    P20 = 0;
    GPIO_SetMode(P2, BIT1, GPIO_PMD_OUTPUT);
    P21 = 0;
    GPIO_SetMode(P2, BIT2, GPIO_PMD_OUTPUT);
    P22 = 0;
    GPIO_SetMode(P2, BIT3, GPIO_PMD_OUTPUT);
    P23 = 0;
    GPIO_SetMode(P2, BIT4, GPIO_PMD_OUTPUT);
    P24 = 0;
    GPIO_SetMode(P2, BIT5, GPIO_PMD_OUTPUT);
    P25 = 0;
    GPIO_SetMode(P2, BIT6, GPIO_PMD_OUTPUT);
    P26 = 0;
    GPIO_SetMode(P2, BIT7, GPIO_PMD_OUTPUT);
    P27 = 0;

    GPIO_SetMode(P4, BIT0, GPIO_PMD_OUTPUT);
    P40 = 0;
    GPIO_SetMode(P4, BIT1, GPIO_PMD_OUTPUT);
    P41 = 0;
    GPIO_SetMode(P4, BIT2, GPIO_PMD_OUTPUT);
    P42 = 0;
    GPIO_SetMode(P4, BIT3, GPIO_PMD_OUTPUT);
    P43 = 0;
    GPIO_SetMode(P4, BIT4, GPIO_PMD_OUTPUT);
    P44 = 0;
    GPIO_SetMode(P4, BIT5, GPIO_PMD_OUTPUT);
    P45 = 0;

        CLK_DisableXtalRC(CLK_PWRCON_XTL12M_EN_Msk);
        for( i = 0 ; i < 200; i++);
        while(1)
        {
        PowerDownFunction();
           }
}
所有I/O都没有接外部元件,只有P1.5接了拉高电阻。外部接了12M的晶振。
antusheng 发表于 2018-3-10 17:04 | 显示全部楼层
  1. /**************************************************************************//**
  2. * [url=home.php?mod=space&uid=288409]@file[/url]     main.c
  3. * [url=home.php?mod=space&uid=895143]@version[/url]  V3.00
  4. * $Revision: 3 $
  5. * $Date: 14/01/28 11:44a $
  6. * [url=home.php?mod=space&uid=247401]@brief[/url]    NUC029 Series GPIO Driver Sample Code
  7. *
  8. * @note
  9. * Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved.
  10. ******************************************************************************/
  11. #include <stdio.h>
  12. #include "NUC029xAN.h"


  13. #define PLL_CLOCK           50000000


  14. /*---------------------------------------------------------------------------------------------------------*/
  15. /*  Function for System Entry to Power Down Mode                                                           */
  16. /*---------------------------------------------------------------------------------------------------------*/
  17. void PowerDownFunction(void)
  18. {
  19.     /* To check if all the debug messages are finished */
  20.     UART_WAIT_TX_EMPTY(UART0);

  21.     SCB->SCR = 4;

  22.     CLK->PWRCON = (CLK->PWRCON & ~(CLK_PWRCON_PWR_DOWN_EN_Msk | CLK_PWRCON_PD_WAIT_CPU_Msk)) |
  23.                   CLK_PWRCON_PD_WAIT_CPU_Msk | CLK_PWRCON_PD_WU_INT_EN_Msk;
  24.     CLK->PWRCON |= CLK_PWRCON_PWR_DOWN_EN_Msk;

  25.     __WFI();
  26. }

  27. /**
  28. * @brief       Port0/Port1 IRQ
  29. *
  30. * @param       None
  31. *
  32. * [url=home.php?mod=space&uid=266161]@return[/url]      None
  33. *
  34. * [url=home.php?mod=space&uid=1543424]@Details[/url]     The Port0/Port1 default IRQ, declared in startup_NUC029xAN.s.
  35. */
  36. void GPIOP0P1_IRQHandler(void)
  37. {
  38.     /* To check if P1.3 interrupt occurred */
  39.     if(GPIO_GET_INT_FLAG(P1, BIT3))
  40.     {
  41.         GPIO_CLR_INT_FLAG(P1, BIT3);
  42.         printf("P1.3 INT occurred.\n");
  43.     }
  44.     else
  45.     {
  46.         /* Un-expected interrupt. Just clear all PORT0, PORT1 interrupts */
  47.         P0->ISRC = P0->ISRC;
  48.         P1->ISRC = P1->ISRC;
  49.         printf("Un-expected interrupts.\n");
  50.     }
  51. }

  52. void SYS_Init(void)
  53. {
  54.     /*---------------------------------------------------------------------------------------------------------*/
  55.     /* Init System Clock                                                                                       */
  56.     /*---------------------------------------------------------------------------------------------------------*/
  57.     /* Enable Internal RC 22.1184MHz clock */
  58.     CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);

  59.     /* Waiting for Internal RC clock ready */
  60.     CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk);

  61.     /* Switch HCLK clock source to Internal RC and HCLK source divide 1 */
  62.     CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));

  63.     /* Enable external XTAL 12MHz clock */
  64.     CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk);

  65.     /* Waiting for external XTAL clock ready */
  66.     CLK_WaitClockReady(CLK_CLKSTATUS_XTL12M_STB_Msk);

  67.     /* Set core clock as PLL_CLOCK from PLL */
  68.     CLK_SetCoreClock(PLL_CLOCK);

  69.     /* Enable UART module clock */
  70.     CLK_EnableModuleClock(UART0_MODULE);

  71.     /* Select UART module clock source */
  72.     CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_PLL, CLK_CLKDIV_UART(1));

  73.     /*---------------------------------------------------------------------------------------------------------*/
  74.     /* Init I/O Multi-function                                                                                 */
  75.     /*---------------------------------------------------------------------------------------------------------*/

  76.     /* Set P3 multi-function pins for UART0 RXD and TXD */
  77.     SYS->P3_MFP &= ~(SYS_MFP_P30_Msk | SYS_MFP_P31_Msk);
  78.     SYS->P3_MFP |= (SYS_MFP_P30_RXD0 | SYS_MFP_P31_TXD0);

  79. }

  80. void UART0_Init(void)
  81. {
  82.     /*---------------------------------------------------------------------------------------------------------*/
  83.     /* Init UART                                                                                               */
  84.     /*---------------------------------------------------------------------------------------------------------*/
  85.     /* Reset UART */
  86.     SYS_ResetModule(UART0_RST);

  87.     /* Configure UART0 and set UART0 Baudrate */
  88.     UART_Open(UART0, 115200);
  89. }

  90. /*---------------------------------------------------------------------------------------------------------*/
  91. /* MAIN function                                                                                           */
  92. /*---------------------------------------------------------------------------------------------------------*/
  93. int main(void)
  94. {
  95.     /* Unlock protected registers */
  96.     SYS_UnlockReg();

  97.     /* Init System, peripheral clock and multi-function I/O */
  98.     SYS_Init();

  99.     /* Init UART0 for printf */
  100.     UART0_Init();

  101.     printf("\n\nCPU [url=home.php?mod=space&uid=72445]@[/url] %d Hz\n", SystemCoreClock);
  102.     printf("+-------------------------------------------------------+\n");
  103.     printf("|    GPIO Power-Down and Wake-up by P1.3 Sample Code    |\n");
  104.     printf("+-------------------------------------------------------+\n\n");

  105.     /* Configure P1.3 as Input mode and enable interrupt by rising edge trigger */
  106.     GPIO_SetMode(P1, BIT3, GPIO_PMD_INPUT);
  107.     GPIO_EnableInt(P1, 3, GPIO_INT_RISING);
  108.     NVIC_EnableIRQ(GPIO_P0P1_IRQn);

  109.     /* Waiting for P1.3 rising-edge interrupt event */
  110.     while(1)
  111.     {
  112.         printf("Enter to Power-Down ......\n");
  113.         PowerDownFunction();
  114.         UART_WAIT_TX_EMPTY(UART0);
  115.         printf("System waken-up done.\n\n");
  116.     }

  117. }

  118. /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
antusheng 发表于 2018-3-10 17:04 | 显示全部楼层
这个Power down例子是不是
antusheng 发表于 2018-3-10 17:05 | 显示全部楼层
关机模式,IO唤醒,你看看这个官方例子可以达到多少
 楼主| 云龙起舞 发表于 2018-3-10 18:20 | 显示全部楼层
我试过这个官方的的例子静态电流也有几个mA
 楼主| 云龙起舞 发表于 2018-3-12 09:19 | 显示全部楼层
顶贴,求教。
maosuyun2009 发表于 2018-9-20 16:58 | 显示全部楼层
进入掉电模式没有成功,写保护寄存器没有关闭,在调用PowerDownFunction()前,调用SYS_UnlockReg()

星星点灯69 发表于 2018-9-27 10:43 | 显示全部楼层
本帖最后由 星星点灯69 于 2018-9-27 10:47 编辑

楼主,请问nuc029的低功耗问题解决了吗?
我也是用的这个demo测得静态电流也有30ma,不休眠状态38ma,感觉功耗根本就没怎么下降
void EINT0_IRQHandler(void)
{
    /* To check if P3.2 interrupt occurred */
    if(GPIO_GET_INT_FLAG(P3, BIT2))
    {
        GPIO_CLR_INT_FLAG(P3, BIT2);
                          
        if(Power_Mode==0)
        {
               Power_Mode =1;
               /*SYS_UnlockReg();
               SYS->BODCR |=SYS_BODCR_BOD_LPM_Msk;  //进入低功耗
               SYS_LockReg();*/
               P35 =0;                  
               PowerDownFunction();
         }
         else
         {
                Power_Mode =0;
                /*SYS_UnlockReg();
                 SYS->BODCR &=~SYS_BODCR_BOD_LPM_Msk;  //退出低功耗(唤醒)
                 SYS_LockReg();*/
                 P35 =1;
                  __SEV();
                  //ExitPowerDown();
           }
    }
    else
    {
        /* Un-expected interrupt. Just clear all PORT2, PORT3 and PORT4 interrupts */
        P3->ISRC = P3->ISRC;
        printf("Un-expected interrupts.\n");
    }
}
还有个问题就是,我通过外部中断进入低功耗后就没法唤醒然后一直处于休眠状态。。。我想实现的功能,按一下休眠,再按一下唤醒,,有做过的同仁帮忙解答解答,感谢!
oahzhao 发表于 2019-5-25 11:41 | 显示全部楼层
也碰到这个问题,感觉NUC029的低POWERDOWN模式用处不大
dongnanxibei 发表于 2019-5-25 22:49 | 显示全部楼层
是没有没有执行成功吗
dongnanxibei 发表于 2019-5-25 22:49 | 显示全部楼层
看上面有手是寄存器写保护没有关闭,试试看。
tanzhi963 发表于 2021-1-19 16:39 | 显示全部楼层
这个单片机是可以做到uA级别的低功耗的,我的源代码:


/* Set the processor uses deep sleep as its low power mode */

SYS_UnlockReg();

SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;

CLK->PWRCON |= CLK_PWRCON_PWR_DOWN_EN_Msk | CLK_PWRCON_PD_WAIT_CPU_Msk;

__WFI();


这样操作的话,我整个板子整体功耗是20uA



如果你还是功耗很高,我估计是进入低功耗时,引脚高低电平状态不对,导致其他设备有功耗,或者采样电阻阻值太小,导致功耗比较高
您需要登录后才可以回帖 登录 | 注册

本版积分规则

11

主题

33

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部