Electronic – arduino – Implementing UART flow control in microcontroller

arduinoflow controluart

I'm communicating data from my microcontroller (Teensy) to my Bluetooth module (nRFx) which is also a microcontroller that I can program. I use UART to communicate the data I want to send over Bluetooth from the Teensy to the nRF, but nRF sends Bluetooth data slower than the transmission of data from the Teensy (UART speed faster than Bluetooth speed). Because of this I need to implement hardware flow control so the nRF buffer doesn't overflow.

I have RTS and CTS pins on both microcontrollers and I'm currently writing in Arduino (this might change to nordic's SDK for the nRF). My question is, can I just connect the RTS and CTS pins and "activate" the flow control somehow and it just works? Or do I need to program them my self?

Teensy

nRF

Best Answer

If the bluetooth module supports control flow, you should just enable it and then it will work automatically on the module's side. If not, tough luck - you can't use flow control.

On the micrcontroller side, you must handle RTS/CTS manually with GPIO (or perhaps some magic UART library will do it for you).

EDIT: Apparently your particular MCU Kinetis K20 supports flow control as part of the UART hardware, so you can have the MCU do it automatically in this case.

Another alternative might be to have the module echo each character sent back to the MCU. This makes everything slower but can perhaps be used as poor man's flow control.