Question
USART Not Receiving Data (Polling)
Posted on May 31, 2017 at 17:06
Hi guys,
So I'm using an STM32F1 and am trying to send data from a serial terminal (RealTerm) to USART3 via a FTDI USB-UART converter cable. I have written code to poll for data on the RX line but for some reason my USART_FLAG_RXNE is not being set when I send data from the terminal. Here is my code (no errors):
void USART3_Config(void)
{ GPIO_InitTypeDef GPIO_InitStruct; USART_InitTypeDef USART_InitStruct; // Clock Config RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);// GPIO Config
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10; // USART3 TX GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStruct); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11; // USART3 RX GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStruct); // USART Struct Config USART_InitStruct.USART_BaudRate = 9600; USART_InitStruct.USART_StopBits = USART_StopBits_1; USART_InitStruct.USART_WordLength = USART_WordLength_8b; USART_InitStruct.USART_Parity = USART_Parity_No; USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART3, &USART_InitStruct); USART_Cmd(USART3, ENABLE); }int main(void)
{ RCC_Configuration(); ... USART3_Config(); ... while(1) { ... State = POLLING_TEST; switch (State) { ... case POLLING_TEST: while(USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == RESET); sprintf(data, 'dummy'); // breakpoint here break;Can anyone help me with this? Have I done something wrong?
Cheers,
Tony
#stm32f1 #usart #rx #polling