nRF51/52 : Disable Unused GPIOs

本文介绍了一种通过设置未使用的GPIO为输入状态并断开输入缓冲的方式,来减少nRF51822/nRF52832设备的功耗。提供了两种实现方法:直接操作寄存器和调用API函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


      

          By this forum thread, for unused GPIOs in nRF51822/nRF52832, programmer should set those as input pin, and set those in disconnection (from input buffer).

Following the rule, the code be:


//#include "nrf_gpio.h"

/**@brief Function to disable all gpio
*/
static void disable_all_gpio(void)
{
 uint32_t i;

 for( i = 0; i< NUMBER_OF_PINS; i++){
  NRF_GPIO->PIN_CNF[i] = 
  (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
  | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
  | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
  | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
  | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
 }/*for i*/

}/*disable_all_gpio*/



        If you avoid to manipulate the GPIO registers directly, you could call the wrapping function, nrf_gpio_input_disconnect.


//#include "nrf_gpio.h"

/**@brief Function to disable all gpio
*/
static void disable_all_gpio(void)
{
 uint32_t i;
 
 for( i = 0; i< NUMBER_OF_PINS; i++)
  nrf_gpio_input_disconnect(i);
}/*disable_all_gpio*/


      Theoretically, if you set the unused GPIOs in that way, the power-consumption will be lower.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值