2022-01-28 01:29 AM
I am have configured 3 ADC pins (PA4,PC4,PB11) with DMA.I want to read individual values at 3 different PINs.
how do adjust the size of the buffer for 3 Pins?Or any other way to read it?
2022-01-28 01:37 AM
The ADC values are interleaved in the buffer. So multiply the buffer size by the number of channels. The last parameter in HAL_ADC_Start_DMA is the size in Bytes. So 17 seems odd. Use sizeof(adc_buf) or calculate by *sizeof(uint32_t) etc..
If unsure: heavily oversize the allocated buffer, fill it with 0 and validate that only the expected number of bytes/values is written by debugging/dumping the buffer.
hth
KnarfB
2022-01-28 01:48 AM
HAL_ADC_Start_DMA(&hadc2, (uint32_t*)adc_buf, sizeofbuf);
Here I tried sizeofbuf as 3.But I cannot read the value .
Can you help me to set the exact value for sizeofbuf.
I am using ADC2.
PA4-ADC2_IN17
PC4-ADC2_IN5
PB11-ADC2_IN14
these are pins used.
What sizeofbuf should i choose in this case?
2022-01-28 01:48 AM
HAL_ADC_Start_DMA(&hadc2, (uint32_t*)adc_buf, sizeofbuf);
Here I tried sizeofbuf as 3.But I cannot read the value .
Can you help me to set the exact value for sizeofbuf.
I am using ADC2.
PA4-ADC2_IN17
PC4-ADC2_IN5
PB11-ADC2_IN14
these are pins used.
What sizeofbuf should i choose in this case?
2022-01-28 02:48 AM
Did you checked DMA init was called before ADC_init?
Its a common bug in cumemx autogenerated code
2022-01-28 02:56 AM
Yes, DMA_Init() is called before ADC_Init().
2022-01-28 04:23 AM
could you post an image of your cubeMX setup for the ADCs?
you should be able to calculate sizeofbuf with that info
match your receiving buffer unit definition (uint8_t/uint16_t/uint32_t) to the one setup n your DMA
word=32bits
halfword=16bits
byte=8bits
2022-01-28 04:31 AM
Half Word = 16 bits
so what would be my buffer size for following Pins?
PA4-ADC2_IN17
PC4-ADC2_IN5
PB11-ADC2_IN14
2022-01-28 05:11 AM
hello
you can read the following tutorial
STM32 ADC Read Example - DMA / Interrupt / Polling Example Code (deepbluembedded.com)
2022-01-28 06:27 AM
simply how many samples you need in buffer for one pin X num pins
for you for example 100 x 3 = 300
uint16_t adc_buf[300];
HAL_ADC_Start_DMA(&hadc2, (uint32_t*)adc_buf,300);
but your images is chaos DMA show ADC1 instead ADC2 and checked inputs isnt as you write