Can not deep sleep with LoRaWAN enabled

cmodrich
Wed, 28 Apr 2021 22:05:48 +0000
Mbed OS

Hello all,

I’m currently working with an NRF52840-DK + SX1262MB2xAS LoRa radio shield, plus another DK with a power profiler attached for current measurements. I have things working with my LoRaWAN gateway but struggle to get the power consumption under control.

To investigate the problem I made a simple sketch:

#include <stdio.h>
#include "lorawan/LoRaWANInterface.h"
#include "lorawan/system/lorawan_data_structures.h"
#include "events/EventQueue.h"

// Application helpers
#include "SX126X_LoRaRadio.h"
SX126X_LoRaRadio radio(D11,//MOSI
                       D12,//MISO
                       D13,//SCK
                       D7,//CS/NSS
                       A0,//RESET
                       D5,//DIO1
                       D3,//BUSY
                       A1,//FREQ_SEL
                       A2,//DEV_SEL
                       A3,//XTAL_SEL
                       D8);//ANT_SW

#include "mbed.h"

//DigitalOut led1(LED1);
using namespace events;
uint8_t tx_buffer[30];
uint8_t rx_buffer[30];
#define TX_TIMER                        20000
#define MAX_NUMBER_OF_EVENTS            10
#define CONFIRMED_MSG_RETRY_COUNTER     3
#define PC_9                            0

static EventQueue ev_queue(MAX_NUMBER_OF_EVENTS *EVENTS_EVENT_SIZE);
static void lora_event_handler(lorawan_event_t event);
static lorawan_app_callbacks_t callbacks;

static LoRaWANInterface lorawan(radio);

int main()
{
    //led1 = 0;
    // Deep sleep for 1 second
    //printf("Deep sleep allowed: %i\r\n", sleep_manager_can_deep_sleep());
    while(true) {
    ThisThread::sleep_for(1500ms);
    }
}

Running the above code shows an average current consumption of 6.66mA. Interestingly enough, if you comment out the line before int main() that sets up the radio, the sketch runs with an average current consumption of ~14uA, more or less what I would expect from properly functioning deep sleep.

Any ideas? Worth noting all other config options are default save for my macros in mbed_app.json:

"macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_lora_config.h\"", "MBED_TICKLESS=1"]

Any and all advice would be much appreciated.

3 posts - 2 participants