T3.2: How to reduce leakage current for 5 V tolerant pins in RFM95 setup?

Status
Not open for further replies.

daanv

Member
hello,

I have a Teensy 3.2 connected to a RFM95 Adafruit breakout board, and want the entire system to sleep with as low power consumption as possible. I managed to put the Teensy in hibernate mode with the Snooze library.

However the RFM module still draws considerable current, 0.5 mA (when measuring between the Teensy 3.3 V power pin and the RFM Vin pin).
When I use a similar setup with Arduino Nano, the current across the same line is 0.03 mA, a stark contrast.

This post on The Things Network suggests that one cause of a high power dissipation (for a different MCU) might be due to the MCU GPIO pins being 5 V tolerant, and that the internal level shifter have high leakage current.

Since all T3.2 digital pins are 5V tolerant, the solution proposed by the OP (using 3.3 V only pins) is not applicable for T3.2

So my question is whether there is another way to reduce this leakage current from the GPIO pins (or other leaks)? Or should I use the analog pins? See code below, library is https://github.com/mcci-catena/arduino-lmic.

Many thanks!


Code:
#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>

//
// For normal use, we require that you edit the sketch to replace FILLMEIN
// with values assigned by the TTN console. However, for regression tests,
// we want to be able to compile these scripts. The regression tests define
// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non-
// working but innocuous value.
//
#ifdef COMPILE_REGRESSION_TEST
# define FILLMEIN 0
#else
# warning "You must replace the values marked FILLMEIN with real values from the TTN control panel!"
# define FILLMEIN (#dont edit this, edit the lines that use FILLMEIN)
#endif

// This EUI must be in little-endian format, so least-significant-byte
// first. When copying an EUI from ttnctl output, this means to reverse
// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,
// 0x70.

/* BS1000-0157 OTAA */
// LSB
static const u1_t PROGMEM APPEUI[8]={  };
// LSB
static const u1_t PROGMEM DEVEUI[8]={  };
// MSB
static const u1_t PROGMEM APPKEY[16] = {  };

//static const u1_t PROGMEM APPEUI[8]={ FILLMEIN };
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}

// This should also be in little endian format, see above.
//static const u1_t PROGMEM DEVEUI[8]={ FILLMEIN };
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}

// This key should be in big endian format (or, since it is not really a
// number but a block of memory, endianness does not really apply). In
// practice, a key taken from ttnctl can be copied as-is.
//static const u1_t PROGMEM APPKEY[16] = { FILLMEIN };
void os_getDevKey (u1_t* buf) {  memcpy_P(buf, APPKEY, 16);}

static uint8_t mydata[] = "Hello, world!";
static osjob_t sendjob;

// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 60;

// Pin mapping
const lmic_pinmap lmic_pins = {
    .nss = 10,
    .rxtx = LMIC_UNUSED_PIN,
    .rst = 9,
    .dio = {2, 5, 6},
};

void printHex2(unsigned v) {
    v &= 0xff;
    if (v < 16)
        Serial.print('0');
    Serial.print(v, HEX);
}

