Skip to main content
Akoli.2
Associate II
October 4, 2021
Solved

usart2 stm32g030k8 does not work correctly

  • October 4, 2021
  • 2 replies
  • 1039 views

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)

This topic has been closed for replies.
Best answer by waclawek.jan

> USART2-> PRESC = USART_PRESC_PRESCALER_0;

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

JW

2 replies

waclawek.jan
waclawek.janBest answer
Super User
October 4, 2021

> USART2-> PRESC = USART_PRESC_PRESCALER_0;

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

JW

Akoli.2
Akoli.2Author
Associate II
October 4, 2021

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