@@ -207,6 +207,7 @@ STATIC mp_obj_t adc_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_
207
207
208
208
// flag the device/channel as being in use.
209
209
ch_busy_flags |= (1 << (self -> adc_config .device * 16 + self -> adc_config .channel ));
210
+ device_mgmt [self -> adc_config .device ].init = false;
210
211
self -> dma_channel = -1 ;
211
212
self -> tc_index = -1 ;
212
213
@@ -225,6 +226,8 @@ STATIC mp_obj_t machine_adc_read_u16(mp_obj_t self_in) {
225
226
mp_raise_OSError (MP_EBUSY );
226
227
}
227
228
229
+ // Set the reference voltage. Default: external AREFA.
230
+ adc -> REFCTRL .reg = adc_vref_table [self -> vref ];
228
231
// Set Input channel and resolution
229
232
// Select the pin as positive input and gnd as negative input reference, non-diff mode by default
230
233
adc -> INPUTCTRL .reg = ADC_INPUTCTRL_MUXNEG_GND | self -> adc_config .channel ;
@@ -262,6 +265,8 @@ STATIC mp_obj_t machine_adc_read_timed(mp_obj_t self_in, mp_obj_t values, mp_obj
262
265
if (self -> tc_index == -1 ) {
263
266
self -> tc_index = allocate_tc_instance ();
264
267
}
268
+ // Set the reference voltage. Default: external AREFA.
269
+ adc -> REFCTRL .reg = adc_vref_table [self -> vref ];
265
270
// Set Input channel and resolution
266
271
// Select the pin as positive input and gnd as negative input reference, non-diff mode by default
267
272
adc -> INPUTCTRL .reg = ADC_INPUTCTRL_MUXNEG_GND | self -> adc_config .channel ;
@@ -432,7 +437,7 @@ static void adc_init(machine_adc_obj_t *self) {
432
437
// Divide a 48MHz clock by 32 to obtain 1.5 MHz clock to adc
433
438
adc -> CTRLB .reg = ADC_CTRLB_PRESCALER_DIV32 ;
434
439
// Select external AREFA as reference voltage.
435
- adc -> REFCTRL .reg = self -> vref ;
440
+ adc -> REFCTRL .reg = adc_vref_table [ self -> vref ] ;
436
441
// Average: Accumulate samples and scale them down accordingly
437
442
adc -> AVGCTRL .reg = self -> avg | ADC_AVGCTRL_ADJRES (self -> avg );
438
443
// Enable ADC and wait to be ready
0 commit comments