USART_InitTypeDef USART_InitStructure;
//enable bus clocks
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
//Set USART2 Tx (PA2) as AF push-pull
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//Set USART2 Rx (PA3) as input floating
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &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_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART2, &USART_InitStructure);
//Enable USART2
USART_Cmd(USART2, ENABLE);
}
/* Usart functions ——————————— ————————*/
/*******************************************************************************
* Function Name : SerialPutChar
* Description : Print a character on the HyperTerminal
* Input : – c: The character to be printed
* Output : None
* Return : None
*******************************************************************************/
void SerialPutChar(u8 c)
{
USART_SendData(USART2, c);
while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
}
int GetChar (void)
{
while (USARTGetFlagStatus(USART2, USARTFLAGRXNE) == RESET);
return USARTReceiveData(USART2);
}
/*******************************************************************************
* Function Name : SerialPutString
* Description : Print a string on the HyperTerminal
* Input : – s: The string to be printed
* Output : None
* Return : None
*******************************************************************************/
void SerialPutString(u8 s)
{
while (s != ‘stm32f103 freertos issue – usart2 false setting of RXNE flag.
Hi, I am using freertos demo for stm32f103x and using stm32f103vct6. Usart 1 is working fine but when i configured usart2 transmit function works fine but usart for receive function RXNE flags is setting falsely hence i am getting garbage data. This is not happening when i am programming two usarts without freertos in keil. Is there any configuration problem? Please help me to solve this issue.
I am posting my code too.
void USART2Init(void)
{
GPIOInitTypeDef GPIO_InitStructure;