Teensy 3.5 Hardware Serial pause sending (Software controlled CTS)

emiel.h

Member
Hi,
I'm dealing with a situation where it would be great to be able to control the "Clear to Send" (CTS) signal of Serial1 using software.
I see I can enable CTS flow control using Serial1.attachCts(pin) where pin can be 18 or 20, but what I'm looking for is something like Serial1.pause() and Serial1.resume(), where after pause() data that is sent to the serial port is just stored in the TX buffer without it actually being sent out yet.
I thought about simply wiring the CTS pin to another pin of the teensy and using a digitalwrite to pause the sending, but I'm already low on pins on this project and this seems kind of a waste of resources.

Any tips would be appreciated!
 
You could write some code to just disable the UART's transmit ready interrupt. Requires diving into the hardware registers, but as low-level hacks go, this one ought to be pretty simple.
 
Thanks, I got it to work in two ways.
I think the way you meant is by using the "Transmitter Interrupt or DMA Transfer Enable" (TIE) on "UART Control Register 2" (UARTx_C2).
Which I set by calling "UART0_C2 = C2_TX_INACTIVE" when wanting to pause and "UART0_C2 = C2_TX_ACTIVE" when wanting to resume.
The only problem is that "UART0_C2 = C2_TX_ACTIVE" is also called from within "serial1.c" every time something is written to the port, so I had to edit "serial1.c" to add a check that would skip this line if the port is paused.

Since preferably I would use a solution that doesn't need editing framework files, I kept on looking and found "Transmitter DMA Select" (TDMAS) on "UART Control Register 5 (UARTx_C5)".
Enabling this with "UART0_C5 = UART_C5_TDMAS" would also pause transmitting until resumed with "UART0_C5 = 0x00", without needing to edit anything else.
I don't know if temporarily generating DMA requests causes any unwanted side effects, at least I didn't notice any (yet).

I did notice though that if the TX buffer gets full (because of continuing to write to the serial port while paused), the Teensy freezes. So I either have to make sure the pauses are very short or keep checking the buffer and resume when it's almost full.
 
Back
Top