Functions in while loop are not working when ADC DMA conversion

Status
Not open for further replies.

uranyumx

Advanced Member level 4
Joined
Mar 5, 2011
Messages
102
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,296
Activity points
2,098
Hello,


I successfully convert analog signals into digital with ADC DMA mode. But when ADC is converting the analog signals, the functions in while loop are not working. It looks like that while loop is not operating. Do you have suggestions about the solution?

Code:
volatile uint8_t convCompleted = 0;
 
int main(void)
...
    HAL_ADC_Start_DMA(&hadc1, (uint32_t*)ADCReadings_Evoked,50000);
 
    while(!convCompleted);
 
    HAL_ADC_Stop_DMA(&hadc1);
 
while (1)
 /* USER CODE BEGIN 3 */
        HAL_GPIO_WritePin(Led_GPIO_Port, Led_Pin, GPIO_PIN_RESET);
        HAL_Delay(1000);
        HAL_GPIO_WritePin(Led_GPIO_Port, Led_Pin, GPIO_PIN_SET);
 

There are two while loops. Of course the second doesn't start before the first has ended. If you wan't some code executed when the DMA transfer ends use an interrupt.
 

Hi,

What are you trying to achieve?

DMA is useful when you want to run cun code while the ADC is converting data.
Code in the meaning of useful code.

But all you run is a useless "while" loop to wait for the ADC to be finished. Useless, because you don't make useful calculations or do anything useful.

So I see two options
* either you simply want to wait until the conversion is complete --> then don't use DMA but use a blocking ADC call.
* or you want to do something useful, then use ADC_DMA ... and run the code you want. And later check if the ADC has finished ...or use an DMA_interrupt.

ADC_DMA is useful when you want to convert "a lot of samples" before you want to process the ADC values.
Let's say 1000 samples with a sampling rate of 10kHz..which takes 100ms.

Klaus
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…