2024-05-17 03:51 AM
Hi all,
I have recently purchased a U083RC core and I am having problems reading data using USART1 under Single Wire (Half-duplex mode).
I am connecting to a sensor that only uses a single wire to send and receive data using a custom protocol running at 1200 bits/s. To send data I put the TX on the pin using these commands:
__HAL_UART_DISABLE(uart_pin->uart);
MODIFY_REG(uart_pin->uart->Instance->CR2, USART_CR2_SWAP, UART_ADVFEATURE_SWAP_DISABLE);
__HAL_UART_ENABLE(uart_pin->uart);
res = HAL_UART_Transmit(uart_pin->uart, (uint8_t *)cmd, cmd_len, 1000);
And this works as expected
The problem comes when I want to read the sensor data. In this case I change the pin to RX using this code
__HAL_UART_DISABLE(uart_pin->uart);
MODIFY_REG(uart_pin->uart->Instance->CR2, USART_CR2_SWAP, UART_ADVFEATURE_SWAP_ENABLE);
__HAL_UART_ENABLE(uart_pin->uart);
But when I use the method HAL_UART_Receive(uart_pin->uart, &c, 1, 110); it always returns HAL_TIMEOUT.
I don't know what's going on because on a STM32L0 this code works fine, it's when I switch to the STM32U0 that the module doesn't read anything.
Any idea what could be going on?
Thanks
2024-05-17 07:57 AM - edited 2024-05-17 07:59 AM
Ok, I think I fixed the problem, but I don't understand why on the stm32l0 it works with the one I wrote first in the post, but on the stm32u0 it works differently.
To receive data on the new board, I need to implement the command
__HAL_UART_DISABLE(uart_pin->uart);
MODIFY_REG(uart_pin->uart->Instance->CR2, USART_CR2_SWAP, UART_ADVFEATURE_SWAP_ENABLE);
__HAL_UART_ENABLE(uart_pin->uart);
HAL_HalfDuplex_EnableReceiver(uart_pin->uart);