Description
Hardware:
Board: DOIT ESP32 DEVKIT V1
Core Installation/update date: 10/Nov/2017
IDE name: Arduino IDE
Flash Frequency: 80Mhz
Upload Speed: 921600
Description:
HardwareSerial device sends some incorrect characters after changing baudrate.
Serial2 is started at 115200 baud. Write works fine.
Serial2 has baud rate changed to 9600 with a second .begin()
Some .write() characters are then incorrect. It appears to work correctly if that first character is not sent at 115200.
If I send more than 4 characters in sequence like this, it seems to always be some characters at the beginning or end which are affected.
Character sequence should be:
[at 115200]
0x55
[at 9600]
0x01 0x02 0x03 0x04
0x01 0x02 0x03 0x04
etc...
Instead it is:
[at 115200]
0x55
[at 9600]
0xf3 0x03 0x04 0x91
0x02 0x03 0x04 0x45
0x4a 0x03 0x04 0x11
0x73 0x03 0x04 0x1e
etc...finally repeating:
0x02 0x03 0x04 0x01
etc...
Sketch:
#include <Arduino.h>
HardwareSerial SerialGPS(2);
void setup() {
Serial.begin(115200); // program/debug port
Serial.println("Starting...");
// start at 115200
SerialGPS.begin(115200, SERIAL_8N1, 15, 5);
SerialGPS.write(0x55);
delay(1000);
SerialGPS.end(); // < doesn't change anything if not present
// switch to 9600
SerialGPS.begin(9600, SERIAL_8N1, 15, 5);
}
void loop() {
SerialGPS.write(0x01);
SerialGPS.write(0x02);
SerialGPS.write(0x03);
SerialGPS.write(0x04);
delay(1000);
}