RAK3172 analog pin goes high and stays high

I am using both the RAK3172 and the RAK3272 breakout board. I am using the ADC 1 - 4 pins to read sensor data. Pretty simple, I have the device go to sleep (api.system.sleep.all(20000)) for 20 seconds. When it wakes up and delays for 200ms then reads ADC1, then delay for 200ms then reads ADC2 and so on. This is to let the sensor board output to settle. I am also using 4 digital pins to enable the sensor boards before the delay. So: turn on sensor > delay 200ms > read ADC > turn off sensor > turn on next sensor > delay 200ms > so on. Before going back to sleep I send the data over LoRaWAN then sleep.

When I am sleeping, I am sitting around 2.2uA. YAY! That is perfect! Very happy about that. But after a while, not sure the interval but let’s say 20 minutes or so of cycling, I start seeing sleep current of 170uA. And one of my ADC’s is high all the time. If I disconnect the ADC pin from the circuit and let it float it reads 4095 counts and my current goes back to 2.2uA.

What is making my ADC pin get stuck high?
Thanks in advance!

Using latest RAK3172-E_latest_Final.hex file. I think it’s version RUI3 4.1.0

Welcome to the forum @Vertigonix

Are you using RUI3 or a custom code based on STM32CubeIDE?

Without any details, it is difficult to say what is happening.

I am using RUI3 with Arduino.
I’m not doing anything fancy. I’m just reading 4 analog inputs 200ms apart and sending the data over LoRaWAN and then going to sleep for 20sec.

Currently it looks like ADC3 is the problem child on the RAK3272 I’m using. If I power off the unit for about a minute and power back on it appears to be fine (back down to 2.4uA) but eventually ADC3 with stick high and current goes to about 164uA. Then it is random how long it is high and low. Circuit wise I am, for now, pulling all 4 of my ADC’s low with a 10K resistor and don’t have any sensors hooked up. Watching the power monitor (Joulescope JS220, awesome little piece of equipment) the event of stick high or going low happens randomly. Meaning, not just after waking up or going to sleep. It can happen in the middle of sleep.

I was trying to use ADC5 with a voltage divider to measure Vbatt but it is stuck high as well, constantly.

Trying to understand your problem

You are using ADC1 to ADC4 as analog inputs.
You are using 4 other GPIO’s to enable an external sensor.

You see on ADC3 a voltage that should not be there.

Is this correct so far?

What level does the GPIO have that “controls” your sensor that is connected to ADC3? Is your sensor really shut down?

If you switch the GPIO’s that control your sensors, does the problem appear on another ADC input?

Yes, I’m using ADC1-4 and PB5, PA0, PA8 and PA9 for digital output.
Yes, I see ADC3 so far appears to be the only one acting up.

So the digital outputs go to a TPS2054BDR power switch IC to enable VCC (3.3VDC) to be applied to each individual sensor. I removed that from the circuit when the ADC was high, and it didn’t change the current. Doesn’t mean it didn’t cause the initial problem, but it didn’t seem to fix it either. All I have in my circuit is a LDO voltage reg and the power switch right now.

*  This example shows LoRaWan protocol joining the network in OTAA mode, class A, region EU868.
 *  Device will send uplink every 20 seconds.
***/

#define analogPin1 PA10
#define analogPin2 PB2
#define analogPin3 PB4
#define analogPin4 PB3
#define analogPin5 PA15
#define digitalPin1 PA8
#define digitalPin2 PA9
#define digitalPin3 PA0
#define digitalPin4 PB5

#define OTAA_PERIOD   (20000)
/*************************************

   LoRaWAN band setting:
     RAK_REGION_EU433
     RAK_REGION_CN470
     RAK_REGION_RU864
     RAK_REGION_IN865
     RAK_REGION_EU868
     RAK_REGION_US915
     RAK_REGION_AU915
     RAK_REGION_KR920
     RAK_REGION_AS923

 *************************************/
