jgromes / RadioLib

Universal wireless communication library for embedded devices
https://jgromes.github.io/RadioLib/
MIT License
1.48k stars 373 forks source link

Lora SX1268 sleep mode power consumption issue #981

Closed codev123 closed 6 months ago

codev123 commented 6 months ago

thank you sir for this amazing project and all support you provided earlier. Currently i am facing a issue regarding sleep current of lora module, it should consume 2uA current in sleep mode, but i am getting 100uA current on my multimeter with stm32l051 and Ebyte E22 400m22s, with only stm32l051 i am getting 4uA max, but with Lora it increases to 100 uA. code:

#include "STM32LowPower.h"
#include <RadioLib.h>

SX1268 radio = new Module(PA4, PB13, PB15, PB14);  
// save transmission states between loops
int transmissionState = RADIOLIB_ERR_NONE;
// flag to indicate transmission state
bool transmitFlag = false;
// flag to indicate reception state
bool receiveFlag = false;
//time when receive flag got activated
unsigned long receiveflagStart = 0;
// flag to indicate previous scan state
bool prevScanFlag = false;
// flag to indicate that a packet was received or transmitted or channel scan
volatile bool scanFlag = false;
void setFlag(void) {
  // we sent or received a packet or scanned channel, set the flag
  scanFlag = true;
}

void setup() {
  //pinMode(LED_BUILTIN, OUTPUT);
  // Configure low power
  delay(10000);
  radio.begin(433.5, 62.5, 9, 5, 0x34, -9, 8, 1.6, false);
  radio.setCurrentLimit(140); 
  radio.setCRC(true);
  // set the function that will be called when new packet is received
  radio.setDio1Action(setFlag);
  LowPower.begin();
}

void loop() {
  //LowPower.sleep(5000);
  radio.sleep();
  LowPower.deepSleep(10000);
  radio.standby(RADIOLIB_SX126X_STANDBY_RC, true);
  delay(5000);
}

i an designing a wireless node on aaa battery to last for 2 years, with 100uA sleep current, its not possible. please help sir

codev123 commented 6 months ago

issue is resolved, had to add spi.begin() and spi.end() before and after deep sleep mode.