Skip to main content
ADIt
Associate II
July 24, 2018
Question

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

  • July 24, 2018
  • 1 reply
  • 601 views

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;

}

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

    This topic has been closed for replies.

    1 reply

    Tesla DeLorean
    Guru
    July 26, 2018

    >>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 (See Profile) Up vote any posts that you find helpful, it shows what's working..