This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Sending integers over USART as ASCII characters, using HAL Libraries

Hello Everyone;

To send ASCII characters via USART I normally use Hal libraries and the function below;

HAL_UART_Transmit(&huart2, (uint_t*)"Hello", 6,10);

But, that one is for characters only. How can I send the value of an integer over USART as its ASCII characters ? Which functions and libraries should I use ?
. .
. For example (dummy program just to show my purpose):

int i = ADC read value; //Lets say i=15

printf(i); //value should be sent in ASCII characters, so 1 and then 5 should be sent in ASCII.
. .
.

Thanks for your help, Kind regards

Salih

Parents
  • hello mr pier , thanks for sharing the code

    i have already tried your code by using sprintf() and itoa() and the result is same.
    let me explain it, the number will split into buffer one by one.

    num = 49
    // sprinf() or itoa() method
    buffer [0] = 4
    buffer [1] = 9

    maybe what he meant was to send a buffer with one variable

    buffer [0] = 49

Reply
  • hello mr pier , thanks for sharing the code

    i have already tried your code by using sprintf() and itoa() and the result is same.
    let me explain it, the number will split into buffer one by one.

    num = 49
    // sprinf() or itoa() method
    buffer [0] = 4
    buffer [1] = 9

    maybe what he meant was to send a buffer with one variable

    buffer [0] = 49

Children