/* Check for overrun errors */ void adc_isr(void) { if (adc_get_overrun_flag(ADC1)) { adc_clear_overrun_flag(ADC1); } gpio_set(GPIOD, GPIO15); }
static void platform_init_adc() { /* Set up DMA for the ADC */ nvic_enable_irq(NVIC_DMA2_STREAM0_IRQ); nvic_set_priority(NVIC_DMA2_STREAM0_IRQ, 64); /* Set up ADC */ for (int i = 0; i < NUM_SENSORS; ++i) { if (config.sensors[i].method == SENSOR_ADC) { adc_pins[i] = config.sensors[i].pin; gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, (1<<adc_pins[i])); } } adc_off(ADC1); adc_enable_scan_mode(ADC1); adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_15CYC); adc_power_on(ADC1); adc_disable_dma(ADC1); adc_enable_dma(ADC1); adc_clear_overrun_flag(ADC1); adc_set_dma_continue(ADC1); dma_stream_reset(DMA2, DMA_STREAM0); dma_set_priority(DMA2, DMA_STREAM0, DMA_SxCR_PL_HIGH); dma_set_memory_size(DMA2, DMA_STREAM0, DMA_SxCR_MSIZE_16BIT); dma_set_peripheral_size(DMA2, DMA_STREAM0, DMA_SxCR_PSIZE_16BIT); dma_enable_memory_increment_mode(DMA2, DMA_STREAM0); dma_set_transfer_mode(DMA2, DMA_STREAM0, DMA_SxCR_DIR_PERIPHERAL_TO_MEM); dma_enable_circular_mode(DMA2, DMA_STREAM0); dma_set_peripheral_address(DMA2, DMA_STREAM0, (uint32_t) &ADC1_DR); dma_set_memory_address(DMA2, DMA_STREAM0, (uint32_t) adc_dma_buf); dma_set_number_of_data(DMA2, DMA_STREAM0, NUM_SENSORS); dma_enable_transfer_complete_interrupt(DMA2, DMA_STREAM0); dma_channel_select(DMA2, DMA_STREAM0, DMA_SxCR_CHSEL_0); dma_enable_stream(DMA2, DMA_STREAM0); adc_set_regular_sequence(ADC1, NUM_SENSORS, adc_pins); }