2017-05-31 08:06 AM
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 #polling2017-05-31 08:09 AM
p.s. my wiring is fine (I can transmit data fine)
2017-05-31 09:59 AM
Hi, checking the code I see it right. I'm not sure about this:
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11; // USART3 RX
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
I generated an example code with CubeMX and get this:
GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);GPIO_InitStruct.Pin = GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);Maybe it could be useful for you:
2017-05-31 01:46 PM
Still doesn't seem to be receiving.
https://community.st.com/0D50X00009XkdezSAB
Make sure to fully initialize the GPIO structure, consider using GPIO_InitTypeDef GPIO_InitStruct = { 0 };
Check the GPIO configuration view debugger peripheral review.
Check the USART SR for other errors flagging.
Consider doing a simple loop back test, ie TX connects to RX, with no other external connectivity.
2017-05-31 06:08 PM
The F1 didn't have a pin level AF multiplexor, peripheral inputs were not 'AF', because inputs can be shared by everyone without interference, so the peripheral just taps into the buffer. ie GPIOx->IDR.x
Dozens of F1 USART SPL examples have been posted, I'm loathed to have to keep fixing broken wheels.
2017-05-31 09:55 PM
This is a STM32F1 USART3 PC10/PC11 example
https://community.st.com/0D70X000006SjYUSA0
Not sure which F1 specifically is being discussed here. I suppose there is a possible conflict with I2C2, which could be remapped off PB10/PB11. Other than that it is more probably failing for mundane reasons. For ST boards check solder-bridge options and whether pins in question reach headers or not, or connect to other peripheral hardware.
Replicate the issue on known working hardware/designs.