This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430G2553: How to send an integer to UART, encoded as ASCI and ordered

Part Number: MSP430G2553


I want to send, for example, the integer 12345 to UART, and i did it like this:

int integer_to_send = 12345;

While (integer_to_send){

UCA0TXBUF = integer_to_send %10 + 48;

integer_to_send /= 10;

}

All this is inside USCIAB0TX_ISR routine.

So i got 54321 read in my computer's UART port.

How can i get the number in correct order?

Thank you very much for your time!

JM

  • Did you do the code on pencil and paper? If you check out K&R's itoa() routine, they use this algorithm and you always get the characters in reverse order, which is why they have to call reverse() at the end.

    You need to process the string before you send it, reverse it, and then send it out the UART.

  • First of all, thank you very much for your answer! 

    And noo lol i have my code on CCS, but you got the idea. In order to use this "reverse()" and "itoa()" functions, which library do i need to include? I tried to include stdlib.h but i get the following error: "unresolved symbol itoa, first referenced in ./main.obj"

    Thanks!

  • K&R is the Kernigham and Ritchie "C Programming Language", itoa() and reverse() are examples in the text. You can probably google for the source code. However, if you have some extra memory and stack space, you can include stdio.h and use snprintf().

**Attention** This is a public forum