Is this the right way to implement RTS flow control on a xenon?
uint8_t weight[3][8] = {
{ 0x0A, 0x03, 0x00, 0x06, 0x00, 0x05, 0x64, 0xB3 },
{ 0x0B, 0x03, 0x00, 0x06, 0x00, 0x05, 0x65, 0x62 }, // for weighing
{ 0x0C, 0x03, 0x00, 0x06, 0x00, 0x05, 0x64, 0xD5 }
};
void setup() {
pinMode(D2, OUTPUT); // tried with and without this
Serial1.begin(9600, SERIAL_DATA_BITS_8 | SERIAL_STOP_BITS_1 | SERIAL_PARITY_NO | SERIAL_FLOW_CONTROL_RTS);
}
void loop() {
delay(1000);
for (int i=0; i<3; i++) {
Serial1.write(weight[i], 8);
delay(100);
while (Serial1.available()) {
Serial.print(Serial1.read(), HEX);
Serial.print(" ");
delay(10);
}
}
}
I cannot get the RTS on pin D2 to go high.
This works though and receive good responce:
uint8_t weight[3][8] = {
{ 0x0A, 0x03, 0x00, 0x06, 0x00, 0x05, 0x64, 0xB3 },
{ 0x0B, 0x03, 0x00, 0x06, 0x00, 0x05, 0x65, 0x62 }, // for weighing
{ 0x0C, 0x03, 0x00, 0x06, 0x00, 0x05, 0x64, 0xD5 }
};
void setup() {
pinMode(D2, OUTPUT);
Serial1.begin(9600, SERIAL_DATA_BITS_8 | SERIAL_STOP_BITS_1 | SERIAL_PARITY_NO);
}
void loop() {
delay(1000);
for (int i=0; i<3; i++) {
pinSetFast (D2); // HIGH
Serial1.write(weight[i], 8);
delay(10); // without this delay RTS will go low before Serial1 has finished writing
pinResetFast(D2); // LOW
delay(100);
while (Serial1.available()) {
Serial.print(Serial1.read(), HEX);
Serial.print(" ");
delay(10);
}
}
}
The docs say:
On mesh devices, flow control is available on Serial1 D3(CTS) and D2(RTS). On the Xenon flow control is also available on Serial2 D6(CTS) and D8(RTS).
SERIAL_FLOW_CONTROL_NONE - no flow control
SERIAL_FLOW_CONTROL_RTS - RTS flow control
SERIAL_FLOW_CONTROL_CTS - CTS flow control
SERIAL_FLOW_CONTROL_RTS_CTS - RTS/CTS flow control