#define RXD2 16 //define Serial2 pins. These are the standard pins for UART2
#define TXD2 17
#include "driver/uart.h" //Need this for hardware or software handshaking
Serial.begin(115200); //Standard serial port - USB via UART-USB chip.
//Very handy for monitoring activity
Serial2.begin(BaudRate, SERIAL_8N1, RXD2, TXD2); //Do this prior to the following
//ref: https://github.com/espressif/arduino-esp32/issues/6185 <--- reference
//Setting hardware flow control must go after the Serial.begin statement
//add #include "driver/uart.h" at program start
uart_set_pin(UART_NUM_2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, 22, 21);
//I used the I2C pins for hardware handshaking as I had connectors on the board for them.
//uart_set_hw_flow_ctrl(UART_NUM_2, UART_HW_FLOWCTRL_RTS, 64);
//^^^ for hardware RTS/CTS handshaking. 64 is buffer size.
uart_set_sw_flow_ctrl(UART_NUM_2, true, 64, 96);
//^^^ for Xon/Xoff software handshaking. 64 and 96 are points in the buffer to say
// enough, stop sending, ok, send more. See the reference about.