cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L152C-DISCO UART doesn't work correctly

SSARI.1
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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".

View solution in original post

6 REPLIES 6
ONadr.1
Senior III

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

SSARI.1
Associate II

I tried with external 16MhZ crystal oscilator.

ONadr.1
Senior III

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
Associate II

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

TDK
Guru

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".

I disabled watchdog in option bytes. It is working now