Multi-Channel ADC with STM32 using DMA and Interrupt- Multiple Analog Sensors

Sdílet
Vložit
  • čas přidán 29. 06. 2024
  • Learn how to use Multi Channel ADC with STM32 Microcontroller. We’ll program ADC to read multiple ADC channels of STM32 Nucleo board. This project uses DMA and Interrupt along with ADC to sample multiple sensor data. In the end, we’ll measure light intensity using LDR and variable resistor using POT as an analog sensor.
    [SUPPORT]
    ►► Try the world's most trusted PCB design software, Altium Designer with 365, for free and 25% off your purchase: www.altium.com/yt/binaryupdates
    ►► Free search engine for the best quality components from Octopart: octopart.com/
    ►► Learn about Altium 365, the electronics product design platform that unites PCB design, MCAD, data management, and teamwork: www.altium.com/altium-365
    [RESOURCES]
    ►► Need Help? To Learn Embedded Systems: courses.binaryupdates.com
    ►► Single Channel ADC: • How to use ADC in STM3...
    [TIMESTAMPS]
    00:00 Introduction
    00:16 Altium Free Trial
    00:47 Create new project
    01:28 Configure Multi-channel ADC
    03:04 Configure DMA in ADC
    03:48 Configure NVIC Interrupt
    04:30 Configure UART
    05:04 Write code for ADC Multiple Channel
    15:03 Connect LDR and POT with STM32
    16:26 Upload the code on STM32 MCU
    16:42 read multiple analog sensor values
    18:05 outro
  • Věda a technologie