void onEvent (ev_t ev) {
    Serial.print(os_getTime());
    Serial.print(": ");
    switch(ev) {
        case EV_SCAN_TIMEOUT:
            Serial.println(F("EV_SCAN_TIMEOUT"));
            break;
        case EV_BEACON_FOUND:
            Serial.println(F("EV_BEACON_FOUND"));
            break;
        case EV_BEACON_MISSED:
            Serial.println(F("EV_BEACON_MISSED"));
            break;
        case EV_BEACON_TRACKED:
            Serial.println(F("EV_BEACON_TRACKED"));
            break;
        case EV_JOINING:
            Serial.println(F("EV_JOINING"));
            break;
        case EV_JOINED:
            Serial.println(F("EV_JOINED"));
            {
              u4_t netid = 0;
              devaddr_t devaddr = 0;
              u1_t nwkKey[16];
              u1_t artKey[16];
              LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey);
              Serial.print("netid: ");
              Serial.println(netid, DEC);
              Serial.print("devaddr: ");
              Serial.println(devaddr, HEX);
              Serial.print("AppSKey: ");
              for (size_t i=0; i<sizeof(artKey); ++i) {
                if (i != 0)
                  Serial.print("-");
                printHex2(artKey[i]);
              }
              Serial.println("");
              Serial.print("NwkSKey: ");
              for (size_t i=0; i<sizeof(nwkKey); ++i) {
                      if (i != 0)
                              Serial.print("-");
                      printHex2(nwkKey[i]);
              }
              Serial.println();
            }
            // Disable link check validation (automatically enabled
            // during join, but because slow data rates change max TX
	    // size, we don't use it in this example.
            LMIC_setLinkCheckMode(0);
            break;
        /*
        || This event is defined but not used in the code. No
        || point in wasting codespace on it.
        ||
        || case EV_RFU1:
        ||     Serial.println(F("EV_RFU1"));
        ||     break;
        */
        case EV_JOIN_FAILED:
            Serial.println(F("EV_JOIN_FAILED"));
            break;
        case EV_REJOIN_FAILED:
            Serial.println(F("EV_REJOIN_FAILED"));
            break;
        case EV_TXCOMPLETE:
            Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
            if (LMIC.txrxFlags & TXRX_ACK)
              Serial.println(F("Received ack"));
            if (LMIC.dataLen) {
              Serial.print(F("Received "));
              Serial.print(LMIC.dataLen);
              Serial.println(F(" bytes of payload"));
            }
            // Schedule next transmission
            os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
            break;
        case EV_LOST_TSYNC:
            Serial.println(F("EV_LOST_TSYNC"));
            break;
        case EV_RESET:
            Serial.println(F("EV_RESET"));
            break;
        case EV_RXCOMPLETE:
            // data received in ping slot
            Serial.println(F("EV_RXCOMPLETE"));
            break;
        case EV_LINK_DEAD:
            Serial.println(F("EV_LINK_DEAD"));
            break;
        case EV_LINK_ALIVE:
            Serial.println(F("EV_LINK_ALIVE"));
            break;
        /*
        || This event is defined but not used in the code. No
        || point in wasting codespace on it.
        ||
        || case EV_SCAN_FOUND:
        ||    Serial.println(F("EV_SCAN_FOUND"));
        ||    break;
        */
        case EV_TXSTART:
            Serial.println(F("EV_TXSTART"));
            break;
        case EV_TXCANCELED:
            Serial.println(F("EV_TXCANCELED"));
            break;
        case EV_RXSTART:
            /* do not print anything -- it wrecks timing */
            break;
        case EV_JOIN_TXCOMPLETE:
            Serial.println(F("EV_JOIN_TXCOMPLETE: no JoinAccept"));
            break;

        default:
            Serial.print(F("Unknown event: "));
            Serial.println((unsigned) ev);
            break;
    }
}

void do_send(osjob_t* j){
    // Check if there is not a current TX/RX job running
    if (LMIC.opmode & OP_TXRXPEND) {
        Serial.println(F("OP_TXRXPEND, not sending"));
    } else {
        // Prepare upstream data transmission at the next possible time.
        LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0);
        Serial.println(F("Packet queued"));
    }
    // Next TX is scheduled after TX_COMPLETE event.
}

void setup() {
    Serial.begin(9600);
    Serial.println(F("Starting"));

    #ifdef VCC_ENABLE
    // For Pinoccio Scout boards
    pinMode(VCC_ENABLE, OUTPUT);
    digitalWrite(VCC_ENABLE, HIGH);
    delay(1000);
    #endif

    // LMIC init
    os_init();
    // Reset the MAC state. Session and pending data transfers will be discarded.
    LMIC_reset();

    // Start job (sending automatically starts OTAA too)
    do_send(&sendjob);
}

void loop() {
    os_runloop_once();
}
 
Last edited:
Not sure if I understand the problem.
Anyway, if you set the Teensy-Pins to INPUT or INPUT_DISABLE ( pinMode(pin,INPUT_DISABLE) ) or even if you use them as output and use digitalWrite(pin, LOW) they will not output current (edit: if there is nothing that drives the pin high externally).
 
I also suggest using a low power MOSFET to power the RFM95, so you can turn it off when Teensy is running and there is no need to communicate.
 
Sorry, I have not played much with doing much low energy stuff, but I assume you are connecting up to the ENABLE pin of the RFM95? And then pulling that signal low when you are wanting to snooze?

I probably missed something obvious that does this, but I only noticed one pin being set HIGH in setup for Pinoccio Scout boards.
 
Thanks for all the suggestions.

I've changed my arrangement a bit. I'm now measuring the total current going into Teensy + RFM module. See image for setup.

I've observed the following:
When T3.2 is by itself (no peripherals connected) it uses 0.04 mA in hibernate mode (snooze library).

When T3.2 is connected to RFM, the total uses 37 mA when T3.2 is awake (at 72 MHz) and 0.112 mA once T3.2 is in hibernate mode. (see code below).

When I pull the EN pin on the RFM to LOW (using 100k Resistor), the total becomes 0.133 mA.

When I implement a pinMode(pin X, INPUT_DISABLE) on all RFM pins before the T goes to sleep (see code), the total current consumption becomes 0.266 mA.

