Skip to main content
Explorer
May 17, 2024
Question

NUCLEO-STM32U083RC HAL_UART_Receive reads nothing

  • May 17, 2024
  • 1 reply
  • 854 views

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

 

    This topic has been closed for replies.

    1 reply

    husqAuthor
    Explorer
    May 17, 2024

    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_HalfDuplex_EnableTransmitter(uart_pin->uart); just before
     res = HAL_UART_Transmit(uart_pin->uart, (uint8_t *)cmd, cmd_len, 1000); 
     
    And I need to remove this:

     

     

    __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);

     

     

     
    and replace with this:

     

     

    HAL_HalfDuplex_EnableReceiver(uart_pin->uart);