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:SCI 如何将8位 uint16_t 打印到十六进制?

Guru**** 2027820 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1463369/tms320f280039c-how-to-sci-print-8-bit-uint16_t-to-hex

器件型号:TMS320F280039C

工具与软件:

我使用 CCS 启用 SCI、  

并制作一个小程序,尝试显示十六进制细节与我收到的其他接口,

例如 UART (或 SCI?) /SPI/I2c 或 CAN

因此、我的变量是 uint16_t

如何以十六进制而不是8位字符显示接收内容。

Fullscreen
1
2
3
4
5
6
7
8
9
10
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);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

如果 RDATA 为49、则 SCI_WRITE 将显示1

如果 RDATA 为31、SCI 写入将不显示任何内容(因为 49不是8位字符)

是否可以显示无符号 int 内容  

就像31=0x1F (我要显示的内容)

我尝试了 include stdio.h 和 snprintf 、但失败了。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 CK:

    您是否将此数据发送到计算机的 UART COM 端口? 这似乎与接收端的编码更相关、因为 MCU 将以按位方式发送数据。 您可以使用 https://docklight.de/ 更 方便地查看 UART 数据并更改编码

    此致、

    Peter

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    感谢您回复、

    看起来 SCI_WRITE 不能像 printf 或 snprint 那样轻松完成。

    我是否正确?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我只是解决了它,

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    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);
    }
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    然后调用 uint16tohex (RDATA、0或1)

    打印我收到的十六进制值。