cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with UART on STM8L151

WRost.1
Associate II

I've been struggling with this problem for some time. Currently I'm porting my application from STM8L051 to STM8L151. Whenever I start USART1 Receiver, the USART Status Register (USART->SR) shows "0xfa", indicating Parity and Overrun Error. I tried with a different chip and still the same results. I'm using a bare chip soldered to QFP32 board with 100nF capacitor between VDD and VSS. The same program works ok on STM8L051. When I turn on USART TX only, USART->SR shows 0xC0. However when I turn on receiver, I get errors on USART and they won't disappear even after reading from DR and SR registers. I tried different power supply and still the same issues....

I'm using internal clock with default frequency of 2Mhz (HSI/8). If I change the prescaler to DIV1, still no progress.

Here's USART code:

CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);
  
 
//GPIO_Init(GPIOA, GPIO_Pin_3, GPIO_Mode_In_PU_No_IT);
//GPIO_ExternalPullUpConfig(GPIOA, GPIO_Pin_2 | GPIO_Pin_3, ENABLE);
 
 
USART_DeInit(USART1);
USART_Init(USART1, 9600, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, (USART_Mode_Rx));
USART_Cmd(USART1, ENABLE);

3 REPLIES 3
Cristian Gyorgy
Senior III

First thing I would do is to arrange some pull-up on the USART RX pin if no real TX port is connected to the pin. Or even better, connect the 2 pins, RX & TX, together for testing only (if you play with the ports, add a resistor in between to protect them in case you setup them both as outputs).

0xFA in USART_SR means overrun and framing errors, so this noise might be the problem.

And, are you doing it correctly, read first the USART_SR and than the USART_DR, to reset the status error flags?

WRost.1
Associate II

Thanks for your reply. I'm able to reset the error flags, but in the next operation they still reappear (tested in ST debugger). I tried the same code on a dev boards (with STM8L152K4) and it works flawlessly. I guess I was unlucky enough to buy two faulty chips.. (different suppliers though). I tried pulling up and down the pins via 20kOhm resistor. Still nothing.

WRost.1
Associate II

It appears that the problem with flags was indeed caused by faulty power supply. I realized I had some issues with a power cord. Almost all power pins (USB, Serial converters, STLinks, etc) where showing stable 5V and 3.3V. However the multi-meter showed 110AC on these pins as well. It's not a True RMS meter, but you can feel the wire ends were "live". Changing the power cord helped to solve the problem with flag errors, but then it took me some time to find out that pins RX and TX on USART1 shown by Stm8CubeMX where the alternate ones ! On chips STM8L151 and 152 primary UART RX and TX are on pins PC2 and PC3, not PA3 and PA2. Problem solved ! Thanks again for help !