Skip to content

Commit

Permalink
sensors: reconfig adc for channel
Browse files Browse the repository at this point in the history
    Some ADCs (e.g. SAM0) can only convert one channel at a time
    and therefore need to be reconfigured for every voltage
    divider prior to startin the conversion

Signed-off-by: Patrick Günzel <patrick.guenzel@kinexon.com>
  • Loading branch information
guenzel-kinexon authored and henrikbrixandersen committed Jan 14, 2025
1 parent c46247b commit 2a999e1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/sensor/voltage_divider/voltage.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ static int fetch(const struct device *dev, enum sensor_channel chan)
/* Wait until sampling is valid */
k_sleep(data->earliest_sample);

/* configure the active channel to be converted */
ret = adc_channel_setup_dt(&config->voltage.port);
if (ret != 0) {
LOG_ERR("adc_setup failed: %d", ret);
return ret;
}

/* start conversion */
ret = adc_read(config->voltage.port.dev, &data->sequence);
if (ret != 0) {
LOG_ERR("adc_read: %d", ret);
Expand Down

0 comments on commit 2a999e1

Please sign in to comment.