When I revert the pinMode changes, and instead disconnect the 3.3 V line to the RFM, or the GND line to the RFM (or both) the total current becomes roughly 0.26 mA (current fluctuates slightly depending on which pin is pulled out). This is not always repeatable, sometimes the current jumps to 6 mA. With this I was trying to simulate the MOSFET scenario.

When I pull the RFM out of the breadboard completely the current becomes 0.047 mA.

Not sure what to make of this. The fact that the total current goes up when the 3.3V and GND lines are removed suggests to me that current is leaking through the DIO / SPI pins. I've tried removing those in different orders, no significant changes.

Code:
#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
#include <Snooze.h>


#define PIN_RFM_SS    10
#define PIN_RFM_RST   9
#define PIN_RFM_DIO0  2
#define PIN_RFM_DIO1  5
#define PIN_RFM_DIO2  6
#define PIN_TEE_DOUT  11
#define PIN_TEE_DIN   12
#define PIN_TEE_SCK   13

// This EUI must be in little-endian format, so least-significant-byte
// first. When copying an EUI from ttnctl output, this means to reverse
// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,
// 0x70.

/* BS1000-0156 OTAA */
// LSB
static const u1_t PROGMEM APPEUI[8]={};
// LSB
static const u1_t PROGMEM DEVEUI[8]={ };
// MSB
static const u1_t PROGMEM APPKEY[16] = {  };


//static const u1_t PROGMEM APPEUI[8]={ FILLMEIN };
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}

// This should also be in little endian format, see above.
//static const u1_t PROGMEM DEVEUI[8]={ FILLMEIN };
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}

// This key should be in big endian format (or, since it is not really a
// number but a block of memory, endianness does not really apply). In
// practice, a key taken from ttnctl can be copied as-is.
//static const u1_t PROGMEM APPKEY[16] = { FILLMEIN };
void os_getDevKey (u1_t* buf) {  memcpy_P(buf, APPKEY, 16);}

static uint8_t mydata[] = "Hello, world!";
static osjob_t sendjob;

// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 60;

unsigned long sendT; 

SnoozeTimer timer1;

SnoozeBlock configTimer(timer1);

//pin mapping 
const lmic_pinmap lmic_pins = {
    .nss = PIN_RFM_SS,
    .rxtx = LMIC_UNUSED_PIN,
    .rst = PIN_RFM_RST,
    .dio = {PIN_RFM_DIO0,PIN_RFM_DIO1, PIN_RFM_DIO2}, // Dio0, Dio1, Dio2, |  dio3,dio4 are not connected. 2,5, 6 work for KPN 
};

void printHex2(unsigned v) {
    v &= 0xff;
    if (v < 16)
        Serial.print('0');
    Serial.print(v, HEX);
}

void onEvent (ev_t ev) {
    Serial.print(os_getTime());
    Serial.print(": ");
    switch(ev) {
        case EV_SCAN_TIMEOUT:
            Serial.println(F("EV_SCAN_TIMEOUT"));
            break;
        case EV_BEACON_FOUND:
            Serial.println(F("EV_BEACON_FOUND"));
            break;
        case EV_BEACON_MISSED:
            Serial.println(F("EV_BEACON_MISSED"));
            break;
        case EV_BEACON_TRACKED:
            Serial.println(F("EV_BEACON_TRACKED"));
            break;
        case EV_JOINING:
            Serial.println(F("EV_JOINING"));
            break;
        case EV_JOINED:
            Serial.println(F("EV_JOINED"));
            {
              u4_t netid = 0;
              devaddr_t devaddr = 0;
              u1_t nwkKey[16];
              u1_t artKey[16];
              LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey);
              Serial.print("netid: ");
              Serial.println(netid, DEC);
              Serial.print("devaddr: ");
              Serial.println(devaddr, HEX);
              Serial.print("AppSKey: ");
              for (size_t i=0; i<sizeof(artKey); ++i) {
                if (i != 0)
                  Serial.print("-");
                printHex2(artKey[i]);
              }
              Serial.println("");
              Serial.print("NwkSKey: ");
              for (size_t i=0; i<sizeof(nwkKey); ++i) {
                      if (i != 0)
                              Serial.print("-");
                      printHex2(nwkKey[i]);
              }
              Serial.println();
            }
            // Disable link check validation (automatically enabled
            // during join, but because slow data rates change max TX
      // size, we don't use it in this example.
            LMIC_setLinkCheckMode(0);
            break;
        /*
        || This event is defined but not used in the code. No
        || point in wasting codespace on it.
        ||
        || case EV_RFU1:
        ||     Serial.println(F("EV_RFU1"));
        ||     break;
        */
        case EV_JOIN_FAILED:
            Serial.println(F("EV_JOIN_FAILED"));
            break;
        case EV_REJOIN_FAILED:
            Serial.println(F("EV_REJOIN_FAILED"));
            break;
        case EV_TXCOMPLETE:
            Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
            if (LMIC.txrxFlags & TXRX_ACK)
              Serial.println(F("Received ack"));
            if (LMIC.dataLen) {
              Serial.print(F("Received "));
              Serial.print(LMIC.dataLen);
              Serial.println(F(" bytes of payload"));
            }
            // Schedule next transmission
//            os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
            break;
        case EV_LOST_TSYNC:
            Serial.println(F("EV_LOST_TSYNC"));
            break;
        case EV_RESET:
            Serial.println(F("EV_RESET"));
            break;
        case EV_RXCOMPLETE:
            // data received in ping slot
            Serial.println(F("EV_RXCOMPLETE"));
            break;
        case EV_LINK_DEAD:
            Serial.println(F("EV_LINK_DEAD"));
            break;
        case EV_LINK_ALIVE:
            Serial.println(F("EV_LINK_ALIVE"));
            break;
        /*
        || This event is defined but not used in the code. No
        || point in wasting codespace on it.
        ||
        || case EV_SCAN_FOUND:
        ||    Serial.println(F("EV_SCAN_FOUND"));
        ||    break;
        */
        case EV_TXSTART:
            Serial.println(F("EV_TXSTART"));
            break;
        case EV_TXCANCELED:
            Serial.println(F("EV_TXCANCELED"));
            break;
        case EV_RXSTART:
            /* do not print anything -- it wrecks timing */
            break;
        case EV_JOIN_TXCOMPLETE:
            Serial.println(F("EV_JOIN_TXCOMPLETE: no JoinAccept"));
            break;

        default:
            Serial.print(F("Unknown event: "));
            Serial.println((unsigned) ev);
            break;
    }
}

