CTS/RTS flow control with esp32-s3

Hi, I need cts/rts serial communication between a module and my esp32, the module already has these pins defined so that’s not an issue but I don’t know which pins are cts and rts on the esp32-s3-wroom-1. In a diagram it is said that it is the pins 20 and 19 but they are also used for usb communication which I need so how do I make it work? And how to I use it in the ide?

Thanks

They are not for ANY Arduino. You will have to add that function to your code.

If not mistaken you can get away by shorting those pins at the module side.

Only if the module's buffer is big enough. Could be any module, I guess.

It’s a satellite communication module, I figured I’d connect it to a GPIO pin and if I need it in the future I’ll have it because this is pcb so I can’t change it however I want

It says to leave it open if not used

If you use hardware serial you should be able to initialize your serial port like this

#include <HardwareSerial.h>

HardwareSerial MySerial(1); // define a Serial for UART1

const int MySerialTX = 17;

const int MySerialRX = 18;

const int MySerialRTS = 19;

const int MySerialCTS = 20;

void setup() {

// put your setup code here, to run once:

MySerial.begin(11500, SERIAL_8N1, MySerialRX, MySerialTX, MySerialCTS, MySerialRTS);

MySerial.setHwFlowCtrlMode(UART_HW_FLOWCTRL_CTS_RTS);

}

and define the cts/rts pins to whichever pins you want

EDIT: looking at the header file a little closer it does not seem that "begin" accepts the cts/rts arguments also it looks like cts rts flow control is the default flow control mode so it may be unnecessary to pass that argument. Modifying the above a little I would try this.

MySerial.begin(115200,SERIAL_8N1);

MySerial.setPins(MySerialRX, MySerialTX, MySerialCTS,MySerialRTS);

MySerial.setHwFlowCtrlMode(HW_FLOWCTRL_CTS_RTS);

look at the hardware serial header file to get a better idea of what these functions are doing

@somelostguy I tested using the last three lines I posted and flow control seemed to be working fine, cts was set to pin 9 in my test , part of the setHwFlowCtrlMode function is the option to set the CTS threshold which defaults to 64 bytes. CTS is active low.

If you comment this line out

MySerial.setHwFlowCtrlMode(HW_FLOWCTRL_CTS_RTS);

flow control is disabled.

Thank you very much for the infos, I am not used to this UART standard , can you explain what you mean by CTS threshold?

@somelostguy the point of flow control is to prevent to much data/too many bytes being sent at once and overflowing the serial buffer.

RTS will allow data to be sent, if the data in the buffer exceeds the threshold RTS will signal the transmitter to stop sending. This happens at both ends so you have cts of the transmitter connected to rts of the receiver at both ends.

The default threshold is 64 bytes after that it will stop data being sent. The maximum is 128 bytes from what I can make out in the header file.

Oh I see so when the buffer is at 64 bytes it stops sending, I guess I find the buffer size in the module’s data sheet or is there an industry standard. Also, where can I modify the 64 bytes default? You mentioned the header file, where do I find that?

@somelostguy you can try trial and error but there is a chance you don't need flow control at all.

Depending on how much data there is and which way it's going . You can create your own very large serial FIFO buffer at the esp32 end that may do what you want, it all depends on what else is going on in your design. I would try that first. You might not need a seperate buffer either.

Search for the library HardwareSerial.h it should be on your PC.

One of the functions is setHwFlowCtrlMode which takes mode and threshold as parameters.

MySerial.setHwFlowCtrlMode(HW_FLOWCTRL_CTS_RTS, 100);

Do not modify the header file or it may cease to function.

Alright,What is the 100 you entered in your code line for?

@somelostguy I modified the default 64 byte threshold to 100 bytes

The 64 byte buffer is in the OTHER, receiving device. If your Arduino is sending, you really don't care what the buffer size is. The RTS/CTS handshake will take care of it.

I had an early dot matrix printer that only printed left to right. Then dropped CTS while the carriage returned to the left side. The CTS goes high to continue data transfer.

1 Like

Alright thanks a lot

Alright thank you very much for your help!