Skip to main content
Visitor II
December 6, 2017
Solved

9-BIT UART TRANSMISSION STM32 cubemx hal driver

  • December 6, 2017
  • 1 reply
  • 2741 views
Posted on December 06, 2017 at 18:06

Hello,

I'm using STM32cubemx and I have created a project using UART in 9-bit configuration. The code is generated and I can find the 'HAL_UART_Transmit' function but the pData parameter is a 8-bit pointer:

HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)

pData should be a 16-bit parameter. I cannot understand how can I send a 9-bit data with this function. Is it a bug in STM32CubeMX?

Thanks

IBRA

    This topic has been closed for replies.
    Best answer by Tesla DeLorean
    Posted on December 06, 2017 at 22:43

    No, the byte array is just a universal solution. A 9-bit value is going to be spread over two bytes, low order bits in the first, or just use a 16-bit array and CAST it. The transfer count is in units, to send two 9-bit words, Size = 2

    uint16_t x[2] = (0x123,0x091};

    HAL_UART_Transmit(huart, (uint8_t *)x, 2, 1000);

    1 reply

    Graduate II
    December 6, 2017
    Posted on December 06, 2017 at 22:43

    No, the byte array is just a universal solution. A 9-bit value is going to be spread over two bytes, low order bits in the first, or just use a 16-bit array and CAST it. The transfer count is in units, to send two 9-bit words, Size = 2

    uint16_t x[2] = (0x123,0x091};

    HAL_UART_Transmit(huart, (uint8_t *)x, 2, 1000);

    Visitor II
    December 7, 2017
    Posted on December 07, 2017 at 11:39

    Clive,

    I test successfully this solution 

    Thank you for your help.

    IBRA