cancel
Showing results for 
Search instead for 
Did you mean: 

Multi Channel ADC with DMA transfer on NUCLEO U575ZI-Q

mebrahim
Associate II

Hello,

 

I'm trying to configure my NUCLEO-U575ZI-Q to read multiple channels of ADC at once. I will describe the settings in the following and then raise my questions:

1- I use IN1 and IN2 on ADC4 which corresponds to PC0 and PC1 on the EVB
2- I set scan conversion mode to Forward (which I guess it means read first PC0 and then PC1 right?)
3- Continuous conversion mode is disabled

4- DMA continuous requests is Enabled (the strange part is that this option doesn't exist for ADC1. Will appreciate if someone can explain the reason and the meaning of it)
5- End of Conversion selection is set to End of Sequence of conversion (not single conversion) which should mean the EoC is True only after the two channels are converted (right?)
6- SamplingTime common 1&2 are set to 7.5 (I'm not sure why there are two)
7- Trigger Frequency is set to Low

8- I'd like to use Regular Conversion Launched by SW at the beginning and later use a Timer to automate this process. But this means that every time I need fresh transfers I need to call HAL_ADC_Start_DMA(&hadc4, (uint32_t*)adcResultsDMA, 2); or only once suffices?

9- I used DMA channel1 from GPDMA1 in Standard Request Mode

10- Circular mode is enabled and Port 0 is selected

11- Request is set to ADC4. Data Width is set to HalfWord (12 bit adc, hence 16 bits of FIFO) for both the source and the destination and by ST recommendation the Burst Length is set to 1

12- In the end, GPDMA1 Channel 1 global interrupt is enabled

I have the following questions and issues:
- I can't find a __weak implementation of DMAxferComplete to customize in another file
- I don't see the updates in adcResultsDMA which is my buffer to get the data from ADC

(uint16_t adcResultsDMA[2]; 
while (1){HAL_ADC_Start_DMA(&hadc4, (uint32_t*)adcResultsDMA, 2);})

-  I'm connecting 3v3 from board to PC1 to hopefully see the result in the buffer but I don't
I have found ST examples for U5 series but none of them were corresponding to my case.
In general it's very challenging to gather information from all manuals for a simple task as such. Any help, comments and insights are greatly appreciated. Sorry if I was verbose but I'm stuck for a while. Please check the screenshots as the reference.
Best regards,
Reza



 

1 ACCEPTED SOLUTION

Accepted Solutions
mebrahim
Associate II

For people who might face the same issue. After a few tough days, I realized one should manually supply the ADC by calling a function. STM Cube IDE is supposed to this automatically but it seems it is a bug in the generate code. To supply the ADCs one should put this line before ADC_Init functions:
HAL_PWREx_EnableVddA();
Otherwise the ADC does not work to begin with. My settings were correct so if anyone seeks the same approach, they can take it.

View solution in original post

9 REPLIES 9
AScha.3
Chief III

Hi,

while (1){HAL_ADC_Start_DMA(&hadc4, (uint32_t*)adcResultsDMA, 2);})

is your program now ?

So at first dont call the dma start continuously, give it some time to do something... ->

while (1)
{
  HAL_ADC_Start_DMA(&hadc4, (uint32_t*)adcResultsDMA, 2);
  HAL_Delay(20);
}

 

If you feel a post has answered your question, please click "Accept as Solution".
TDK
Guru

Here's a good example to go from. It addresses 90% of your questions.

https://github.com/STMicroelectronics/STM32CubeU5/blob/c8fcb26ff629cf7c2a3b2c60e6121625eaa5ca2d/Projects/NUCLEO-U575ZI-Q/Examples/ADC/ADC_DMA_Transfer/Src/main.c#L114

 

If you feel a post has answered your question, please click "Accept as Solution".

No In fact, I have HAL_DELAY(100) in my program. The real issues are the ones I talked about.

No I don't think it does. First, it doesn't explain at all about the ADC configuration and second it uses linked-list whereas this is not my goal. The README file contains no answer of the questions I raised.

mebrahim
Associate II

For people who might face the same issue. After a few tough days, I realized one should manually supply the ADC by calling a function. STM Cube IDE is supposed to this automatically but it seems it is a bug in the generate code. To supply the ADCs one should put this line before ADC_Init functions:
HAL_PWREx_EnableVddA();
Otherwise the ADC does not work to begin with. My settings were correct so if anyone seeks the same approach, they can take it.

TDK
Guru

Thanks for posting the solution.

That is called in the example but yeah seems like a bug for CubeMX not to include it in the auto-generated MspInit code.

https://github.com/STMicroelectronics/STM32CubeU5/blob/c8fcb26ff629cf7c2a3b2c60e6121625eaa5ca2d/Projects/NUCLEO-U575ZI-Q/Examples/ADC/ADC_DMA_Transfer/Src/stm32u5xx_hal_msp.c#L74

If you feel a post has answered your question, please click "Accept as Solution".
_Danny_
Associate III

Hi mebrahim,

I am facing the same issue, i have added  HAL_PWREx_EnableVddA() function  before ADC Init function. When i try to read the ADC value i am getting values like 49,50,51, is this correct ?

My Configurations

hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
hadc1.Init.Resolution = ADC_RESOLUTION_14B;
hadc1.Init.GainCompensation = 0;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
hadc1.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}

Hello Danny,

I'm not sure. Considering the max value you can have with 14 bits is 16383, it means you are reading very low voltages. In any case, please provide more information:
- How do you trigger the readings?

- What is the signal read by ADC?

- Which environment are you using?

Hi mebrahim

I am using STM32 Cube IDE for my project, and the signal being read by the ADC is the current sense output. I have  configured ADC1 with 12 bits, but it produced low values like 55,58 even after giving  3.3V to the adc pin. Then, I switched to ADC4, and now it works perfectly. What could be the possible reasons for the issue with ADC1. Should i need to change my configurations.?