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);
	}
}

 

 

0 REPLIES 0