cancel
Showing results for 
Search instead for 
Did you mean: 

Transfering data through Hal_Uart_Transmit is working fine but using printf the output printed is garbage.

ADIt
Associate II

MCU: Stm32f103c8t6

i want to use Printf in my Code

Currently i am using Hal_Uart_transmit to send data this Data when printed is correctly displayed

I wanted to add printf so i have added the following to my code

But when i use printf to send data the data printed is garbage

How can i fix this?

/****************************************************************************/

#ifdef __GNUC__

#define PUTCHAR_PROTOTYPE int __io_putchar(int ch11)

#else

#define PUTCHAR_PROTOTYPE int fputc(int ch11, FILE *f)

#endif

/****************************************************************************/

PUTCHAR_PROTOTYPE

{

   HAL_UART_Transmit(&huart1,(uint8_t*)ch11,1,0xffff);

   return ch11;

}

/****************************************************************************/

1 REPLY 1

>>How can i fix this?

Do the pointer casting properly

HAL_UART_Transmit(&huart1,(uint8_t*)&ch11,1,0xffff);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..