Komentáře • 35

  • @lucdrouin2625
    @lucdrouin2625 Před 7 měsíci +3

    Excellent work, very clear, structured and informative presentation on a popular topic for STM32. Congratulations Sir.

    • @BINARYUPDATES
      @BINARYUPDATES  Před 6 měsíci

      Thanks you! I'm glad you enjoyed this STM32 tutorial. Best wishes!

  • @javierlopez2022
    @javierlopez2022 Před 3 měsíci +1

    Thanks a lot :)

  • @usmantariq1611
    @usmantariq1611 Před 7 měsíci

    Excellent explained

  • @abelashenafi6291
    @abelashenafi6291 Před 4 měsíci

    Thanks for the superb explanation. I learned quite a lot! But why do we need to reset the MCU every time we need to read the input voltage of each Analog pin? is there anyway where we could read the input voltage without resetting the MCU?

  • @gujarisantamanyugmai
    @gujarisantamanyugmai Před 13 dny

    Nice Video Sir!!!

  • @unknown.477
    @unknown.477 Před 7 měsíci +2

    this multiple ADC doesn't work for me. I'm using nucleo G070rb . What may the reason..?

  • @javierlopez2022
    @javierlopez2022 Před 3 měsíci

    I should use a DMA with a lot more samples (32, 64 ones) to work them after in order to use DMA advantages

  • @bobby4976
    @bobby4976 Před 4 měsíci

    thank you.
    anyway i am wondering, in line 126 (minute 10:20): why does the code has to iterate it until i < number of conv. ?
    i can understand if it is only 2 number conversions so that the code only does the iteration once since it is 2-1.
    say, for example, if we have 3 number of conversions, then the code there will have to iterate twice since it is 3 - 1. So reading adc chanel 0, 1, 2 twice?

    • @neudyvielma
      @neudyvielma Před měsícem

      Not only are you right about that, but there is a final line missing: reset the "convCompleted" variable to zero.

  • @JoeBob189
    @JoeBob189 Před 2 měsíci

    at 7:12 you cast rawValues as a uint32_t pointer, however rawValues is a 16 bit array with a size of 2. This means that 32 bits in total are taken up by rawValues.
    You give your uint32_t casted rawValues a size of 2, which would tell the compiler that you have 64 bits allocated for this buffer. Wouldn't this be a vulnerability as it is *possible* to overwrite an unrelated address?
    Am I missing something here?

  • @dragon_619
    @dragon_619 Před 4 měsíci

    Brother Im using NUCLEO-L452RE so what I do if i want to make all 16 channels in active mode

  • @CAN_MIKE
    @CAN_MIKE Před 4 měsíci +1

    Hello, I don't understand why you have to reset the board to obtain a new value from the ADC, in theory the DMA ADC would have to do it

    • @BINARYUPDATES
      @BINARYUPDATES  Před 4 měsíci +1

      Hi Mike. you're right to make this multiple ADC with STM32 short I did conversion in while loop. Otherwise to avoid press RESET button I'll have to add few more lines on code. To keep video short I prefer this way of reading multichannel ADC in video lesson.

    • @abelashenafi6291
      @abelashenafi6291 Před 4 měsíci +1

      @@BINARYUPDATES Hey man, can you please add the few lines of code to avoid resetting the MCU all the time and see the values change in real-time? This would be really really appreciated. Regardless, you just earned a subscriber. Kudos

    • @neudyvielma
      @neudyvielma Před měsícem

      @@abelashenafi6291 To avoid the reset it is only necessary to reset the "convCompleted" variable to zero

  • @khichadeneeta
    @khichadeneeta Před 2 měsíci +1

    sir please make the video on SPI and I2C

    • @BINARYUPDATES
      @BINARYUPDATES  Před 2 měsíci

      Hi Khichadeneeta, I'll try to find time soon to finish making videos on using I2C and SPI peripheral to interface different sensors with STM32 Microcontroller. Thanks for your patience. Best wishes!

  • @spencerclegg1606
    @spencerclegg1606 Před 5 měsíci +3

    Why were the channel cycles set to 480 cycles instead of 3?

    • @BINARYUPDATES
      @BINARYUPDATES  Před 4 měsíci +1

      The 480 cycle is an optimal and most common choice to make sure we achieve resolution and accuracy while reading ADC value. If we choose 3 cycle then it will be very fast and it'll not allows us to read analog pins to maintain stable output from ADC channel of STM32

    • @spencerclegg1606
      @spencerclegg1606 Před 4 měsíci

      @@BINARYUPDATES Perfect, thanks. Yeah, I'd assume at some point it will not finish reading the ADC channels before the next cycle begins. So in cases where sample rate isn't critical it makes sense to select the slowest sample rate (480 cycles).

  • @muhammadabdullah5660
    @muhammadabdullah5660 Před měsícem

    Kindly tell that why we are pressing reset button to see new value, why don't we get new value automatically. I understood everything it was informative video but this Question kindly answer. Anyone can tell me i need the answer i am learning this.

  • @woldecosgrove
    @woldecosgrove Před 7 měsíci +1

    Nice video, can u share the code and instructions?

  • @itayjc1
    @itayjc1 Před 3 měsíci +1

    how come you're not resetting the flag after the blocking while loop?

    • @JoeBob189
      @JoeBob189 Před 2 měsíci

      Because he's only doing one reading from the ADC. If you check his code, he never does another conversion. He is manually resetting the board to force another conversion. No need to reset the flag if it is only used once.

  • @whiteknighte
    @whiteknighte Před 9 měsíci

    Please give me a link to the previous video on the stm32

    • @BINARYUPDATES
      @BINARYUPDATES  Před 9 měsíci

      Hi Whiteknighte, the video of Single channel ADC is in description section. Also, check entire playlist of STM32 Nucleo Board. Thanks!

  • @ahbushnell1
    @ahbushnell1 Před 3 měsíci

    Good job. But slowwww down.

  • @OndrejPopp
    @OndrejPopp Před 4 měsíci

    I haven't seen a schematic, but from the "wiring explanation" I got the impression that you are feeding the ADC input from 5V and not from 3V3. You have to be careful with that, because not every input of the micro controller is 5V tolerant.... And if you use one that is not, it may get damaged due to the 5V...
    So, actually I just checked on the stm32 forum : 5V tolerance does not apply to analog inputs at all, and you should not go beyond min(VDDA, VREF+) +0.3. VDDA and VREF+ are on the nucleo boards I have, Nucleo-743ZI2, equal to VDD_MCU which is dependent on a jumper setting and is either 3V3 or 1V8.... so be careful with that, and check the board schematic to see what VDDA and VREF+ actually are on your board, most likely 3V3 with the standard jumper setting like on the one I have.

  • @wavemusic6386
    @wavemusic6386 Před 6 měsíci

    I have problem with line
    while(!convCompleted);
    this 'while' clause does not guard... [-Wmisleading-indentation] main.c
    This code working only one time.
    What can i do?

    • @BINARYUPDATES
      @BINARYUPDATES  Před 6 měsíci

      The code is written to print ADC value only once using Single conversion. So when we press RESET button then only next ADC conversion happen. It's because of the use of interrupt in code. if you make ADC conversion code in while loop then it will print continuously in continuous conversion mode instead of single conversion mode. I hope this may help you. Good luck and best wishes!

    • @OndrejPopp
      @OndrejPopp Před 4 měsíci

      Actually, while(!convCompleted); means : "loop until convCompleted becomes true", and there are no additional statements needed, and the semi-colon at the end means an "empty single statement". You can have a single statement after a control structure, such as a while or an if, without the need of curly braces {....} which is called a compound statement, if there is only one or an empty statement following it. So while(cond) stat; a control structure with a single statement, is equivalent to while(cond) {stat;} and while(cond); a control structure with an empty statement is equivalent to while(cond){}. This short form without the curly braces is more convenient to write, but can be ambiguous and a source of very subtle mistakes and that is why the compiler checks for this. For example while(cond) ; {.....} means : a while loop with an empty statement, (like in this code) followed by an "unguarded" compound statement. But maybe there is a typo in the code and what was actually meant was while(cond) {.... }. This can happen because while typing you are used to put a semi-colon at almost every line and so a mistake like this is easily made and very hard to track down. And that is why the compiler warns about this, because it can not know what was actually meant. But the construct here is correct, but writing it like while(!convCompleted){} is more readable and will silence the compiler ⚠️.
      P.S, because the compiler warns about "misleading identation" maybe if you write it like this,
      while(!convCompleted)
      ;
      So putting the semi-colon on the next line, and indent it, will silence the compiler as well. But you need to try that, most of the time "white space" is ignored so maybe this does not work, but using empty curly braces, so while(cond){} should always work.

  • @MohammedAltowayti
    @MohammedAltowayti Před 3 měsíci

    I'm using STM32 NUCLEO-F411RE chip... Can you help me write a code to make it capture an image using OV2640 and store it in pc folder?