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.

TM4C123GH6PM: NEGATIVE NUMBER IN UART COMMUNICATION

Part Number: TM4C123GH6PM

Hello All,

Iam using a TM4C123 MCU & Iam trying to send negative numbers via UART. My data is a digital filter output which has both negative and positive numbers . When I use UART0 and send data using 

UARTprintf("%d\n", finaldata) The data is sent to PC without any issues as long as Iam doing Serial readline (receiver keeps receiving data until newline char is received) on the PC side.

My data is like  in the range of (500 to -500)

But if I break the data in MSB & LSB  and send using UART2

UARTCharPutNonBlocking(UART2_BASE,(finaldata & 0x00FF))


UARTCharPutNonBlocking(UART2_BASE,((finaldata & 0xFF00) >>8))

Then the negative numbers are NOT RECEIVED at the Receiver end. 

Kindly help in resolving the issue.

  • Hi,

      Please note that the UART takes a 8-bit 'character' input. You cannot do what you are doing with the UARTCharPutNonBlocking(UART2_BASE,(finaldata & 0x00FF)). Suppose your finaldata is -450 and this is going to be a 4 characters (e.g. "-", "4", "5", "0"). You will need to convert the -450 into four individual ASCII characters before calling the UARTCharPutNonBlocking. 

      Why don't you configure UARTsdioConfig for UART2 so you can use UARTprintf.

    //
    // Initialize the UART for console I/O.
    //
    UARTStdioConfig(2, 115200, 16000000); // Configure UART2