STM32 ADC Read Methods
We can read actually configure the ADC module to take samples (conversions) in 3 different ways. Depending on the application types and requirements you can choose the best fit for you.
1 Polling
First of which is the polling method, in this method we’d start an ADC conversion and stop the CPU at this point to wait for the ADC conversion completion. Only after ADC conversion completion, the CPU can resume the main code execution.
2 Interrupts
The second method is by using interrupts, so we can trigger the ADC in order to start a conversion and the CPU continues executing the main code routine. Upon conversion completion, the ADC fires an interrupt and the CPU is notified so that it can switch the context to the ISR handler and save the ADC conversion results.
Despite being an efficient way, the interrupt method can add so much overhead to the CPU and cause very high CPU loading. Especially when you’re doing so many conversions per second.
3 DMA
And here comes the third method which is using the DMA unit that can directly transfer the ADC result from the peripheral to the memory in the manner that you want and program it to. All that being done without any CPU intervention and upon DMA transfers completion to maybe a 1kb in length buffer, it can notify the CPU to process the data of whatever.
Example 1, ADC is used in blocking mode (polling)
Example 2, ADC is used in non-blocking mode (interrupt)
Example 3, ADC is used in non-blocking mode (DMA)
Example 4, Timer2 PWM is used in non-blocking mode (DMA)
https://github.com/ismailErolAcOCrW