cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103RCT6 UART5 not working

TNguy.1482
Associate

Hi all,

I'm using uart5 of stm32f03rct6 with Std lib but it's not working. However, when i use cubemx with HAL, It works perfectly. Anyone can help me check my code :(

USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
 
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5 , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
 
 
 USART_InitStructure.USART_BaudRate = 115200;
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
    USART_InitStructure.USART_Parity = USART_Parity_No;
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(UART5, &USART_InitStructure);
	  /* Enable ZM_UART Receive interrupts */
USART_ClearFlag(UART5,USART_IT_RXNE);
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
		/* Enable ZM_UART Receive interrupts */
USART_Cmd(UART5, ENABLE);
 
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
			

1 REPLY 1

Not working? Are you sure it is the code here that's "not working"?

Can you output in a loop? Check bit rate with a scope?

Try without the interrupts.

Can you poll the UART? Any errors/status flagging?

How about a simple echo-back?

Clear the data structures.

Check the RCC, GPIO and UART registers in the debugger.

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