- What HAL_ADC_START_IT() does:
- It doesn't directly start the ISR, instead it
- Starts the ADC conversion in interrupt mode
- Enables the ADC interrupt so that when the conversion completes, the ADC peripheral will trigger an interrupt
- The ISR - specifically HAL_ADC_CONVCpltCallback() - is then called automatically by the HAL when the conversion finishes
- It doesn't directly start the ISR, instead it
- Comparing it ot HAL_ADC_Start:
- HAL_ADC_Start():
- Starts ADC conversion in Polling Mode
- CPU waits (blocks) until conversion is complete
- You manually call HAL_ADC_GETValue() to retrieve the result
- No ISR is involved
- Must be called again after each conversion if not in continuous mode
- HAL_ADC_START_IT():
- Starts ADC conversion in Interrupt Mode
- CPU continues executing other code - non-blocking
- When converesion completes, ADC triggers an interrupt
- HAL calls your HAL_ADC_ConvCpltCallback() ISR
- You typically read the result insdie that callback
- Also needs to be called again after each conversion unless continuous mode is enabled
- HAL_ADC_Start():
- Blocking Operation:
- The CPU waits until the operation finishes
- It does nothing else during that time
- Example: HAL_ADC_Start() followed by HAL_ADC_PollForConversion() — the CPU sits and waits for the ADC to finish before moving on.
- Analogy: Like standing at a microwave waiting for your food - you're not doing anything else until it's done
- Non-Blocking Operation:
- The CPU starts the operation then moves on immediately
- When the operation finishes, it notifies the CPU (via interrupt or callback)
- Example: HAL_ADC_Start_IT() — ADC runs in the background, and the CPU keeps working until the ISR fires.
- Analogy: Like setting atime on the oven and going to do laundry - the oven beeps when it's done, and you respond then
- Blocking is simpler to implement, but it wastes CPU cycles
- Non-Blocking is efficient and let's you multitask - ideal for real-time systems or juggling multiple peripherals
- DMA: Direct Memory Access
- hardware feature that let's peripherals (like ADCs) transfer data directly to memory - without involving the CPU
- HAL_ADC_Start_DMA():
- The ADC starts converting
- DMA controller watches the ADC
- As soon as a conversion completes, DMA automatically copies the result into a buffer in RAM
- The CPU is never blocked, and no ISR is needed for each sample
- When the buffer is full (or transfers completes) DMA triggers an interrupt - and you anlde it with HAL_ADC_ConvCpltCallback() or HAL_ADC_ConvHalfCpltCallback()
- Polling: Best for simple, one shot reads
- Interrupt: Best for event driven sampling
- DMA: Best for high-speed, multichannel, contiuous sampling
Ghani Lawal
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.