Skip to main content
SSARI.1
Associate
March 15, 2022
Solved

STM32L152C-DISCO UART doesn't work correctly

I want to send the numbers in order but it only sends the number 0 constantly. When I make the delay 100ms it only sends 0 and 1. When I remove the delay completely, it sends numbers from 1 to 30 in order.

This topic has been closed for replies.
TDK
TDKBest answer
March 15, 2022

Sounds like it's resetting due to a watchdog or other event sometime 200-300ms after reset. That would explain all behavior.

Disable watchdog in option bytes.

Monitor NRST line to verify reset.

Read and clear RCC->CSR bits on startup to determine cause of reset.

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

6 replies

ONadr.1
Senior III
March 15, 2022

I woudl try this code with external crystal oscilator. Or measure the USART output with osciloscope or LA (if timing is correct).

SSARI.1
SSARI.1Author
Associate
March 15, 2022

I tried with external 16MhZ crystal oscilator.

ONadr.1
Senior III
March 15, 2022

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

RCC_OscInitStruct.HSIState = RCC_HSI_ON;

RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

In this code is used internal oscilator. I dont know what you try.

Are some pulses on the Tx output or line hungs to L/H after some time?

SSARI.1
SSARI.1Author
Associate
March 15, 2022

I tried with external 16MhZ crystal oscilator but now i'm using internal OSC.

TDK
TDKBest answer
March 15, 2022

Sounds like it's resetting due to a watchdog or other event sometime 200-300ms after reset. That would explain all behavior.

Disable watchdog in option bytes.

Monitor NRST line to verify reset.

Read and clear RCC->CSR bits on startup to determine cause of reset.

"If you feel a post has answered your question, please click ""Accept as Solution""."
SSARI.1
SSARI.1Author
Associate
March 15, 2022

I disabled watchdog in option bytes. It is working now