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.

TMS320F280039C: how to SCI print 8-bit uint16_t to Hex?

Part Number: TMS320F280039C


Tool/software:

i use CCS to enable SCI, 

and make a small program, try to display HEX detail with what i received by other interface ,

like UART(or SCI ?) /SPI/I2c or can

so, my variable is uint16_t.

how do i display what is receive content in hex instead of 8-bit char.

uint16_t rData = 0;
uint16_t receivedChar;
unsigned char *msg;


 rData= 31; //want to show 1F instead of 31 

msg=(rData<<8);  //fail
msg=(rData)&0xFF;  //fail
SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 13);

if rdata is 49, the SCI_write will show 1

if rdata is 31, the SCI write will show nothing (because of  49 is not 8-bit character)

is there any way to show unsigned int content 

just like 31=0x1F(what i want to show)

i tried include stdio.h and  snprintf  but failed.

  • Hi CK,

    Are you sending this data over to a computer UART COM port? This seems more related to the encoding on the receiving side, as the MCU will send out the data in bitwise manner. You can use https://docklight.de/ to view the UART data and change the encoding more conveniently

    Regards,

    Peter

  • thank you replying,

    looks like SCI_write can't be done like printf or snprint easily.

    am i correct ?

  • i just solved it,

    static char hex_digits2[] = "0123456789ABCDEF";
    
    
    void uint16tohex(uint16_t indata, uint16_t tail){
    
        unsigned char* msg;
        msg=(unsigned char*)&hex_digits2[(indata >> 4) & 0x0F];
        SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 1);
        msg=(unsigned char*)&hex_digits2[indata & 0x0F];
        SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 1);
        if(tail==0){
            msg="-";
            SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 1);
        }else {
                msg="\r\n";
                SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 4);
        }
    }

    then call uint16tohex(rData,0 or 1)

    to print the hex what i receive .