#define OTAA_BAND     (RAK_REGION_US915)
#define OTAA_DEVEUI   {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}
#define OTAA_APPEUI   {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
#define OTAA_APPKEY   {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0x0AA, 0xAA, 0xAA, 0xAA}

/** Packet buffer for sending */
int fPort = 0;
uint8_t collected_data[200] = { 0 };
int aVal1 = 0;
int aVal2 = 0;
int aVal3 = 0;
int aVal4 = 0;
int aVal5 = 0;
int cVal1 = 0;
int cVal2 = 0;
int cVal3 = 0;
int cVal4 = 0;
int cVal5 = 0;
int payload_counter = 0;

void recvCallback(SERVICE_LORA_RECEIVE_T * data)
{
    if (data->BufferSize > 0) {
        Serial.println("Something received!");
        for (int i = 0; i < data->BufferSize; i++) {
            Serial.printf("%x", data->Buffer[i]);
        }
        Serial.print("\r\n");
    }
}

void joinCallback(int32_t status)
{
    Serial.printf("Join status: %d\r\n", status);    
}

/*************************************
 * enum type for LoRa Event
    RAK_LORAMAC_STATUS_OK = 0,
    RAK_LORAMAC_STATUS_ERROR,
    RAK_LORAMAC_STATUS_TX_TIMEOUT,
    RAK_LORAMAC_STATUS_RX1_TIMEOUT,
    RAK_LORAMAC_STATUS_RX2_TIMEOUT,
    RAK_LORAMAC_STATUS_RX1_ERROR,
    RAK_LORAMAC_STATUS_RX2_ERROR,
    RAK_LORAMAC_STATUS_JOIN_FAIL,
    RAK_LORAMAC_STATUS_DOWNLINK_REPEATED,
    RAK_LORAMAC_STATUS_TX_DR_PAYLOAD_SIZE_ERROR,
    RAK_LORAMAC_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS,
    RAK_LORAMAC_STATUS_ADDRESS_FAIL,
    RAK_LORAMAC_STATUS_MIC_FAIL,
    RAK_LORAMAC_STATUS_MULTICAST_FAIL,
    RAK_LORAMAC_STATUS_BEACON_LOCKED,
    RAK_LORAMAC_STATUS_BEACON_LOST,
    RAK_LORAMAC_STATUS_BEACON_NOT_FOUND,
 *************************************/

void sendCallback(int32_t status)
{
    if (status == RAK_LORAMAC_STATUS_OK) {
        Serial.println("Successfully sent");
    } else {
        Serial.println("Sending failed");
    }
}

