I am trying to run ADC measurement from the ULP RISC-V coprocessor but cannot figure out how to trigger them.
According to https://docs.espressif.com/projects/esp ... isc-v.html the ULP RISC-V has access to the SAR ADC peripheral but I am unsure how to use it from the ULP-RISCV. I have tried with code as follows:
Code: Select all
void init_ulp_program(void)
{
esp_err_t err = ulp_riscv_load_binary(ulp_main_bin_start, (ulp_main_bin_end - ulp_main_bin_start));
ESP_ERROR_CHECK(err);
/* The first argument is the period index, which is not used by the ULP-RISC-V timer
* The second argument is the period in microseconds, which gives a wakeup time period of: 20ms
*/
ulp_set_wakeup_period(0, 20000);
// adc setup
adc1_config_width(ADC_WIDTH_BIT_13);
adc1_config_channel_atten(ADC_UNIT_1, ADC_ATTEN_6db);
adc1_ulp_enable();
/* Start the program */
err = ulp_riscv_run();
ESP_ERROR_CHECK(err);
}
Code: Select all
uint32_t channel_mask = 1 << ADC_CHANNEL_8;
REG_WRITE(SENS_SAR_MEAS1_CTRL2_REG, SENS_SAR1_EN_PAD_FORCE | SENS_MEAS1_START_FORCE | SENS_MEAS1_START_SAR | (channel_mask << SENS_SAR1_EN_PAD_S));
do {
ulp_riscv_delay_cycles(100 * ULP_RISCV_CYCLES_PER_US);
last_reg_val = REG_READ(SENS_SAR_MEAS1_CTRL2_REG);
} while ((last_reg_val & SENS_MEAS1_DONE_SAR_M) == 0);