2021-10-04 04:48 AM
Hello everybody!
I can't use USART2 in STM32G030K8 to transfer data.
The TC flag of the ISR register is not set after writing data to the TDR register for an infinite time, if I use it to control the transfer of a byte, the program hangs without transferring anything.
If I use the TXE bit of the ISR for control, then the data is transmitted partially, i.e. not every byte sent arrives.
If I insert a forced delay after the byte is sent, then it doesn't solve the problem.
USART1 works without problems.
I am using the following USART initialization
RCC-> APBENR1 | = RCC_APBENR1_USART2EN;
USART2-> PRESC = USART_PRESC_PRESCALER_0;
USART2-> BRR = 3333; //baud rate 9600
USART2-> CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_UE;
for transfer data
while(!(USART2->ISR & (1 << 7))); //wait set TXE
USART2->TDR = data;
//while(!(USART2->ISR & (1 << 6))); // wait set TC (do not work)
Solved! Go to Solution.
2021-10-04 05:08 AM
> USART2-> PRESC = USART_PRESC_PRESCALER_0;
in 'G030, USART2 does not have the prescaler, don't use it.
JW
2021-10-04 05:08 AM
> USART2-> PRESC = USART_PRESC_PRESCALER_0;
in 'G030, USART2 does not have the prescaler, don't use it.
JW
2021-10-04 05:30 AM
Thank you very much. I removed USART2-> PRESC = USART_PRESC_PRESCALER_0; and now it works.