Comments (5)
@goshawk22 interesting answer from @jeromecoutant to rewrite hal_deepsleep()
for this one (and also for the serial) but I'm far from ST HAL guru, so if anyone have an example on how to reset 115200 on serial console after deep sleep, I take it.
Anyway I don't have the ADC issue mentioned here.
What I'm doing after deep sleep is to call read_sensors()
this as follow
bool read_sensors()
{
vdda = get_vdda();
vbat = get_vbat();
info("Vdda %dmV Vbat %dmV ", vdda, vbat);
}
and functions used are
// Defined globally
DigitalOut baten(BAT_EN, 0); // Digital Pin to enable R divider to read battery voltage
AnalogIn adc_vbat(BAT_MON);
uint16_t vdda = 0; // VDD Average in mV (calculated by internal ADC)
uint16_t vbat = 0; // Vbat in mV calculated with Resistor Divider
uint16_t get_vdd()
{
uint16_t vref_cal = *((const uint16_t*)VREFINT_CAL_ADDR);
return ((float)VREFINT_CAL_VREF * vref_cal / (AnalogIn(ADC_VREF).read() * 4095.0));
}
uint16_t get_vdda()
{
uint32_t sum = 0;
// Average 8 measures
for (int i=0; i<8 ; i++) {
sum += get_vdd();
}
vdda = sum >> 3 ;
return vdda;
}
uint16_t get_vbat()
{
float sum = 0;
baten = 1; // Enable reading analog R/R divider
adc_vbat.set_reference_voltage((float) vdda / 1000.0f);
ThisThread::sleep_for(5ms); // voltage to settle
// Average 8 measures
for (int i=0; i<8 ; i++) {
sum += adc_vbat.read_voltage() * 1.27 * 1000.0;
}
vbat = (uint16_t) (sum / 8.0f) ;
baten = 0; // Disable reading analog R/R divider (save R/R power)
return vbat;
}
from mbed-os.
@goshawk22 thank you for raising this issue.Please take a look at the following comments:
Could you add some more detail to the description? A good description should be at least 25 words.
What toolchain(s) are you using?
What Mbed OS version are you using?
How can we reproduce your issue?
NOTE: If there are fields which are not applicable then please just add 'n/a' or 'None'. This indicates to us that at least all the fields have been considered.
Please update the issue header with the missing information.
from mbed-os.
The apparent hang after the first reading seems to have been caused by #15331. After fixing this, when deep sleep is enabled, analogin reports near zero values around 0.09.
from mbed-os.
From STM32WL ref manual, seems that ADC configuration is not retained with Stop2 (deep sleep) power mode.
So idea could be:
- to disable deep sleep when ADC is configured
- to enable ADC only when a measurement is needed
- re-implement in your application hal_deepsleep(void)
https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/sleep.c#L166
in order to save ADC registers before going in stop2 and restore them after
from mbed-os.
With regards to point 1 and 2, if I put AnalogIn voltage(PB_3)
inside a function so that it is called each time I want to read the adc pin, I get wrong values. It returns roughly 2.7 instead of the expected 3.3.
from mbed-os.
Related Issues (20)
- STM32WL Deep Sleep STOP1 over consumption HOT 2
- TARGET_STM: masking logic for CAN rx interrupt is wrong HOT 2
- Buffer overflow vulnerablilty in MbedOS BLE Cordio stack HOT 2
- STM32WL USART2@2400 not working with every device HOT 6
- STM32WL System Clock differs at boot/reset and after deepsleep HOT 2
- Mbed CLI 2 USB no such file or directory HOT 2
- mbed-tools deploy is limiting the git fetch specification HOT 2
- STM32_gen_peripheralPins.py chrashing after generating pinmaps HOT 3
- Linking with error: "cannot move location counter backwards" HOT 1
- BLE start routine freezes when the event_queue dispatching inside mbed-os-ble-utils moved to a thread HOT 1
- Include directive issue with BLE API HOT 1
- PD_14 is not labeled as a SPI CS pin for Nucleo-F413ZH HOT 5
- time(NULL) not returning real RTC value after reboot HOT 1
- PC_13 is unlisted HOT 2
- TARGET_STM32F303xC: SetSysClock() missing HOT 2
- Update hidapi used for non-Linux platforms HOT 2
- Flashing Controller from Docker Container HOT 2
- mbed::CircularBuffer interrupt safe but not thread safe? HOT 2
- STM32 I2CSlave race condition causing timeouts
- LoRaWAN no OTAA Uplink on AS923 region STM32WL HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mbed-os.