Guys,
I faced this kind of problem when played with ULPNode, In my case I was powering down RFM module with a mosfet to be sure 0 power will be consumed but had problem with port config pull up/down, I solved with the following code
The one part interesting for you is the part after f (!power)
/* ======================================================================
Function: powerRadio
Purpose : expose driver method of power or unpower the RF module
Input : true to power on false to power off
Output : true if powered and module found
Comments: -
====================================================================== */
boolean ULPNode::powerRadio(uint8_t power)
{
// do we need to power up the sensors
if ( power) {
uint8_t status_mask = 0;
// From here and with latest Arduino version we have a problem
// Arduino SPI library now check if SPI has already been initialized
// if so, init is not done again and as we changed SS pin and some
// others to have full Low Power, we need to enhance back all as it
// should be done in a real Spi init EACH time.
//SPCR |= _BV(SPE);
// Warning: if the SS pin ever becomes a LOW INPUT then SPI
// automatically switches to Slave, so the data direction of
// the SS pin MUST be kept as OUTPUT.
// set back CSN pin with pullup (it was input)
digitalWrite(RF_CSN_PIN, HIGH);
// now set it as output high
pinMode(RF_CSN_PIN, OUTPUT);
digitalWrite(RF_CSN_PIN, HIGH);
// Power Up Modules SPI
power_spi_enable();
// Enable back SPI and set as MASTER
SPCR |= _BV(SPE);
SPCR |= _BV(MSTR);
// MISO pin automatically overrides to INPUT.
// By doing this AFTER enabling SPI, we avoid accidentally
// clocking in a single bit since the lines go directly
// from "input" to SPI control.
// http://code.google.com/p/arduino/issues/detail?id=888
// Not needed because we didn't changed these pins
//pinMode(SCK, OUTPUT);
//pinMode(MOSI, OUTPUT);
// power ON VCC the radio module
setDevice(DEVICE_RF_ON);
// RF module settle delay
sleepQuickWake( WDTO_15MS );
//delay(15);
if (_radio_type == RF_MOD_NRF24)
status_mask = RF_NODE_STATE_NRF24;
if (_radio_type == RF_MOD_RFM69)
status_mask = RF_NODE_STATE_RFM69;
// Init the radio driver with moteino config
if (!driver.init()) {
// Radio state not OK
_status &= ~status_mask;
return false;
}
// Radio is okay
_status |= status_mask;
// Specific init for RFM69
if ( _status & RF_NODE_STATE_RFM69) {
RH_RF69 * prf69_drv = (RH_RF69 *) &driver;
// Moteino settings
prf69_drv->setModemConfig(RH_RF69::FSK_MOTEINO);
prf69_drv->setPreambleLength(3);
// Copied from LowPowerLab
prf69_drv->spiWrite(RH_RF69_REG_29_RSSITHRESH, 220);
prf69_drv->spiWrite(RH_RF69_REG_3D_PACKETCONFIG2, RH_RF69_PACKETCONFIG2_RXRESTARTDELAY_2BITS | RH_RF69_PACKETCONFIG2_AUTORXRESTARTON);
// default moteino Frequency For 433 MHz
prf69_drv->setFrequency(433.0);
}
// Specific init for NRF24
if ( _status & RF_NODE_STATE_NRF24) {
// Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
//nrf24.setChannel(1))
//nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
}
}
// So this is a power off
if ( !power) {
// This will configure the radio pins for correct low power mode
driver.sleep();
// We're going to sleep, we've done our job no need to be awake by
// RF module firing up a IRQ when we're in power down (can cause trouble?)
//detachInterrupt(digitalPinToInterrupt(RF_IRQ_PIN));
// Once agin, very important even if we power off the module, because
// of pullup, module still powered via SS/IRQ Pin. if we don't do this
// even if VDD of RFModule set to "float" using mosfet, current is get
// drawn by other pins pullup (CS or IRQ), so disable pull up
pinMode(RF_CSN_PIN, INPUT);
digitalWrite(RF_CSN_PIN, 0);
// Disable SPI device
SPCR &= ~_BV(SPE);
// unpower SPI of Arduino
power_spi_disable();
// unpower RF module
setDevice(DEVICE_RF_OFF);
}
return (true);
}