Skip to content

Pullup all unused pins to minimize power consumption. #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Examples/idleWakePeriodic/idleWakePeriodic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

void setup()
{
// No setup is required for this library
LowPower.pullupAllPins(); // This should appear before any calls to pinMode
}

void loop()
Expand Down Expand Up @@ -33,4 +33,3 @@ void loop()
// Do something here
// Example: Read sensor, data logging, data transmission.
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void wakeUp()

void setup()
{
LowPower.pullupAllPins(); // This should appear before any calls to pinMode
// Configure wake up pin as input.
// This will consumes few uA of current.
pinMode(wakeUpPin, INPUT);
Expand Down
2 changes: 1 addition & 1 deletion Examples/powerDownWakePeriodic/powerDownWakePeriodic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

void setup()
{
// No setup is required for this library
LowPower.pullupAllPins(); // This should appear before any calls to pinMode
}

void loop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ unsigned char count = 10;

void setup()
{
LowPower.pullupAllPins(); // This should appear before any calls to pinMode

// Wait for serial USB port to open
while(!SerialUSB);
SerialUSB.println("***** ATSAMD21 Standby Mode Example *****");
Expand Down
122 changes: 122 additions & 0 deletions LowPower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,30 @@ void LowPowerClass::idle(period_t period, adc_t adc, timer2_t timer2,
if (usart0 == USART0_OFF) power_usart0_enable();
if (twi == TWI_OFF) power_twi_enable();
}

/*******************************************************************************
* Name: pullupAllPins
* Description: If some pins are unused, it is recommended to ensure
* that these pins have a defined level. Even though most of the digital
* inputs are disabled in the deep sleep mode floating inputs should be
* avoided to reduce current consumption in all other modes where the
* digital inputs are enabled (reset, active mode and idle mode).The
* simplest method to ensure a defined level of an unused pin, is to
* enable the internal pull-up.
*
* Argument Description
* ========= ===========
* 1. NIL
*
*******************************************************************************/
void LowPowerClass::pullupAllPins()
{
for (uint8_t i = 0; i < 23; i++)
{
pinMode(i, INPUT_PULLUP);
}

}
#endif

/*******************************************************************************
Expand Down Expand Up @@ -327,6 +351,30 @@ void LowPowerClass::idle(period_t period, adc_t adc,
if (twi == TWI_OFF) power_twi_enable();
if (usb == USB_OFF) power_usb_enable();
}

/*******************************************************************************
* Name: pullupAllPins
* Description: If some pins are unused, it is recommended to ensure
* that these pins have a defined level. Even though most of the digital
* inputs are disabled in the deep sleep mode floating inputs should be
* avoided to reduce current consumption in all other modes where the
* digital inputs are enabled (reset, active mode and idle mode).The
* simplest method to ensure a defined level of an unused pin, is to
* enable the internal pull-up.
*
* Argument Description
* ========= ===========
* 1. NIL
*
*******************************************************************************/
void LowPowerClass::pullupAllPins()
{
for (uint8_t i = 0; i < 26; i++)
{
pinMode(i, INPUT_PULLUP);
}

}
#endif

/*******************************************************************************
Expand Down Expand Up @@ -449,6 +497,31 @@ void LowPowerClass::idle(period_t period, adc_t adc, timer2_t timer2,
if (usart0 == USART0_OFF) power_usart0_enable();
if (twi == TWI_OFF) power_twi_enable();
}


/*******************************************************************************
* Name: pullupAllPins
* Description: If some pins are unused, it is recommended to ensure
* that these pins have a defined level. Even though most of the digital
* inputs are disabled in the deep sleep mode floating inputs should be
* avoided to reduce current consumption in all other modes where the
* digital inputs are enabled (reset, active mode and idle mode).The
* simplest method to ensure a defined level of an unused pin, is to
* enable the internal pull-up.
*
* Argument Description
* ========= ===========
* 1. NIL
*
*******************************************************************************/
void LowPowerClass::pullupAllPins()
{
for (uint8_t i = 0; i < 32; i++)
{
pinMode(i, INPUT_PULLUP);
}

}
#endif

/*******************************************************************************
Expand Down Expand Up @@ -605,6 +678,30 @@ void LowPowerClass::idle(period_t period, adc_t adc, timer5_t timer5,
if (usart0 == USART0_OFF) power_usart0_enable();
if (twi == TWI_OFF) power_twi_enable();
}

/*******************************************************************************
* Name: pullupAllPins
* Description: If some pins are unused, it is recommended to ensure
* that these pins have a defined level. Even though most of the digital
* inputs are disabled in the deep sleep mode floating inputs should be
* avoided to reduce current consumption in all other modes where the
* digital inputs are enabled (reset, active mode and idle mode).The
* simplest method to ensure a defined level of an unused pin, is to
* enable the internal pull-up.
*
* Argument Description
* ========= ===========
* 1. NIL
*
*******************************************************************************/
void LowPowerClass::pullupAllPins()
{
for (uint8_t i = 0; i < 86; i++)
{
pinMode(i, INPUT_PULLUP);
}

}
#endif

/*******************************************************************************
Expand Down Expand Up @@ -749,6 +846,31 @@ void LowPowerClass::idle(period_t period, adc_t adc, timer5_t timer5,
if (usart0 == USART0_OFF) power_usart0_enable();
if (twi == TWI_OFF) power_twi_enable();
}


/*******************************************************************************
* Name: pullupAllPins
* Description: If some pins are unused, it is recommended to ensure
* that these pins have a defined level. Even though most of the digital
* inputs are disabled in the deep sleep mode floating inputs should be
* avoided to reduce current consumption in all other modes where the
* digital inputs are enabled (reset, active mode and idle mode).The
* simplest method to ensure a defined level of an unused pin, is to
* enable the internal pull-up.
*
* Argument Description
* ========= ===========
* 1. NIL
*
*******************************************************************************/
void LowPowerClass::pullupAllPins()
{
for (uint8_t i = 0; i < 38; i++)
{
pinMode(i, INPUT_PULLUP);
}

}
#endif


Expand Down
1 change: 1 addition & 0 deletions LowPower.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class LowPowerClass
void powerSave(period_t period, adc_t adc, bod_t bod, timer2_t timer2) __attribute__((optimize("-O1")));
void powerStandby(period_t period, adc_t adc, bod_t bod) __attribute__((optimize("-O1")));
void powerExtStandby(period_t period, adc_t adc, bod_t bod, timer2_t timer2) __attribute__((optimize("-O1")));
void pullupAllPins();

#elif defined (__arm__)

Expand Down
3 changes: 2 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ powerDown KEYWORD2
powerSave KEYWORD2
powerStandby KEYWORD2
powerExtStandby KEYWORD2
standby KEYWORD2
standby KEYWORD2
pullupAllPins KEYWORD2

#######################################
# Instances (KEYWORD2)
Expand Down