2017年4月4日 星期二

nRF51/52 : Disable Unused GPIOs


      

          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.

沒有留言:

張貼留言