I am using the AnalogIn api to measure battery voltage on the rak3172 using the code below.
#include "mbed.h"
AnalogIn voltage(PB_3);
int main()
{
//sleep_manager_lock_deep_sleep();
while (true) {
float raw_adc;
float calc_voltage;
raw_adc = voltage.read();
calc_voltage = ((3.3f*raw_adc*(5.0f))/(3.0f))*(1.3f);
printf("\r\nRaw ADC: %f\r\n", raw_adc);
printf("\r\n Calc Voltage: %f\r\n", calc_voltage);
ThisThread::sleep_for(5s);
}
}
When deep sleep is locked, the code works perfectly.
Raw ADC: 0.459096
Calc Voltage: 3.282540
Raw ADC: 0.459341
Calc Voltage: 3.284286
Raw ADC: 0.458852
Calc Voltage: 3.280794
Raw ADC: 0.459341
Calc Voltage: 3.284286
Raw ADC: 0.459585
Calc Voltage: 3.286032
However, when deep sleep is unlocked, the loop only runs once before seeming to crash without any error message. The value printed is also incorrect.
Raw ADC: 0.387790
Calc Voltage: 2.772699
Has anyone else experienced similar problems and/or knows how to fix it?