I am trying to set UART2 on an ESP-WROOM-32 Dev Kit 1 to 460800 baud rate. After setting the baud rate with Serial2.updateBaudRate(460800), Serial2.baudRate() returns 470588. This causes errors between the two devices.
What is also interesting is it gets errors running in loopback, with TX and RX pins jumpered. Other speeds, like 230,400 and 512000, work fine in loopback.
Is there any way to get the baud rate closer to 460800?
Serial.begin() will set the UART clock to APB if the baud rate is above 250K and REF_TICK if below 250K.
Serial.updateBaudRate() does not change the clock from REF_TICK to APB if switching from a baud rate below 250K to above 250K. It also won't switch from APB to REF_TICK if going the other way.
The work-around is to either make sure Serial.begin() is called with a baud rate above 250K before calling Serial.setBaudRate, which will set APB clock, or Serial.end() and Serial.begin() instead of Serial.updateBaudRate().
My application requires the baud rate to be changed during program execution, not just startup.