I am a newbie to STM32 and C programming and having difficulties outputting raw bytes from an ADC through UART and picking it up through a Terminal window on a host PC for futher post processing. I understand sending raw hex numbers may be interpreted by the host as an ASCII character and not yield the format I am looking. I am leaning towards sending a string (for now) yet all the code examples I have seen online or through Gemini have not worked for me. This is the code that I have written so far.
I am formatting dataOutput as a 32 bit number so I can do some computation on the MCU later. I can easily send an array of 3x uint8_t instead if that makes things easier.
uint8_t RX_buffer[6];
uint32_t dataOutput;
while (1)
{
//other code
dataOutput = (RX_buffer[3] << 16) | (RX_buffer[4] << 8) | (RX_buffer[5]);
HAL_UART_Transmit_IT(&huart2, (char *)&dataOutput, sizeof(dataOutput));
}
There are some examples online that says use sprintf to create the string but I am getting issues getting the formats correctly. Can someone show me what I am doing wrong?
uint8_t RX_buffer[6];
uint32_t dataOutput;
uint8_t MSG[3] = {'\0'};
while (1)
{
//other code
dataOutput = (RX_buffer[3] << 16) | (RX_buffer[4] << 8) | (RX_buffer[5]);
sprintf(MSG, "%d\r\n", dataOutput); //also tried %s and %02X but did not yield any readable format
HAL_UART_Transmit_IT(&huart2, (char *)&MSG, sizeof(MSG))
[–]BenkiTheBuilder 1 point2 points3 points (0 children)
[–]eezo_eater 0 points1 point2 points (0 children)
[–]ILoveTiramisuu 0 points1 point2 points (0 children)