STM32F103RB UART comm. in half-duplex, single-wire mode
I am using two NUCLEO-F103RB boards for implementing and testing single-wire, half-duplex UART communication in polling mode. First I implemented and tested code based on the ‘UART_TwoBoards_ComPolling' example, which is included in the STM32F1 HAL library. Next I modified the code with the STM32CubeMX tool and set UART to Single-Wire (Half-Duplex), then re-created the code. See the screenshot. The idea is to only change what is required for switching from full-duplex to half-duplex, and leave the remaining code unchanged.
Note that STM32CubeMX configures full-duplex UART config with a Push-Pull output. The half-duplex output is Open Drain and requires a pull-up resistor.
Test setup:
* Two NUCLEO-F103RB boards.
* STM32CubeIDE Version 1.12.1.
* STM32CubeMX Version 6.8.1.
Known required changes from full-duplex to half-duplex (here UART1):
* One wire from UART1 PA9 on both NUCLEOs.
* Call in main(): HAL_UART_MspInit() changes pin PA9 to Open drain.
* CubeMX adds HAL_HalfDuplex_Init() to MX_USART1_UART_Init().
Question:
Is it required to call HAL_HalfDuplex_EnableTransmitter() and HAL_HalfDuplex_EnableReceiver() every time before sending/receiving packets? For example:
HAL_HalfDuplex_EnableTransmitter(&huart1);
HAL_UART_Transmit(&huart1, (uint8_t*)aTxBuffer, TXBUFFERSIZE, 5000);HAL_HalfDuplex_EnableReceiver(&huart1);
HAL_UART_Receive(&huart1, (uint8_t *)aRxBuffer, RXBUFFERSIZE, 5000);
