cancel
Showing results for 
Search instead for 
Did you mean: 

stm8l uart1 works but uart2 doesn't work

SSin.1
Associate II

Dear all,

I'm now using stm8l15x to send 8 bits data with both UART1 & UART2. UART1 works fine & can communicate with my PC for both TX & RX via both polling & interrupt mode. But UART2 doesn't work. It doesn't output any waveform (always 1) with or without connecting to a PC. And the TC flag never set, where it set in UART1 after TX.

I tried to use nop() loop to replace reading flag status. It still output nothing. nop() loop works fine for toggling GPIO

I don't think it's a hardware problem as flag status should not be affected by hardware. Are there any other methods for me to debug?

Attached please find some of my code

 

void main(void)
{	
	// LED
	GPIO_Init(GPIOD, GPIO_Pin_5 | GPIO_Pin_4, GPIO_Mode_Out_PP_Low_Slow);
	// UART
	CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);
	CLK_PeripheralClockConfig(CLK_Peripheral_USART2, ENABLE);
	GPIO_ExternalPullUpConfig(GPIOC, GPIO_Pin_2, ENABLE);
	GPIO_ExternalPullUpConfig(GPIOE, GPIO_Pin_3, ENABLE);
	GPIO_Init(GPIOC, GPIO_Pin_3, GPIO_Mode_Out_PP_High_Fast);
	GPIO_Init(GPIOE, GPIO_Pin_4, GPIO_Mode_Out_PP_High_Fast);
	USART_Init(USART1, 9600, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, USART_Mode_Rx|USART_Mode_Tx);
	USART_Init(USART2, 9600, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, USART_Mode_Rx|USART_Mode_Tx);
	USART_Cmd(USART1, ENABLE);
	USART_Cmd(USART2, ENABLE);
	
	while(1) {
		GPIO_ToggleBits(GPIOD, GPIO_Pin_4);
		USART_SendData8(USART1, '1');
		while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
		GPIO_ToggleBits(GPIOD, GPIO_Pin_5);
		USART_SendData8(USART2, '2');
		main_delay_us_polling(50000);
		//while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
	}
}

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

The MCU is stm8l152c6 but it only have USART1 as I said before.

View solution in original post

7 REPLIES 7
AA1
Senior III

I don't know which board you are using. On some boards USART2 is used as VCP and is connected to ST-LINK, and by default is not available.

Board details and schematics would help.

Also dump out the UART2 registers, make sure baud rate, control and status are non-zero

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
SSin.1
Associate II

Thanks for your reply. Sorry for missing hardware info

The board I am using is STM8L-DISCOVERY development board (Ofcourse I removed the LCD display). Hust have a quick look on it's schematic. I can't find any connection between uart2 (PE3 & PE4) with on board ST Link

Thankyou. But how can I watch the register of UART2? I can only find UART1 in view > peripherial registers

SSin1_1-1730950378980.png

 

STM8L-DISCOVERY board only have USART1 because MCU is stm8l152c4.

 

SSin.1
Associate II

Really? Maybe I used the wrong datasheet then

SSin1_0-1731299252225.png

 

The MCU is stm8l152c6 but it only have USART1 as I said before.