void do_send(osjob_t* j){
    // Check if there is not a current TX/RX job running
    if (LMIC.opmode & OP_TXRXPEND) {
        Serial.println(F("OP_TXRXPEND, not sending"));
    } else {
        // Prepare upstream data transmission at the next possible time.
        LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0);
        Serial.println(F("Packet queued"));
    }
    // Next TX is scheduled after TX_COMPLETE event.
}

void setup() {
    Serial.begin(9600);
    Serial.println(F("Starting"));
    timer1.setTimer(60*1000);// wake after 1.5 hours if sensor is not woken by interrupt (milliseconds)
    
    pinMode(7, OUTPUT); 
    
    digitalWrite(7,HIGH); 

    // LMIC init
    os_init();
    // Reset the MAC state. Session and pending data transfers will be discarded.
    LMIC_reset();

    // Start job (sending automatically starts OTAA too)
    do_send(&sendjob);
    unsigned long tStart = millis(); 
    
    while( millis() < tStart + 15*1000){
      os_runloop_once();
    }
    
    
}

void loop() {
    
    os_runloop_once();

    if (millis() > sendT + 10*1000){
      
     digitalWrite(7,LOW); 
//    disableRFMpins(); 
    delay(2000); 
    Snooze.hibernate( configTimer);  
    
    while(true){
      
    }
  }
}

//void disableRFMpins(){
//  pinMode(PIN_RFM_SS, INPUT_DISABLE); 
//  pinMode(PIN_RFM_RST, INPUT_DISABLE); 
//  pinMode(PIN_RFM_DIO0, INPUT_DISABLE); 
//  pinMode(PIN_RFM_DIO1, INPUT_DISABLE); 
//  pinMode(PIN_RFM_DIO2, INPUT_DISABLE);  
//  pinMode(PIN_RFM_DIO2, INPUT_DISABLE);  
//  pinMode(PIN_RFM_DIO2, INPUT_DISABLE);  
//  pinMode(PIN_TEE_DOUT, INPUT_DISABLE);  
//  pinMode(PIN_TEE_DIN,  INPUT_DISABLE); 
//  pinMode(PIN_TEE_SCK, INPUT_DISABLE);
//}
////
//void enableRFMpins(){
//  pinMode(PIN_RFM_SS, OUTPUT); 
//  pinMode(PIN_RFM_RST, INPUT); 
//  pinMode(PIN_RFM_DIO0, INPUT); 
//  pinMode(PIN_RFM_DIO1, INPUT); 
//  pinMode(PIN_RFM_DIO2, INPUT);
//  pinMode(PIN_TEE_DOUT, OUTPUT);  
//  pinMode(PIN_TEE_DIN,  INPUT); 
//  pinMode(PIN_TEE_SCK, OUTPUT);  
//}


signal-2021-06-09-155221.jpg
 
Status
Not open for further replies.
Back
Top