adc_monitor example
Posted: Mon Jun 03, 2024 9:31 pm
I'm trying to use the esp32-h2 with an adc.
According to https://docs.espressif.com/projects/esp ... nuous.html i should be able to use a adc_monitor.
I've written an example, it doesn't give any error, but it doesn't work. Does anyone have a working example?
Setting up the monitor
I get no errors, and i can see using my continious monitor that the values are being read.
According to https://docs.espressif.com/projects/esp ... nuous.html i should be able to use a adc_monitor.
I've written an example, it doesn't give any error, but it doesn't work. Does anyone have a working example?
- static bool IRAM_ATTR monitor_event(adc_monitor_handle_t monitor_handle, const adc_monitor_evt_data_t *event_data, void *user_data)
- {
- ESP_LOGI(TAG, "Monitor event triggered");
- return true;
- }
Setting up the monitor
- // Set up the monitor
- adc_monitor_handle_t monitor_handle = NULL;
- adc_monitor_config_t monitor_config = {
- .adc_unit = ADC_UNIT_1,
- .channel = ADC_CHANNEL,
- .h_threshold = 3400,
- .l_threshold = 3200,
- };
- adc_monitor_evt_cbs_t cbs_monitor = {
- .on_over_high_thresh = monitor_event,
- .on_below_low_thresh = monitor_event,
- };
- ret = adc_new_continuous_monitor(handle, &monitor_config, &monitor_handle);
- if (ret != ESP_OK) {
- ESP_LOGE(TAG, "Failed to create new monitor: %s", esp_err_to_name(ret));
- }
- ret = adc_continuous_monitor_register_event_callbacks(monitor_handle, &cbs_monitor, NULL);
- if (ret != ESP_OK) {
- ESP_LOGE(TAG, "Failed to register monitor event callbacks: %s", esp_err_to_name(ret));
- }
- ret = adc_continuous_monitor_enable((adc_monitor_handle_t)monitor_handle);
- if (ret != ESP_OK) {
- ESP_LOGE(TAG, "Failed to enable ADC monitor: %s", esp_err_to_name(ret));
- }