sleep(0) in V2.1 doesn't sleep indefinitely anymore. Used to powerdown and sleep in V1.5



  • For battery powered nodes that need to completely sleep between events sleep(0) could be used in V1.5 in conjunction with the pin change interrupts on portC of an ATmega 328p. It would gracefully power down the radio and then enter the CPU into sleep mode until a pin change event on port C woke it up. In V2.1 sleep(0) simply returns. PortC pin-change mode is needed because INT0 and INT1 only work on either falling or raising level changes but not on either edge at the same time on the 328p .

    I modified the file MyHwAVR.cpp as follows to restore the missing functionality back into V2.1 : Lines 150 and up:

    int8_t hwSleep(unsigned long ms)
    {
    
    
    	if (ms>0) {
    		// sleep for defined time
    		hwInternalSleep(ms);
    		return MY_WAKE_UP_BY_TIMER;
    	} else {  // Fix for missing feature that allowed (in 1.5.1) to use the pin chnage interrupt with a sleep(0) to completely power down the system
    		// sleep until ext interrupt triggered
    		hwPowerDown(SLEEP_FOREVER);
    		return 0;
    	}
    
    
    }
    

    Let me know if this is the correct venue to bring this to the attention of the code maintainers, or if I should go and furnish a git pull request or something like that.

    Or if this has been addressed in post V2.1.1 releases
    Thanks
    gary


  • Mod

    Thanks @garystofer

    Looks to me like this was fixed in https://github.com/mysensors/MySensors/pull/1113

    You seem to be using very old code 🙂



  • @mfalkvidd No, the issue with sleep(0) still exists in V2.3.2. That is the version that the ArDuino Library installer installs currently . -- Work around is to call hwPowerDown(WDTO_SLEEP_FOEREVER) as in above code if you want the battery to last more than a day.

    GS


Log in to reply
 

Suggested Topics

  • 33
  • 11
  • 5
  • 17
  • 6
  • 2

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts