打印
[APM32F1]

关闭全局中断不会影响RTC计时中断

[复制链接]
522|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Peixu|  楼主 | 2024-1-29 18:01 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 Peixu 于 2024-1-29 18:04 编辑

关闭全局中断 & RTC计时中断试验。
在MCU微控制器的应用中,全局中断的管理是一项至关重要的任务。全局中断是一种机制,它允许或禁止所有中断的触发,是确保关键代码段原子性执行的重要手段。在一些实时系统中,时钟和定时功能的正常运行对于整个系统的稳定性和准确性至关重要。
本文将验证在使用APM32F103时全局中断的开启或关闭会不会影响RTC(Real-Time Clock)计时中断的正常运行,将MCU进入低功耗模式,然后配置3秒钟的RTC闹钟来进行唤醒。
1. MCU初始化和系统配置
在开始任何应用程序时,首先需要进行GPIO、低功耗、RTC库的初始化以及系统时钟的配置。这确保了后续的代码能够正常的运行。
<article data-content="[{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;hfRN-1706518417671&quot;,&quot;name&quot;:&quot;code&quot;,&quot;data&quot;:{&quot;version&quot;:1,&quot;language&quot;:&quot;c&quot;,&quot;theme&quot;:&quot;default&quot;},&quot;nodes&quot;:[{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;1uB9-1706518417666&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;0A3X-1706518417665&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot; int main(void)\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;5eSY-1706520578387&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;fc0W-1706520578386&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;{ &quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;A7R4-1706520575090&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;6gq7-1706520575089&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    RCM_EnableAPB1PeriphClock((RCM_APB1_PERIPH_T)(RCM_APB1_PERIPH_PMU | RCM_APB1_PERIPH_BAKR));\r  \r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;Mjop-1706520267405&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;GlWx-1706520267404&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    APM_MINI_PBInit(BUTTON_KEY1, BUTTON_MODE_EINT);//按下KEY1进入低功耗\r\r\r    \r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;Wipa-1706520267421&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;L7rr-1706520267420&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    PMU_EnableBackupAccess();\r    \r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;0BFg-1706520267425&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;DJwz-1706520267424&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    RTC_Init();\r    \r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;PLcY-1706520267429&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;SkE7-1706520267428&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    SysTick_Init();&quot;,&quot;marks&quot;:[]}]}]}],&quot;state&quot;:{}}]"><div yne-bulb-block="code" data-theme="default" style="white-space-collapse: preserve;" data-language="c"> int main(void)
{
    RCM_EnableAPB1PeriphClock((RCM_APB1_PERIPH_T)(RCM_APB1_PERIPH_PMU | RCM_APB1_PERIPH_BAKR));
  
    APM_MINI_PBInit(BUTTON_KEY1, BUTTON_MODE_EINT);//按下KEY1进入低功耗


   
    PMU_EnableBackupAccess();
   
    RTC_Init();
   
    SysTick_Init();</div></article>
2. RTC模块初始化和配置
RTC是用于实时时钟的模块,用于处理时间和日期的相关功能。在系统中配置RTC并设置RTC闹钟,以便在特定时间触发中断。
<article data-content="[{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;kbHQ-1706518417680&quot;,&quot;name&quot;:&quot;code&quot;,&quot;data&quot;:{&quot;version&quot;:1,&quot;language&quot;:&quot;c&quot;,&quot;theme&quot;:&quot;default&quot;},&quot;nodes&quot;:[{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;EdJz-1706518417677&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;oATG-1706518417676&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;void RTC_Init(void)\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;OF3g-1706520619943&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;zYLX-1706520619942&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;{\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;9Ulb-1706520619965&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;JTPs-1706520619964&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        BAKPR_Reset();\r\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;rYcd-1706520619969&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;XY3j-1706520619968&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        RCM_ConfigLSE(RCM_LSE_OPEN);\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;xMBE-1706520619971&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;TeGe-1706520619970&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        while(RCM_ReadStatusFlag(RCM_FLAG_LSERDY) == RESET);\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;PFCz-1706520619973&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Em1O-1706520619972&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        RCM_ConfigRTCCLK(RCM_RTCCLK_LSE);\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;MXe1-1706520619975&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;j9ku-1706520619974&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        RCM_EnableRTCCLK();\r\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;CcHv-1706520619979&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;n9hA-1706520619978&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        RTC_WaitForSynchro();\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;HsZN-1706520619981&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;5vlk-1706520619980&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        RTC_ConfigPrescaler(32767);\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;TNgq-1706520619983&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;nXJN-1706520619982&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        RTC_WaitForLastTask();\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;KkRl-1706520733991&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;I94P-1706520733990&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;               \r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;opy0-1706520619989&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Rimq-1706520619988&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        EINT_Config_T     EINT_configStruct;\r\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;cZCf-1706520620024&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;i7gq-1706520620023&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        /* Configure Button EINT line */\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;y900-1706520620026&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;EWPs-1706520620025&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        EINT_configStruct.line = EINT_LINE_0;\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;eyd9-1706520620028&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;bfH5-1706520620027&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        EINT_configStruct.mode = EINT_MODE_INTERRUPT;//此示例中,把PA0 EINT0配置为中断\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;iHrQ-1706520620030&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;gjFk-1706520620029&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        EINT_configStruct.trigger = EINT_TRIGGER_FALLING;//注意需要是此处需要 FALLING\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;K3k7-1706520620032&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;TnDX-1706520620031&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        EINT_configStruct.lineCmd = ENABLE;\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;1cEQ-1706520620034&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;WqS0-1706520620033&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        EINT_Config(&EINT_configStruct);\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;EsSi-1706520620036&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;1ObH-1706520620035&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        \r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;1yEz-1706520620038&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;nJh9-1706520620037&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        /* Configure Button EINT line */\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;DMny-1706520620040&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Ir3h-1706520620039&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        EINT_configStruct.line = EINT_LINE_17;//RTC Alarm唤醒. 需要开启EINT17\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;vFJt-1706520620042&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Y7wg-1706520620041&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        EINT_configStruct.mode = EINT_MODE_INTERRUPT;//中断\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;tvgu-1706520620044&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;JTQx-1706520620043&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        EINT_configStruct.trigger = EINT_TRIGGER_RISING;\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;6ish-1706520620046&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;wfWr-1706520620045&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        EINT_configStruct.lineCmd = ENABLE;\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;koxx-1706520620048&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;myJy-1706520620047&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        EINT_Config(&EINT_configStruct);\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;EYRd-1706520620050&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;C69Q-1706520620049&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        \r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;AjTt-1706520620052&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;XL2y-1706520620051&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        NVIC_SetPriority(EINT0_IRQn, 0X02);\r\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;fn8E-1706520620060&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;H8eh-1706520620059&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    }\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;QaBJ-1706520620062&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;YVOy-1706520620061&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;}&quot;,&quot;marks&quot;:[]}]}]}],&quot;state&quot;:{}}]"><div yne-bulb-block="code" data-theme="default" style="white-space-collapse: preserve;" data-language="c">void RTC_Init(void)
{
        BAKPR_Reset();

        RCM_ConfigLSE(RCM_LSE_OPEN);
        while(RCM_ReadStatusFlag(RCM_FLAG_LSERDY) == RESET);
        RCM_ConfigRTCCLK(RCM_RTCCLK_LSE);
        RCM_EnableRTCCLK();

        RTC_WaitForSynchro();
        RTC_ConfigPrescaler(32767);
        RTC_WaitForLastTask();
               
        EINT_Config_T     EINT_configStruct;

        /* Configure Button EINT line */
        EINT_configStruct.line = EINT_LINE_0;
        EINT_configStruct.mode = EINT_MODE_INTERRUPT;//此示例中,把PA0 EINT0配置为中断
        EINT_configStruct.trigger = EINT_TRIGGER_FALLING;//注意需要是此处需要 FALLING
        EINT_configStruct.lineCmd = ENABLE;
        EINT_Config(&EINT_configStruct);
        
        /* Configure Button EINT line */
        EINT_configStruct.line = EINT_LINE_17;//RTC Alarm唤醒. 需要开启EINT17
        EINT_configStruct.mode = EINT_MODE_INTERRUPT;//中断
        EINT_configStruct.trigger = EINT_TRIGGER_RISING;
        EINT_configStruct.lineCmd = ENABLE;
        EINT_Config(&EINT_configStruct);
        
        NVIC_SetPriority(EINT0_IRQn, 0X02);

    }
}</div></article>
3. 低功耗种加入全局中断的禁用和启用
在进入低功耗前使用__disable_irq()函数禁用全局中断
<article data-content="[{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;S0YB-1706518417798&quot;,&quot;name&quot;:&quot;code&quot;,&quot;data&quot;:{&quot;version&quot;:1,&quot;language&quot;:&quot;c&quot;,&quot;theme&quot;:&quot;default&quot;},&quot;nodes&quot;:[{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;G088-1706518417783&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;l4dr-1706518417782&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot; if(LPW_Flag==1)\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;ugr4-1706521446445&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;mwZL-1706521446444&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot; {     \r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;ys36-1706521446447&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;isJ5-1706521446446&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    RTC_ClearStatusFlag(RTC_FLAG_SEC); \r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;oK3R-1706521446449&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;rcHa-1706521446448&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    while(RTC_ReadStatusFlag(RTC_FLAG_SEC) == RESET); \r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;MoQA-1706521446451&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;oTwW-1706521446450&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    \r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;SfYa-1706521446453&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;nLGQ-1706521446452&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    RTC_ConfigAlarm(RTC_ReadCounter()+ 3);    //此处配置的\&quot;3秒\&quot;闹钟有设置误差, 可理解为\&quot;一段时间\&quot;后有RTC闹钟唤醒就好 \r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;B80x-1706521446455&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;3ZLK-1706521446454&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    RTC_WaitForLastTask();&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;aC0y-1706521840726&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;pW2R-1706521840725&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    &quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;ltoB-1706521547498&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;2n7G-1706521547496&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;     __disable_irq();&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;lqfz-1706521838151&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;i035-1706521838150&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    // 在这里执行关键代码,确保不被其他中断打断&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;w4Fg-1706521838940&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;suQO-1706521838939&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;       &quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;zogn-1706518417791&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Ux6c-1706518417790&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    PMU_EnableWakeUpPin();\r&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;iUFt-1706521421403&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;SOkL-1706521421402&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    PMU_EnterSTANDBYMode();&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;d2eS-1706518417797&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;xhVA-1706518417796&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;}&quot;,&quot;marks&quot;:[]}]}]}],&quot;state&quot;:{}}]"><div yne-bulb-block="code" data-theme="default" style="white-space-collapse: preserve;" data-language="c"> if(LPW_Flag==1)
{     
    RTC_ClearStatusFlag(RTC_FLAG_SEC);
    while(RTC_ReadStatusFlag(RTC_FLAG_SEC) == RESET);
   
    RTC_ConfigAlarm(RTC_ReadCounter()+ 3);    //此处配置的"3秒"闹钟有设置误差, 可理解为"一段时间"后有RTC闹钟唤醒就好
    RTC_WaitForLastTask();
   
     __disable_irq();
    // 在这里执行关键代码,确保不被其他中断打断
      
    PMU_EnableWakeUpPin();
    PMU_EnterSTANDBYMode();
}</div></article>
通过以上步骤,当进入低功耗模式前__disable_irq()函数禁用全局中断, 仍然不会影响RTC的使用,由于RTC计时中断是由RTC模块内部产生和触发的,与全局中断的状态无关。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

24

主题

48

帖子

0

粉丝