2024-11-05 08:15 PM - last edited on 2024-11-05 08:32 PM by Tesla DeLorean
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);
}
}
Solved! Go to Solution.
2024-11-11 10:36 AM
The MCU is stm8l152c6 but it only have USART1 as I said before.
2024-11-06 10:57 AM
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.
2024-11-06 01:15 PM
Board details and schematics would help.
Also dump out the UART2 registers, make sure baud rate, control and status are non-zero
2024-11-06 05:18 PM
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
2024-11-06 07:33 PM
Thankyou. But how can I watch the register of UART2? I can only find UART1 in view > peripherial registers
2024-11-08 10:23 AM
STM8L-DISCOVERY board only have USART1 because MCU is stm8l152c4.
2024-11-10 08:27 PM
Really? Maybe I used the wrong datasheet then
2024-11-11 10:36 AM
The MCU is stm8l152c6 but it only have USART1 as I said before.