Skip to main content
Tejashree
Associate III
January 28, 2022
Question

How to read ADC for different ADC pins using DMA buffer?

  • January 28, 2022
  • 5 replies
  • 4710 views

0693W00000JNfd6QAD.pngI am have configured 3 ADC pins (PA4,PC4,PB11) with DMA.I want to read individual values at 3 different PINs.

0693W00000JNfi1QAD.pnghow do adjust the size of the buffer for 3 Pins?Or any other way to read it?

This topic has been closed for replies.

5 replies

KnarfB
Super User
January 28, 2022

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

Tejashree
TejashreeAuthor
Associate III
January 28, 2022

 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?

Tejashree
TejashreeAuthor
Associate III
January 28, 2022

 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?

Javier1
Principal
January 28, 2022

Did you checked DMA init was called before ADC_init?

Its a common bug in cumemx autogenerated code

it happened to me

hit me up in https://www.linkedin.com/in/javiermuñoz/
Tejashree
TejashreeAuthor
Associate III
January 28, 2022

Yes, DMA_Init() is called before ADC_Init().

Javier1
Principal
January 28, 2022

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

0693W00000JNhcZQAT.pngword=32bits

halfword=16bits

byte=8bits

hit me up in https://www.linkedin.com/in/javiermuñoz/
Tejashree
TejashreeAuthor
Associate III
January 28, 2022

0693W00000JNhgbQAD.pngHalf Word = 16 bits

so what would be my buffer size for following Pins?

PA4-ADC2_IN17

PC4-ADC2_IN5

PB11-ADC2_IN14

ssipa.1
Visitor II
January 28, 2022
Javier1
Principal
January 31, 2022

this tutorial is lit

hit me up in https://www.linkedin.com/in/javiermuñoz/