Skip to content

High speed RS232 for PIC

Addendum A

This addendum lists nuggets of information that hinted me about software implementation of hardware flow control. Doc on UART ([9], page 11)

CTS, Clear to Send, Pin 36: When low, this indicates that the MODEM or data set is ready to exchange data. The CTS signal is a MODEM status input whose conditions can be tested by the CPU reading bit 4 (CTS) of the MODEM Status Register. Bit 4 is the complement of the CTS signal. Bit 0 (DCTS) of the MODEM Status Register indicates whether the CTS input has changed state since the previous reading of the MODEM Status Register. CTS has no effect on the Transmitter.

MSDN, Requirements for the serial port in a Windows Thin Client device.

The serial port must meet flow-control requirements.
Hardware flow control that uses Request To Send (RTS) and Clear To Send (CTS) must be supported. Data Terminal Ready (DTR) and Data Set Ready (DSR) hardware flow control is optional. Software flow control must be supported, including the capability to support a clean stop in transmission of the current buffer. Supporting such a clean stop is more challenging for implementations that support large direct memory access (DMA) buffers than it is for implementations that use small serial ports that are based on the first in, first out (FIFO) method.
The serial port must support a maximum skid of 16 bytes; this is the maximum number of bytes that continue to be sent after the receiver requests a flow control off command.

During my experiments I found out that this number of bytes depends on UART transmit buffer length specified at port configuration. This parameter is not applied immediately but only after a reboot.
WinAPI function SetCommState and DCB structure (see [10])

If this member is TRUE, the CTS (clear-to-send) signal is monitored for output flow control. If this member is TRUE and CTS is turned off, output is suspended until CTS is sent again

Addendum B

Download Addendum B (95k)


Application sources (including MP LAB IDE project)


An example of using RS_bodySEND, RS_bodyRECEIVE macros.


A compiled and ready to load PIC application


The console terminal application with a set of tests


[1] 500kbps @ 4MHz; Regulus Berdin
[2] SPBRG Calc
[3] HiSerial.sys High speed serial port driver, André Rippstein
[4] PIC16F84A Data Sheet, Microchip
[5] PICmicro™ Mid-Range MCU Family Reference Manual; Microchip
[6] Serial HOWTO; David S.Lawyer original by Greg Hankins
[7] The RS232 Standard; Christopher E. Strangio
[8] Serial Programming Guide for POSIX Compliant Operating Systems; Michael Sweet
[9] PC16550D Universal Asynchronous Receiver/Transmitter with FIFOs; National Semiconductor
[10] Platform SDK: Device I/O, DCB; Microsoft
[11] Serial Communications in Win32; Allen Denver

Post a Comment

Your email is never published nor shared. Required fields are marked *