Question
Fastes way with as little blocking as possible to read ADC-values
I'm currently thinking about how to make the ADC-readings not neccessary as fast as possible, but to cause as little blocking as possible. My current idea is to start the reading in the main() with
// Start ADC with DMA support
adc_dma_values_valid = 0;
HAL_ADC_Start_DMA(&hadc, adc_values, 8);
if (adc_dma_values_valid)
{
adc_dma_values_valid = 0;
// do something with the adc_values
}The DMA Interrupt then will set the adc_dma_values_valid to 1
void DMA1_Channel1_IRQHandler(void)
{
adc_dma_values_valid = 1;
HAL_DMA_IRQHandler(&hdma_adc);
}The other option would be to wait for the function to return a HAL_OK. But this will block the remaining program from running
while ( HAL_ADC_Start_DMA(adc_handler, adc_data, data_length) != HAL_OK );