Author Topic: De-init() RF69  (Read 222 times)

RatTrap

  • Newbie
  • *
  • Posts: 18
De-init() RF69
« on: April 22, 2019, 12:40:56 PM »
So this is going to sound a little strange.  I have a rfm69hcw transiever connected to an atmega1284p mcu, and powered by way of an LDO regulator, and I am trying to find a way to undo the RF69.init() function.  That's the goal here is the information and the problem:

if the radio has been initialized RF69.init(), then even if I have turned off the power to the radio by way of the LDO regulator.  The MCU continues to draw 35mA in power down mode.
if the radio has not been initialized No RF69.init(), and I turn the power off to the radio with the LDO regulator then the consumption of the MCU during powerdown mode is around 1-5uA.

I know the cause and the effect, but I can't quite wrap my head around the why.  Somehow the RF69.init() function is setting the mcu to some task, which doesn't end even if the radio is turned off and the mcu is placed into... well any of the sleep modes.  (I have confirmed there is no power going to the radio).  I'm  wondering if anyone knows how to undo what the RF69.init() function is doing.

Charlie

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6023
  • Country: us
    • LowPowerLab
Re: De-init() RF69
« Reply #1 on: April 22, 2019, 02:03:40 PM »
There is no de-init().
Call radio.sleep() to sleep the radio.

RatTrap

  • Newbie
  • *
  • Posts: 18
Re: De-init() RF69
« Reply #2 on: April 22, 2019, 02:21:52 PM »
Believe me Felix, I wouldn't have bothered you if I hadn't tried using the radio.sleep() command already.  What is truly bizarre is that the radio is turned completely off.  Yet somehow initializing it has something running on the mcu that is simply not turning off, but....  actually I'll get back to you.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6023
  • Country: us
    • LowPowerLab
Re: De-init() RF69
« Reply #3 on: April 22, 2019, 02:40:35 PM »
Look at how it's done in a MoteinoMEGA. That design works and is low power.
https://lowpowerlab.com/guide/moteino/design-files/

ChemE

  • Sr. Member
  • ****
  • Posts: 402
  • Country: us
Re: De-init() RF69
« Reply #4 on: April 23, 2019, 01:54:04 AM »
Initialization of the RFM69 essentially just boils down to setting about a dozen values in its registers.  While it isn't the same, here is my own custom radio initialization code that is quite simple to follow.  Change_OP_Mode is just a #define for me.  Perhaps your SPI bus is on rather than being shut down?
Code: [Select]
#define         CHANGE_OP_MODE(mode)                    writeReg(REG_OPMODE, mode)

Code: [Select]
static inline void RadioInit(void) {
    SPI_INIT();
    CHANGE_OP_MODE(SLEEP_MODE);  // Put the radio to sleep ASAP to save power
    writeReg( REG_BITRATEMSB, RF_BITRATEMSB_300000 ); // 0x03
    writeReg( REG_BITRATELSB, RF_BITRATELSB_300000 ); // 0x04
    writeReg( REG_FDEVMSB, RF_FDEVMSB_300000 ); // 0x05
    writeReg( REG_FDEVLSB, RF_FDEVLSB_300000 ); // 0x06
    writeReg( REG_RXBW, RF_RXBW_DCCFREQ_111 | RF_RXBW_MANT_16 | RF_RXBW_EXP_0 );  // 0x19
    writeReg( REG_RSSITHRESH, 220 );  // 0x29
    writeReg( REG_SYNCCONFIG, RF_SYNC_ON | RF_SYNC_FIFOFILL_AUTO | RF_SYNC_SIZE_2 | RF_SYNC_TOL_0 );  // 0x2E - 2 sync bytes
    writeReg( REG_SYNCVALUE1, 0x3D ); // 0x2F
    writeReg( REG_SYNCVALUE2, NETWORKID );  // 0x30
    //writeReg( 0x31, 0xAA );  // 0x31
    writeReg( REG_PACKETCONFIG1, RF_PACKET1_FORMAT_VARIABLE | RF_PACKET1_DCFREE_OFF | RF_PACKET1_CRC_OFF | RF_PACKET1_CRCAUTOCLEAR_OFF | RF_PACKET1_ADRSFILTERING_OFF );  // 0x37 // 0x37
    //writeReg( REG_AUTOMODES, AUTO_TRANSMITTER );  // 0x3B - Put the radio in automatic mode
    writeReg( REG_PACKETCONFIG2, RF_PACKET2_RXRESTARTDELAY_2BITS | RF_PACKET2_AUTORXRESTART_ON | RF_PACKET2_AES_ON );  // 0x3D
    writeReg( 0x6F, 0x30 );
    SET_POWER_LEVEL(0);
}

De-init would be setting these registers back to their power-on default values which can be obtained from the datasheet.  As Felix said, changing their values back should not effect power draw but experimentation is easy so go for it.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6023
  • Country: us
    • LowPowerLab
Re: De-init() RF69
« Reply #5 on: April 23, 2019, 09:45:08 AM »
Right, or just hard reset the radio with another pin.

RatTrap

  • Newbie
  • *
  • Posts: 18
Re: De-init() RF69
« Reply #6 on: May 06, 2019, 03:03:12 PM »
So I'm sorry for the delay.  I have been addressing other issues.  Felix as always your advice is pretty spot on.  I found out that the issue is because several of the devices data lines miso,mosi, and sck all appear to go to ground when the spi devices are turned off by way of ldo.  It sucks a little because the total consumption using the ldo to turn things off is sub 5uA and it is almost 90uA just using power down on the peripheral devices.  In any event placing all of the spi devices into their respective power down modes solved the problem just not saving as much power as I had hoped for. 

Out of curiosity Felix do you do contract work.  I ask because I am wrapping up a wireless mesh network and am having some issues with the timing and acknowledgement logic of nodes multiple hops down the com path.  Just wondering if that might be something you would be interested in.

Charlie

ChemE

  • Sr. Member
  • ****
  • Posts: 402
  • Country: us
Re: De-init() RF69
« Reply #7 on: May 06, 2019, 03:16:43 PM »
Perhaps in your application you could power the peripherals from a digital pin if they collectively don't draw more than 40mA and they don't have to be on and sleeping.  That would allow you to turn them fully off rather than just sleep them.  I find the start up times and currents aren't usually that much of a penalty compared to sleeping things; but it depends on your application obviously.