void setup()
{
    Serial.begin(115200, RAK_AT_MODE);

    delay(2000);
    randomSeed(micros());    
    fPort = random(10,200);
    Serial.print("Fport is: ");Serial.println(fPort);
    // Setup output control pins
    analogReadResolution(12);
    pinMode(digitalPin1, OUTPUT);
    pinMode(digitalPin2, OUTPUT);
    pinMode(digitalPin3, OUTPUT);
    pinMode(digitalPin4, OUTPUT);
    digitalWrite(digitalPin1, LOW);
    digitalWrite(digitalPin2, LOW);
    digitalWrite(digitalPin3, LOW);
    digitalWrite(digitalPin4, LOW);
    Serial.println("RAKwireless LoRaWan OTAA Example");
    Serial.println("------------------------------------------------------");
  
    if(api.lorawan.nwm.get() != 1)
    {
        Serial.printf("Set Node device work mode %s\r\n",
            api.lorawan.nwm.set(1) ? "Success" : "Fail");
        api.system.reboot();
    }

    // OTAA Device EUI MSB first
    uint8_t node_device_eui[8] = OTAA_DEVEUI;
    // OTAA Application EUI MSB first
    uint8_t node_app_eui[8] = OTAA_APPEUI;
    // OTAA Application Key MSB first
    uint8_t node_app_key[16] = OTAA_APPKEY;
  
    if (!api.lorawan.appeui.set(node_app_eui, 8)) {
        Serial.printf("LoRaWan OTAA - set application EUI is incorrect! \r\n");
        return;
    }
    if (!api.lorawan.appkey.set(node_app_key, 16)) {
        Serial.printf("LoRaWan OTAA - set application key is incorrect! \r\n");
        return;
    }
    if (!api.lorawan.deui.set(node_device_eui, 8)) {
        Serial.printf("LoRaWan OTAA - set device EUI is incorrect! \r\n");
        return;
    }
  
    if (!api.lorawan.band.set(OTAA_BAND)) {
        Serial.printf("LoRaWan OTAA - set band is incorrect! \r\n");
        return;
    }
    if (!api.lorawan.deviceClass.set(RAK_LORA_CLASS_A)) {
        Serial.printf("LoRaWan OTAA - set device class is incorrect! \r\n");
        return;
    }
    if (!api.lorawan.njm.set(RAK_LORA_OTAA))	// Set the network join mode to OTAA
    {
        Serial.printf("LoRaWan OTAA - set network join mode is incorrect! \r\n");
        return;
    }
    if (!api.lorawan.join())	// Join to Gateway
    {
        Serial.printf("LoRaWan OTAA - join fail! \r\n");
        return;
    }
    /** Wait for Join success */
    while (api.lorawan.njs.get() == 0) {
        Serial.print("Wait for LoRaWAN join...");
        api.lorawan.join();
        delay(10000);
    }
    if (!api.lorawan.adr.set(true)) {
        Serial.printf("LoRaWan OTAA - set adaptive data rate is incorrect! \r\n");
        return;
    }
    if (!api.lorawan.rety.set(1)) {
        Serial.printf("LoRaWan OTAA - set retry times is incorrect! \r\n");
        return;
    }
    if (!api.lorawan.cfm.set(1)) {
        Serial.printf("LoRaWan OTAA - set confirm mode is incorrect! \r\n");
        return;
    }
  
    /** Check LoRaWan Status*/
    Serial.printf("Duty cycle is %s\r\n", api.lorawan.dcs.get()? "ON" : "OFF");	// Check Duty Cycle status
    Serial.printf("Packet is %s\r\n", api.lorawan.cfm.get()? "CONFIRMED" : "UNCONFIRMED");		// Check Confirm status
    uint8_t assigned_dev_addr[4] = { 0 };
    api.lorawan.daddr.get(assigned_dev_addr, 4);
    Serial.printf("Device Address is %02X%02X%02X%02X\r\n", assigned_dev_addr[0], assigned_dev_addr[1], assigned_dev_addr[2], assigned_dev_addr[3]);	// Check Device Address
    Serial.printf("Uplink period is %ums\r\n", OTAA_PERIOD);
    Serial.println("");
    api.lorawan.registerRecvCallback(recvCallback);
    api.lorawan.registerJoinCallback(joinCallback);
    api.lorawan.registerSendCallback(sendCallback);
}

