Hi all,
I would like to read the battery voltage in the wake stub (esp_wake_deep_sleep), but as the ADC functions are not in the RTC memory I have absolutely no clue where to start. Couldn't find anything here: https://github.com/espressif/esp-idf/tr ... /esp32/rom
Did anybody manage to read ADC values in the wake stub?
Thanks in advance & greetings,
Timm
Read ADC voltage in wake stub
Re: Read ADC voltage in wake stub
Hi all,
I figured it out and would like to share the code in case anyone else has a similar problem. The following function can run in the wake stub, turns on ADC and measures the voltage of a certain channel of AD1 (result will be stored in adcValue) and then turns off ADC again:
I figured it out and would like to share the code in case anyone else has a similar problem. The following function can run in the wake stub, turns on ADC and measures the voltage of a certain channel of AD1 (result will be stored in adcValue) and then turns off ADC again:
Code: Select all
RTC_DATA_ATTR uint16_t adcValue;
void RTC_IRAM_ATTR adc1_get_raw_ram(adc1_channel_t channel) {
SENS.sar_read_ctrl.sar1_dig_force = 0; // switch SARADC into RTC channel
SENS.sar_meas_wait2.force_xpd_sar = SENS_FORCE_XPD_SAR_PU; // adc_power_on
RTCIO.hall_sens.xpd_hall = false; //disable other peripherals
SENS.sar_meas_wait2.force_xpd_amp = SENS_FORCE_XPD_AMP_PD; // channel is set in the convert function
// disable FSM, it's only used by the LNA.
SENS.sar_meas_ctrl.amp_rst_fb_fsm = 0;
SENS.sar_meas_ctrl.amp_short_ref_fsm = 0;
SENS.sar_meas_ctrl.amp_short_ref_gnd_fsm = 0;
SENS.sar_meas_wait1.sar_amp_wait1 = 1;
SENS.sar_meas_wait1.sar_amp_wait2 = 1;
SENS.sar_meas_wait2.sar_amp_wait3 = 1;
//set controller
SENS.sar_read_ctrl.sar1_dig_force = false; //RTC controller controls the ADC, not digital controller
SENS.sar_meas_start1.meas1_start_force = true; //RTC controller controls the ADC,not ulp coprocessor
SENS.sar_meas_start1.sar1_en_pad_force = true; //RTC controller controls the data port, not ulp coprocessor
SENS.sar_touch_ctrl1.xpd_hall_force = true; // RTC controller controls the hall sensor power,not ulp coprocessor
SENS.sar_touch_ctrl1.hall_phase_force = true; // RTC controller controls the hall sensor phase,not ulp coprocessor
//start conversion
SENS.sar_meas_start1.sar1_en_pad = (1 << channel); //only one channel is selected.
while (SENS.sar_slave_addr1.meas_status != 0);
SENS.sar_meas_start1.meas1_start_sar = 0;
SENS.sar_meas_start1.meas1_start_sar = 1;
while (SENS.sar_meas_start1.meas1_done_sar == 0);
adcValue = SENS.sar_meas_start1.meas1_data_sar; // set adc value!
SENS.sar_meas_wait2.force_xpd_sar = SENS_FORCE_XPD_SAR_PD; // adc power off
}
-
- Posts: 4
- Joined: Thu Jan 19, 2023 11:58 am
Re: Read ADC voltage in wake stub
Hi, I'm trying to read ADC voltage in wake stub and I have tried the code that has been posted here but I just get errors. Can someone help me?
Re: Read ADC voltage in wake stub
My help: what kind of errors, be specific, cut and paste.
IT Professional, Maker
Santiago, Dominican Republic
Santiago, Dominican Republic
Re: Read ADC voltage in wake stub
Hey,
the posted code is specific for the ESP32 Pico D4. Maybe different hardware?
Best
the posted code is specific for the ESP32 Pico D4. Maybe different hardware?
Best
-
- Posts: 4
- Joined: Thu Jan 19, 2023 11:58 am
Re: Read ADC voltage in wake stub
The thing is, I copy the previously provided code into the Arduino IDE and include the relevant libraries, but I only get errors like this: Compilation error: 'sens_dev_t' {aka 'volatile struct sens_dev_s'} has no member named 'sar_read_ctrl'; did you mean 'sar_reader1_ctrl'?
From what I've been seeing, these functions used to be in "rtc_module.c" but now this file doesn't exist (I haven't found it in my ESP folder) and I've read that they are in different libraries. Well, even including these libraries I am unable to prevent the code from making errors.
From what I've been seeing, these functions used to be in "rtc_module.c" but now this file doesn't exist (I haven't found it in my ESP folder) and I've read that they are in different libraries. Well, even including these libraries I am unable to prevent the code from making errors.
-
- Posts: 4
- Joined: Thu Jan 19, 2023 11:58 am
Re: Read ADC voltage in wake stub
I'm using an ESP32 S2 SOLO
-
- Posts: 1
- Joined: Mon Dec 04, 2023 5:03 pm
Re: Read ADC voltage in wake stub
timmbo wrote: ↑Tue Jun 02, 2020 6:15 amHi all,
I figured it out and would like to share the code in case anyone else has a similar problem. The following function can run in the wake stub, turns on ADC and measures the voltage of a certain channel of AD1 (result will be stored in adcValue) and then turns off ADC again:
Code: Select all
RTC_DATA_ATTR uint16_t adcValue; void RTC_IRAM_ATTR adc1_get_raw_ram(adc1_channel_t channel) { SENS.sar_read_ctrl.sar1_dig_force = 0; // switch SARADC into RTC channel SENS.sar_meas_wait2.force_xpd_sar = SENS_FORCE_XPD_SAR_PU; // adc_power_on RTCIO.hall_sens.xpd_hall = false; //disable other peripherals SENS.sar_meas_wait2.force_xpd_amp = SENS_FORCE_XPD_AMP_PD; // channel is set in the convert function // disable FSM, it's only used by the LNA. SENS.sar_meas_ctrl.amp_rst_fb_fsm = 0; SENS.sar_meas_ctrl.amp_short_ref_fsm = 0; SENS.sar_meas_ctrl.amp_short_ref_gnd_fsm = 0; SENS.sar_meas_wait1.sar_amp_wait1 = 1; SENS.sar_meas_wait1.sar_amp_wait2 = 1; SENS.sar_meas_wait2.sar_amp_wait3 = 1; //set controller SENS.sar_read_ctrl.sar1_dig_force = false; //RTC controller controls the ADC, not digital controller SENS.sar_meas_start1.meas1_start_force = true; //RTC controller controls the ADC,not ulp coprocessor SENS.sar_meas_start1.sar1_en_pad_force = true; //RTC controller controls the data port, not ulp coprocessor SENS.sar_touch_ctrl1.xpd_hall_force = true; // RTC controller controls the hall sensor power,not ulp coprocessor SENS.sar_touch_ctrl1.hall_phase_force = true; // RTC controller controls the hall sensor phase,not ulp coprocessor //start conversion SENS.sar_meas_start1.sar1_en_pad = (1 << channel); //only one channel is selected. while (SENS.sar_slave_addr1.meas_status != 0); SENS.sar_meas_start1.meas1_start_sar = 0; SENS.sar_meas_start1.meas1_start_sar = 1; while (SENS.sar_meas_start1.meas1_done_sar == 0); adcValue = SENS.sar_meas_start1.meas1_data_sar; // set adc value! SENS.sar_meas_wait2.force_xpd_sar = SENS_FORCE_XPD_SAR_PD; // adc power off }
Thank you very much for sharing the code! Works like a charm!
Do you probably have a repository?
Who is online
Users browsing this forum: Google [Bot] and 212 guests