STM32 ADC using Interrupt method
AS mentioned in the previous posts that there are many ways to write a program for ADC in STM32 like PollForConversion, interrupt and DMA. This post is going to cover the interrupt method. You can check out the PollForConversion and DMA methods too.
An interrupt is a signal sent to the CPU which indicates that a system event has occurred, which needs immediate attention. In case of an interrupt got triggered, CPU stops whatever it is doing and executes a function first. This function is a small piece of code also known as ISR(Interrupt Service Routine).
Interrupt is widely used in embedded systems to ensure that no CPU time is wasted ‘polling‘ the sensor for the data rather an interrupt is triggered whenever the data is available to be read from the sensor.
PA5 is selected as GPIO Output and a LED is connected to it to show how the interrupt method doesn’t affect the normal working of the controller.
Select the ADC1 channel 0
- Here Resolution of adc is selected as 12 bit
- Scan conversion mode is disabled because only one channel is selected
- Continuous conversion mode is enabled as we want adc to work continuously
- DMA continuous request is disabled as we are not using DMA here.
Go to NVIC Settings tab and check the “ADC global interrupt”.
Some Insight into the CODE
Let’s begin by writing a Conversion complete callback function. This function will be called whenever ADC finishes the conversion and data is ready to be read.
Whenever the conversion is complete, following function is executed. The value of ADC will be stored in the value variable. After the completion of the function, control will go back to main function.
In order to start the ADC in interrupt mode, we need to use
. . . . . DOWNLOAD . . . . .
You can buy me acontrollerstech
coffeeSensor by clicking DONATE OR Just click DOWNLOAD to download the code
- WavePlayer using STM32 Discovery January 16, 2021
- How to use SPI in LPC2148 December 26, 2020
- STM32 ADC MULTI CHANNEL WITHOUT DMA December 24, 2020
- Send and Receive data to PC without UART (STM32 USB COM) December 10, 2020
- STM32 GPIO INPUT Configuration December 4, 2020
- STM32 GPIO OUTPUT Config using REGISTERS November 24, 2020