【NCS隨筆】如何進(jìn)入system_off深度睡眠模式以及配置GPIO中斷喚醒
本文章主要是講解NCS下面使用nRF54L15如何進(jìn)入system_off模式,以及如何配置通過(guò)按鍵喚醒
一、如何進(jìn)入system_off模式
在prj.conf里面添加CONFIG_POWEROFF=y
在主函數(shù)文件調(diào)用如下頭文件#include
即可使用進(jìn)入system_off模式的函數(shù):sys_poweroff();
進(jìn)入 System OFF 前,需確保所有 EasyDMA 事務(wù)結(jié)束,HFXO 停止,且 RESETREAS 清零,否則可能無(wú)法進(jìn)入
二、配置GPIO中斷喚醒
還是老規(guī)矩,使用hello_world例程,分別使用nrfx的gpio庫(kù)和zephyr的庫(kù)來(lái)喚醒
2.1 nrf_gpio庫(kù)
1、頭文件調(diào)用#include
2、main函數(shù)里面添加
#define BUTTON3_PIN 4 // P0.04 對(duì)應(yīng)DK的BUTTON3
// 配置 P0.04 為輸入,上拉,并使能 SENSE 低電平喚醒
nrf_gpio_cfg_input(BUTTON3_PIN, NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_sense_set(BUTTON3_PIN, NRF_GPIO_PIN_SENSE_LOW);
2.2 zephyr的API
1、頭文件調(diào)用#include
2、添加宏定義CONFIG_GPIO=y
3、主函數(shù)配置gpio喚醒
#define BUTTON_NODE DT_ALIAS(sw0)
#define BUTTON_PIN DT_GPIO_PIN(BUTTON_NODE, gpios)
#define BUTTON_FLAGS (GPIO_INPUT | DT_GPIO_FLAGS(BUTTON_NODE, gpios))
static const struct device *button_dev;
void main(void)
{
int ret;
printf("Hello World! %sn", CONFIG_BOARD_TARGET);
button_dev = DEVICE_DT_GET(DT_GPIO_CTLR(BUTTON_NODE, gpios));
if (!device_is_ready(button_dev)) {
printk("Button device not readyn");
return;
}
ret = gpio_pin_configure(button_dev, BUTTON_PIN, BUTTON_FLAGS);
if (ret < 0) {
printk("Failed to configure buttonn");
return;
}
// 配置為喚醒源
ret = gpio_pin_interrupt_configure(button_dev, BUTTON_PIN, GPIO_INT_EDGE_TO_ACTIVE | GPIO_INT_WAKEUP);
if (ret < 0) {
printk("Failed to configure button interruptn");
return;
}
printk("Waiting 5 seconds before entering System OFF...n");
k_sleep(K_SECONDS(5));
printk("Entering System OFF moden");
sys_poweroff();
// 進(jìn)入System OFF后,只有喚醒源(如按鍵)才能喚醒,喚醒后會(huì)復(fù)位
}
4、overlay里面設(shè)置BUTTON0的sense-edge-mask寄存器
&gpio1 {
sense-edge-mask = < 0x00002000 >;
//sense-edge-mask 的每一位對(duì)應(yīng)一個(gè) GPIO pin,bit0 對(duì)應(yīng) P0.00,bit1 對(duì)應(yīng) P0.01,……,bit31 對(duì)應(yīng) P0.31所以P1,13對(duì)應(yīng)0x200
};
2.3、附上所有代碼
main:
/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include < stdio.h >
#include < zephyr/kernel.h >
#include < zephyr/device.h >
#include < zephyr/drivers/gpio.h >
#include < zephyr/pm/pm.h >
#include < zephyr/pm/policy.h >
#include < zephyr/sys/printk.h >
#include < zephyr/sys/poweroff.h >
#include < hal/nrf_gpio.h >
#define BUTTON_NODE DT_ALIAS(sw0)
#define BUTTON_PIN DT_GPIO_PIN(BUTTON_NODE, gpios)
#define BUTTON_FLAGS (GPIO_INPUT | DT_GPIO_FLAGS(BUTTON_NODE, gpios))
static const struct device *button_dev;
#define BUTTON3_PIN 4 // P0.04 對(duì)應(yīng)DK的BUTTON3
void main(void)
{
int ret;
printf("Hello World! %sn", CONFIG_BOARD_TARGET);
button_dev = DEVICE_DT_GET(DT_GPIO_CTLR(BUTTON_NODE, gpios));
if (!device_is_ready(button_dev)) {
printk("Button device not readyn");
return;
}
ret = gpio_pin_configure(button_dev, BUTTON_PIN, BUTTON_FLAGS);
if (ret < 0) {
printk("Failed to configure buttonn");
return;
}
// 配置為喚醒源
ret = gpio_pin_interrupt_configure(button_dev, BUTTON_PIN, GPIO_INT_EDGE_TO_ACTIVE | GPIO_INT_WAKEUP);
if (ret < 0) {
printk("Failed to configure button interruptn");
return;
}
// 配置 P0.04 為輸入,上拉,并使能 SENSE 低電平喚醒
nrf_gpio_cfg_input(BUTTON3_PIN, NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_sense_set(BUTTON3_PIN, NRF_GPIO_PIN_SENSE_LOW);
printk("Waiting 5 seconds before entering System OFF...n");
k_sleep(K_SECONDS(5));
printk("Entering System OFF moden");
sys_poweroff();
// 進(jìn)入System OFF后,只有喚醒源(如按鍵)才能喚醒,喚醒后會(huì)復(fù)位
}
prj.conf
CONFIG_GPIO=y
CONFIG_POWEROFF=y
overlay:
&gpio1 {
sense-edge-mask = < 0x00002000 >; // 只舉例,實(shí)際bit需對(duì)應(yīng)你的按鍵引腳
};
三測(cè)試
設(shè)置上電5S進(jìn)入深度休眠模式,然后通過(guò)按鍵喚醒:
你的點(diǎn)贊、收藏和評(píng)論是對(duì)我最大的支持,有問(wèn)題多多指教,如果有需要Nordic開(kāi)發(fā)板、Nordic的芯片以及Nordic技術(shù)支持的可以在個(gè)人資料獲取我的聯(lián)系方式,感謝讀者支持!
審核編輯 黃宇
-
NCS
+關(guān)注
關(guān)注
1文章
21瀏覽量
9314 -
GPIO
+關(guān)注
關(guān)注
16文章
1299瀏覽量
55245 -
Nordic
+關(guān)注
關(guān)注
9文章
228瀏覽量
48551
發(fā)布評(píng)論請(qǐng)先 登錄
n32g031單片機(jī)進(jìn)入睡眠模式無(wú)法喚醒怎么解決?
【NCS隨筆】NCS使用CJSON庫(kù)

RK3128 Android 7.1 進(jìn)入深度休眠流程分析
請(qǐng)問(wèn) CYW20829 深度睡眠模式是否可以通過(guò)遠(yuǎn)程 BLE 喚醒,還是必須從主機(jī)喚醒?
【RA4L1-SENSOR】07 低功耗待機(jī)模式及功耗實(shí)測(cè)
STM32U5 IWDG的提前喚醒中斷無(wú)法在STOP模式下觸發(fā)怎么解決?
STM32U5 IWDG的提前喚醒中斷無(wú)法在STOP模式下觸發(fā)怎么解決?
STM32U5 IWDG的提前喚醒中斷無(wú)法在STOP模式下觸發(fā)怎么解決?
AG32 MCU 如何進(jìn)入低功耗模式
基于小凌派RK2206開(kāi)發(fā)板:OpenHarmony如何使用IoT接口控制GPIO中斷

【瑞薩RA2L1入門學(xué)習(xí)】05、待機(jī)模式按鍵外部中斷喚醒 低功耗測(cè)試
stm32 GPIO中斷配置教程
一文搞懂Linux進(jìn)程的睡眠和喚醒
【AI技術(shù)支持】ESP32-C3-MINI-1U模組睡眠模式下喚醒死機(jī)問(wèn)題

評(píng)論