cancel
Showing results for 
Search instead for 
Did you mean: 

usart2 stm32g030k8 does not work correctly

Akoli.2
Associate III

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)

1 ACCEPTED SOLUTION

Accepted Solutions

> USART2-> PRESC = USART_PRESC_PRESCALER_0;

in 'G030, USART2 does not have the prescaler, don't use it.

JW

View solution in original post

2 REPLIES 2

> USART2-> PRESC = USART_PRESC_PRESCALER_0;

in 'G030, USART2 does not have the prescaler, don't use it.

JW

Thank you very much. I removed USART2-> PRESC = USART_PRESC_PRESCALER_0; and now it works.