Send Data With Usart STM32


I have to send data using the usart2 in my nucleo64 stm32f446re board.
The type of data I have to send is float but until now I always send uint8_t using this code;

   char msg[1];

   for(int i = 0 ; i < Nbit*Sb ; i++)
       sprintf(msg, "%d ", sigTX[i]);
       HAL_UART_Transmit(&huart2, (uint8_t *)msg, strlen(msg), HAL_MAX_DELAY);

Because sigTX is a pointer to float data in an array, I try to change the code using msg[4], in order to have 32 bit, and in HAL_UART_transmit I put (int32 *)msg, in order to send data with sign.
This doesn't work, so can someone say to me where is the mistake?
Sorry, but I'm new in embedded world.

Best Answer

While the other answers focus on sending one float at a time, and you want to send the whole array of floats anyway, it can be sent with a single call.

Assuming sigTX is a pointer, and you want to send Nbit*Sb amount of floats:

HAL_UART_Transmit(&huart2, (uint8_t *)sigTX, sizeof(float)*Nbit*Sb, HAL_MAX_DELAY);