cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f4: issues with rts/cts flow control with UART

abhiran
Associate
Posted on May 09, 2015 at 03:07

I am trying to get RTS/CTS working with UART3. I am using theMCBSTM32f400 (STM32F407VG) board and connected a serial cable on the UART3 with a PC.

If i am not using the flow control on the PC side, i can get the MCU to accept data. But the RTS line seems to be kept high. I am pretty sure i'm missing something trivial and it'll be great ifsomeone could help me out. Below is my code, which just tries to do basic read a single character from the PC

void
HAL_UART_MspInit(UART_HandleTypeDef *huart)
{
GPIO_InitTypeDef GPIO_InitStruct;
__USART3_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
}
UART_HandleTypeDef UartHandle;
int
main(
void
)
{ 
UartHandle.Instance = USART3;
UartHandle.Init.BaudRate = 115200;
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
UartHandle.Init.StopBits = UART_STOPBITS_1;
UartHandle.Init.Parity = UART_PARITY_NONE;
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS;
UartHandle.Init.Mode = UART_MODE_TX_RX;
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
if
(HAL_UART_Init(&UartHandle) != HAL_OK) {
/* Initialization Error */
GLCD_DrawString (0, 4*24, 
'' UART NOT initialized ''
);
} 
else
{
GLCD_DrawString (0, 4*24, 
'' UART initialized ''
);
}
uint8_t SEND_DATA[] = {0x01, 0x03, 0x0c, 0x00}; 
HAL_UART_Transmit(&UartHandle, (uint8_t *)SEND_DATA, 
sizeof
(SEND_DATA), 0xFFFF);

//trasmit is successful

unsigned 
char
receive_queue, transmit_queue;
while
(1) {
HAL_UART_Receive(&UartHandle, (uint8_t *)&receive_queue, 1, 0xFFFF);
 //receive is unsuccessful
sprintf
(ret_message, 
''USART msg# %hu %c''
, msg_num++, receive_queue);
GLCD_DrawString (0, 7*24, (
const
char
*)ret_message); 
}
}

Thanks for reading #stm32f4-serial-rts-dts-flowcontr
1 REPLY 1
Posted on May 09, 2015 at 16:38

Really can't help you with the HAL stuff, but as I've observed in other CTS/RTS threads it's important the think about the behaviour at a system level because you've presumably got a buffer that's deeper than the one byte the hardware has.

For you to hold off a transmitter you have to leave data in the holding register of the USART. Placing a debug view over the peripheral will read the DR, altering the behaviour.

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