void uplink_routine()
{
    uint8_t assigned_dev_addr[4] = { 0 };
    api.lorawan.daddr.get(assigned_dev_addr, 4);
    
    digitalWrite(digitalPin1, HIGH);
    delay(200);    
    aVal1 = analogRead(analogPin1);
    Serial.println(aVal1);
    digitalWrite(digitalPin1, LOW);
    
    digitalWrite(digitalPin2, HIGH);    
    delay(200);    
    aVal2 = analogRead(analogPin2); 
    Serial.println(aVal2);   
    digitalWrite(digitalPin2, LOW);
    
    digitalWrite(digitalPin3, HIGH);
    delay(200);
    aVal3 = analogRead(analogPin3);
    Serial.println(aVal3);
    digitalWrite(digitalPin3, LOW);
    
    digitalWrite(digitalPin4, HIGH);
    delay(200);
    aVal4 = analogRead(analogPin4);
    Serial.println(aVal4);
    digitalWrite(digitalPin4, LOW);
    
    aVal5 = analogRead(analogPin5);
    Serial.println(aVal5);
    float res = 8059;
    cVal1 = (int)(aVal1 * res / 10000);
    Serial.println(cVal1);
    cVal2 = (int)(aVal2 * res / 10000);
    Serial.println(cVal2);
    cVal3 = (int)(aVal3 * res / 10000);
    Serial.println(cVal3);
    cVal4 = (int)(aVal4 * res / 10000);
    Serial.println(cVal4);
    cVal5 = (int)(aVal5 * res / 10000);
    Serial.println(cVal5);
    /** Payload of Uplink */
    uint8_t data_len = 0;
    collected_data[data_len++] = (uint8_t) 0x7E;

    collected_data[data_len++] = (uint8_t) 0;
    collected_data[data_len++] = (uint8_t) 0;
    collected_data[data_len++] = (uint8_t) assigned_dev_addr[0];
    collected_data[data_len++] = (uint8_t) assigned_dev_addr[1];
    collected_data[data_len++] = (uint8_t) assigned_dev_addr[2];
    collected_data[data_len++] = (uint8_t) assigned_dev_addr[3];
    
    collected_data[data_len++] = (uint8_t) highByte(cVal5);
    collected_data[data_len++] = (uint8_t) lowByte(cVal5);
    
    collected_data[data_len++] = (uint8_t) payload_counter;

    collected_data[data_len++] = (uint8_t) 1;
    
    collected_data[data_len++] = (uint8_t) highByte(cVal1);
    collected_data[data_len++] = (uint8_t) lowByte(cVal1);

    collected_data[data_len++] = (uint8_t) 2;
    
    collected_data[data_len++] = (uint8_t) highByte(cVal2);
    collected_data[data_len++] = (uint8_t) lowByte(cVal2);

    collected_data[data_len++] = (uint8_t) 3;
    
    collected_data[data_len++] = (uint8_t) highByte(cVal3);
    collected_data[data_len++] = (uint8_t) lowByte(cVal3);

    collected_data[data_len++] = (uint8_t) 4;
    
    collected_data[data_len++] = (uint8_t) highByte(cVal4);
    collected_data[data_len++] = (uint8_t) lowByte(cVal4);

    collected_data[data_len++] = (uint8_t) 0xFF;

    Serial.println("Data Packet:");
    for (int i = 0; i < data_len; i++) {
        Serial.printf("0x%02X ", collected_data[i]);
    }
    payload_counter++;
    /** Send the data package */
    if (api.lorawan.send(data_len, (uint8_t *) & collected_data, fPort, true, 1)) {
        Serial.println("Sending is requested");        
    } else {
        Serial.println("Sending failed");
    }
}

void loop()
{
    static uint64_t last = 0;
    static uint64_t elapsed;
    if ((elapsed = millis() - last) > OTAA_PERIOD) {
        uplink_routine();  
        last = millis();
    }
    Serial.printf("Try sleep %ums..", OTAA_PERIOD);
    api.system.sleep.all(OTAA_PERIOD);
    Serial.println("Wakeup..");
}

Haven’t heard from you guys for a while so I thought I’d reach out. I haven’t had much luck in getting the analog pins to behave properly. I have 5 modules, and all have some analog pin reading something while pulled low with a 10K resistor. reading either ~1000 counts to full count is the pull-down is removed.

On another note. All 5 modules just started to lock up and not boot up. I measured the reset pins and they read between 0 - 0.9 volts. And they are all pulled high with a 10K resistor. I have resorted to removing the resistor and short it out directly to VCC. Has anyone seen this before? Very odd behavior and it happened over the course of a day or two of running. I have it wake up every 5 minutes to transit some bytes.

Thanks!

Hey @Vertigonix ,

Could you look at your reset pin with an oscilloscope to check that it is really stable at 0.9 V and not switching on/off quickly?

Because that is what happened to some of our modules and there reading the reset pin with a multimeter also produced a result that looks similar to yours (see my question).