cancel
Showing results for 
Search instead for 
Did you mean: 

UART_FLAG_TXE is not set while a lots of ADC interrupt are issued.

Paul.Lee
Associate III

Hi,

I am using 4 ADC channel to read MIC circuit with STM32G030C8T6

I am using ADC interrupt service to read ADCs

I set ADC as follow:

Clock Prescaler: Async clock mode divided by 32

Scan conversion Mode: enable

Continuous conversion mode: enable

ADC_regular conversion node: sampling time common1 : 160.5 cycle

....

In main while loop. I do the print the 4 ADC data thru UART1.

But, for a while print the ADC data, stuck into checking UART_FLAG_TXE function.

When I set clock prescaler to Async clock mode divided by 16 or 8, faster UART TX stuck than 32 mode.

When I reduce the sampling time to smaller than 160.5 cycle, TX stuck become faster

When I set slow ADC processing, only 1 minute is good and then stuck

If no use printf, No problem.

What is problem?

Thank you

4 REPLIES 4
TDK
Guru

Sounds like you may be trying to send data out faster than the UART allows. Do a check of percentage bandwidth utilization. How much data are you generating and how quickly are you able to send it out.

If it occurs when you have lots of interrupts, it's also possible you get an overrun error due to not handling things fast enough. Shouldn't be directly related to TXE but perhaps you're not handling RXNE fast enough. Check for the OVR flag. Unlikely to be directly related to the ADC.

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

> stuck into checking UART_FLAG_TXE function.

What does that mean?

And how do you know it is stuck there?

Read our and check/post UART registers content.

JW

gbm
Lead III

Basically you cannot handle multiple channel ADC with interrupts unless you set the WAIT mode bit in ADC.

Since you didn't provide any code it's hard to guess what errors you made, but this is likely the root of the problems you encounter.

ADC interrupts are rarely useful in practice. Either use DMA with ADC or use timer interrupt to read the result from ADC with the WAIT mode set.

Paul.Lee
Associate III

This is Hardfault at this case.

My tx function is as follow.

 while (!(USART1->ISR & UART_FLAG_TXE));

 USART1->TDR = (ch & 0x1FF);

I run IWDG and I found the watchdog expire at while loop at checking UART_FLAG_TXE

I was considered using DMA but I have to count some event in ADC interrupt.

If not using UART, no hardfault.

0693W00000NpGxSQAV.jpg