Arduino 通过 XBee 发送十六进制值

Arduino send HEX values via XBee

我正在尝试通过 XBee 将 HEX 值从 Arduino 发送到 digi 的 Xbee 程序 XCTU。但是我有一些字节无法发送的问题

我无法发送的字节列表: 0x11 0x13 0x7D 0x7E 0x81 0xEC 0xEE

如果我使用任何其他字节,我可以在 XCTU 控制台中看到它 window 并且我会收到对 Arduino 的回复

我已经在两个 Xbee 上启用了 API 模式 (AP=1)。我正在使用从 Arduino 网站链接的 XBee 库 (https://www.arduino.cc/en/Reference/Libraries) 我的代码如下所示:

#define XBEE_RX_PIN 8
#define XBEE_TX_PIN 9
SoftwareSerial xbeeSerial(XBEE_RX_PIN, XBEE_TX_PIN);

void setup()
{
    Serial.begin(9600);
    xbeeSerial.begin(9600);
    xbee.begin(xbeeSerial);

}

void loop()
{
    Serial.println("Send next 255 msg:");
    uint8_t testMsg[1] = { 0x0 };
    for (uint8_t i = 0; i <= 0xFF; i++)
    {
        test2[0] = i;
        Tx16Request testTx = Tx16Request(0xFFFF, testMsg, sizeof(testMsg));

        xbee.send(testTx);
        Serial.print("Message send: ");
        Serial.println(test2[0], HEX);

        if (xbee.readPacket(5000)) {      
            Serial.println("SUCCESS");
        }
        else if (xbee.getResponse().isError()) {
            Serial.println("isError");
        }
        else {
            Serial.println("No Response");
        }
    }
    Serial.println("");
    delay(3000);
}


当 AP=1 时,您不能发送一些特殊字节,例如:

  • 0x7E(帧开始)
  • 0x11/0x13(XOn XOff)
  • ...

如 XBee 文档(XBee®XBee-PRO® ZB RF 模块手册 90000976_W.pdf,起始页 112)中所述,您应该使用 AP=2 模式,该模式允许您通过转义来传输这些特殊字节他们:

Escape characters.
When sending or receiving a UART data frame, specific data values must be escaped (flagged) so they do not interfere with the data frame sequencing.
To escape an interfering data byte, insert 0x7D and follow it with the byte to be escaped XOR’d with 0x20.
Note that, if not escaped, 0x11 and 0x13 is sent as is.

Data bytes that need to be escaped:
- 0x7E – Frame Delimiter
- 0x7D – Escape
- 0x11 – XON
- 0x13 – XOFF

Example - Raw UART Data Frame (before escaping interfering bytes):
- 0x7E 0x00 0x02 0x23 0x11 0xCB
0x11 needs to be escaped which results in the following frame:
- 0x7E 0x00 0x02 0x23 0x7D 0x31 0xCB
Note In the above example, the length of the raw data (excluding the checksum) is 0x0002 and the checksum of the non-escaped data (excluding frame delimiter and length) is calculated as:
0xFF - (0x23 + 0x11) = (0xFF - 0x34) = 0xCB.

希望对您有所帮助