cancel
Showing results for 
Search instead for 
Did you mean: 

UART trames are not good

Samiot
Associate

Hello I am worcking an the P-NUCLEO-WB55 and I try to communicate with a other module with the LPUART. Seeing that I didn't have any responce to my commands, I use a scope to see the TX trame.

0690X00000D88KlQAJ.jpgThis is for example the trame of '<' (00111100) .

I used the command HAL_UART_Transmit(&hlpuart1, '<', 1, HAL_MAX_DELAY);

And there, the LPUART parameters:

static void MX_LPUART1_UART_Init(void)

{

 /* USER CODE BEGIN LPUART1_Init 0 */

 /* USER CODE END LPUART1_Init 0 */

 /* USER CODE BEGIN LPUART1_Init 1 */

 /* USER CODE END LPUART1_Init 1 */

 hlpuart1.Instance = LPUART1;

 hlpuart1.Init.BaudRate = 115200;

 hlpuart1.Init.WordLength = UART_WORDLENGTH_8B;

 hlpuart1.Init.StopBits = UART_STOPBITS_1;

 hlpuart1.Init.Parity = UART_PARITY_NONE;

 hlpuart1.Init.Mode = UART_MODE_TX_RX;

 hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;

 hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

 hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;

 hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

 hlpuart1.FifoMode = UART_FIFOMODE_DISABLE;

 if (HAL_UART_Init(&hlpuart1) != HAL_OK)

 {

  Error_Handler();

 }

 if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)

 {

  Error_Handler();

 }

 if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)

 {

  Error_Handler();

 }

 if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN LPUART1_Init 2 */

 /* USER CODE END LPUART1_Init 2 */

}

I tired to send many other caracters but I never see the good trame on the scope.

Any idea of what appened?

4 REPLIES 4
Danish1
Lead II

I think HAL_UART_Transmit needs a C string "<" not a single character '<'.

Hope this helps,

Danish

Well not really but thanks for the advice

You might have some other things wrong, but when you call

HAL_UART_Transmit(&hlpuart1, '<', 1, HAL_MAX_DELAY);

what the library-function is expecting is of the form

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

So you are giving '<' to the pointer-to-string variable pData.

What does the C compiler do under these circumstances?

It gets the ascii value of the character '<', in this case 0b00111100 or 0x3c

And passes that as the address for where to find the (in your case one-character) string.

And then the library-function then sends whatever happens to be in memory location 0x3c. Not the value 0x3c.

If instead you did

HAL_UART_Transmit(&hlpuart1, "<", 1, HAL_MAX_DELAY);

The C compiler would create a C string consisting of your character '<' and the string-terminator '\0' and store it in program memory. It would pass the address of that string to HAL_UART_Transmit(). And the library-function would look in the memory-location specified by the address, and retrieve the character '<' and send it.

@Danish​ is correct: you are sending over UART what's at 0x0000003c address, not the actual '<' character.