Hello. Does anyone have a configuration example for stm32f103 uart in half-duplex mode(switch TX/RX modes) using Low Level Library. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-02-08 8:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-02-10 6:19 AM
Apart from setting HDSEL bit, there is no much difference to full-duplex UART. Just keep in mind that the RX will always be active and TX will "take over" the pin when data is transmitted. RX will even receive the same data that TX is transmitting. Therefore the code has to ignore it or turn RX off during transmission. And of course the software has to manage concurrency to not try to receive and transmit simultaneously.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-02-10 8:05 AM
I find solution!
Initialization:
void MX_USART1_UART_Init(void)
{
LL_USART_InitTypeDef USART_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/* Peripheral clock enable */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB);
/**USART1 GPIO Configuration
PB6 ------> USART1_TX
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_6;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
LL_GPIO_AF_EnableRemap_USART1();
/* USART1 interrupt Init */
NVIC_SetPriority(USART1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 15, 0));
NVIC_EnableIRQ(USART1_IRQn);
USART_InitStruct.BaudRate = 115200;
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
USART_InitStruct.Parity = LL_USART_PARITY_NONE;
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
LL_USART_Init(USART1, &USART_InitStruct);
LL_USART_ConfigHalfDuplexMode(USART1);
LL_USART_Enable(USART1);
LL_USART_EnableHalfDuplex(USART1);
LL_USART_EnableIT_RXNE(USART1);
}
For select rx mode:
LL_USART_DisableDirectionTx(USART1);
LL_USART_EnableDirectionRx(USART1);
For select tx mode:
LL_USART_DisableDirectionRx(USART1);
LL_USART_EnableDirectionTx(USART1);
