Working through the dev academy exercise, it appears that the sample code does not wait for the conversion to complete before reading out the sample:
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* STEP 7.1 - Implement timer callback handler function */
void battery_sample_timer_handler(struct k_timer *timer)
{
· · · · /* STEP 7.2 - Trigger the sampling */
· · · · nrfx_err_t err = nrfx_saadc_mode_trigger();
· · · · if (err != NRFX_SUCCESS) {
· · · · · · · · printk("nrfx_saadc_mode_trigger error: %08x", err);
· · · · · · · · return;
· · · · }
· · · · /* STEP 7.3 - Calculate and print voltage */
· · · · int battery_voltage = ((600*6) * sample) / ((1<<12));
· · · · printk("SAADC sample: %d\n", sample);
· · · · printk("Battery Voltage: %d mV\n", battery_voltage);
}
Would it not be more appropriate to get a call back from the nrfx_saadc_irq_handler when the conversion is complete?
When using the Zephyr ADC driver on the same exact board, it appears the ADC measurements are ~30 mV different.
Can you please confirm if we should be waiting for the conversion to complete here?