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?
At 3:53 Why did you tick the ADC1,ADC2,ADC3 interrupts? Is it because you are using multiple channels? If I am using a single channel then should I tick it or not?
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?
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.
@@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
@@abelashenafi6291 HAL_ADC_Start_DMA add this code inside the while loop. Also its good to use HAL_ADC_Stop_DMA inside the conversion complete callback function
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?
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
@@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).
very intro about dma in stm32....i have implemented in stm32f446re. but i am unable to visualize adc data which is changing in live expression tab.it is freezing at initial value. how to change it? any solution would be appreciable.
Hi Dileep, this code only read value once from ADC channel. But it keep printing on UART continuously. If you want to see the changed ADC values on serial terminal then you've to modify the program. While making video I needed ADC conversion only once at interrupt so i used same code but you can easily modify. Best wishes!
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.
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!
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.
HAL_ADC_Start_DMA, the code responsible for taking reading is not inside the while loop. so it only takes the reading once. So maybe adding it inside the loop helps.
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.
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?
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!
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.
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?
At 3:53 Why did you tick the ADC1,ADC2,ADC3 interrupts? Is it because you are using multiple channels? If I am using a single channel then should I tick it or not?
Excellent work, very clear, structured and informative presentation on a popular topic for STM32. Congratulations Sir.
Thanks you! I'm glad you enjoyed this STM32 tutorial. Best wishes!
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?
Not only are you right about that, but there is a final line missing: reset the "convCompleted" variable to zero.
this multiple ADC doesn't work for me. I'm using nucleo G070rb . What may the reason..?
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
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.
@@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
@@abelashenafi6291 To avoid the reset it is only necessary to reset the "convCompleted" variable to zero
@@abelashenafi6291 HAL_ADC_Start_DMA add this code inside the while loop. Also its good to use HAL_ADC_Stop_DMA inside the conversion complete callback function
Very nice, I dont need to make the video faster because you speak on a very reasonable speed.
I don't think you need a for loop at 11:30 to get values for `lux` and `pot`, also resetting mcu doesn't help much
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?
Why were the channel cycles set to 480 cycles instead of 3?
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
@@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).
very intro about dma in stm32....i have implemented in stm32f446re. but i am unable to visualize adc data which is changing in live expression tab.it is freezing at initial value. how to change it? any solution would be appreciable.
Thanks a lot :)
Brother Im using NUCLEO-L452RE so what I do if i want to make all 16 channels in active mode
How did you learn all this? I would also like to know this way. Would you be able to recommend any books or courses?
Excellent explained
Thank you
Good luck and best wishes!
why we need to reset the board any reason behind it?
Hi Dileep, this code only read value once from ADC channel. But it keep printing on UART continuously. If you want to see the changed ADC values on serial terminal then you've to modify the program. While making video I needed ADC conversion only once at interrupt so i used same code but you can easily modify. Best wishes!
Nice Video Sir!!!
Thank you so much Santamanyu. Best wishes!
how come you're not resetting the flag after the blocking while loop?
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.
sir please make the video on SPI and I2C
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!
I should use a DMA with a lot more samples (32, 64 ones) to work them after in order to use DMA advantages
Nice video, can u share the code and instructions?
Please give me a link to the previous video on the stm32
Hi Whiteknighte, the video of Single channel ADC is in description section. Also, check entire playlist of STM32 Nucleo Board. Thanks!
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.
HAL_ADC_Start_DMA, the code responsible for taking reading is not inside the while loop. so it only takes the reading once. So maybe adding it inside the loop helps.
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?
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.
Good job. But slowwww down.
Thank you! I'll incorporate your suggestions. Best wishes!
This is awful.
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?
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!
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.