Skip to content

Commit ccc34b9

Browse files
committed
Fix Low Power sleep, now 3uA
1 parent e5dcd7e commit ccc34b9

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

connectivity/drivers/lora/COMPONENT_SX1276/SX1276_LoRaRadio.cpp

+27-10
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ SPDX-License-Identifier: BSD-3-Clause
3535
#include "sx1276Regs-LoRa.h"
3636

3737
#include <math.h> //rint
38-
38+
#include <chrono>
39+
using namespace std::chrono_literals;
3940
using namespace rtos;
4041
using namespace mbed;
4142

@@ -210,6 +211,8 @@ SX1276_LoRaRadio::SX1276_LoRaRadio(PinName spi_mosi,
210211

211212
if (tcxo != NC) {
212213
_tcxo = 1;
214+
// TCXO startup time
215+
ThisThread::sleep_for(5ms);
213216
}
214217

215218
#ifdef MBED_CONF_RTOS_PRESENT
@@ -288,9 +291,9 @@ void SX1276_LoRaRadio::radio_reset()
288291
{
289292
_reset_ctl.output();
290293
_reset_ctl = 0;
291-
ThisThread::sleep_for(2);
294+
ThisThread::sleep_for(2ms);
292295
_reset_ctl.input();
293-
ThisThread::sleep_for(6);
296+
ThisThread::sleep_for(6ms);
294297
}
295298

296299
/**
@@ -357,7 +360,7 @@ uint32_t SX1276_LoRaRadio::random(void)
357360
set_operation_mode(RF_OPMODE_RECEIVER);
358361

359362
for (i = 0; i < 32; i++) {
360-
ThisThread::sleep_for(1);
363+
ThisThread::sleep_for(1ms);
361364
// Unfiltered RSSI value reading. Only takes the LSB value
362365
rnd |= ((uint32_t) read_register(REG_LR_RSSIWIDEBAND) & 0x01) << i;
363366
}
@@ -805,7 +808,7 @@ void SX1276_LoRaRadio::send(uint8_t *buffer, uint8_t size)
805808
// FIFO operations can not take place in Sleep mode
806809
if ((read_register(REG_OPMODE) & ~RF_OPMODE_MASK) == RF_OPMODE_SLEEP) {
807810
standby();
808-
ThisThread::sleep_for(1);
811+
ThisThread::sleep_for(1ms);
809812
}
810813
// write_to_register payload buffer
811814
write_fifo(buffer, size);
@@ -1025,7 +1028,7 @@ bool SX1276_LoRaRadio::perform_carrier_sense(radio_modems_t modem,
10251028
set_operation_mode(RF_OPMODE_RECEIVER);
10261029

10271030
// hold on a bit, radio turn-around time
1028-
ThisThread::sleep_for(1);
1031+
ThisThread::sleep_for(1ms);
10291032

10301033
Timer elapsed_time;
10311034
elapsed_time.start();
@@ -1263,13 +1266,27 @@ void SX1276_LoRaRadio::read_fifo(uint8_t *buffer, uint8_t size)
12631266
void SX1276_LoRaRadio::set_operation_mode(uint8_t mode)
12641267
{
12651268
if (mode == RF_OPMODE_SLEEP) {
1269+
write_to_register(REG_OPMODE, (read_register(REG_OPMODE) & RF_OPMODE_MASK) | mode);
12661270
set_low_power_mode();
1271+
/* FIXME taken from set_modem, it reduces the power consumption
1272+
*from 300µA to 1.5µA */
1273+
write_to_register(REG_DIOMAPPING1, 0x00); // sets DIO0-DI03 in default mode
1274+
write_to_register(REG_DIOMAPPING2, 0x30); // bits 4-5 are turned on i.e.,
1275+
if (_rf_ctrls.tcxo != NC) {
1276+
ThisThread::sleep_for(1ms);
1277+
_tcxo = 0;
1278+
}
12671279
} else {
1280+
if (_rf_ctrls.tcxo != NC) {
1281+
_tcxo = 1;
1282+
// TCXO startup time
1283+
ThisThread::sleep_for(5ms);
1284+
}
12681285
set_low_power_mode();
1286+
write_to_register(REG_OPMODE, (read_register(REG_OPMODE) & RF_OPMODE_MASK) | mode);
12691287
set_antenna_switch(mode);
12701288
}
12711289

1272-
write_to_register(REG_OPMODE, (read_register(REG_OPMODE) & RF_OPMODE_MASK) | mode);
12731290
}
12741291

12751292
/**
@@ -1327,14 +1344,14 @@ void SX1276_LoRaRadio::set_sx1276_variant_type()
13271344
{
13281345
if (_rf_ctrls.ant_switch != NC) {
13291346
_ant_switch.input();
1330-
ThisThread::sleep_for(1);
1347+
ThisThread::sleep_for(1ms);
13311348
if (_ant_switch == 1) {
13321349
radio_variant = SX1276MB1LAS;
13331350
} else {
13341351
radio_variant = SX1276MB1MAS;
13351352
}
13361353
_ant_switch.output();
1337-
ThisThread::sleep_for(1);
1354+
ThisThread::sleep_for(1ms);
13381355
} else {
13391356
radio_variant = MBED_CONF_SX1276_LORA_DRIVER_RADIO_VARIANT;
13401357
}
@@ -2274,4 +2291,4 @@ void SX1276_LoRaRadio::handle_timeout_irq()
22742291

22752292
#endif // DEVICE_SPI
22762293

2277-
// EOF
2294+
// EOF

0 commit comments

Comments
 (0)