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])

fOutxCtsFlow
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)

SRC

Application sources (including MP LAB IDE project)

RS.ASM

An example of using RS_bodySEND, RS_bodyRECEIVE macros.

UTRS.HEX

A compiled and ready to load PIC application

TESTS

The console terminal application with a set of tests

References

[1] 500kbps @ 4MHz; Regulus Berdin
http://www.piclist.com/techref/microchip/rs232at500kbps.htm
[2] SPBRG Calc
http://www.piclist.com/techref/microchip/spbrgcalc.asp?fOSCILLATOR=4&fErr=20
[3] HiSerial.sys High speed serial port driver, André Rippstein
http://www.rippstein.net/HiSerialEN.htm
[4] PIC16F84A Data Sheet, Microchip
[5] PICmicro™ Mid-Range MCU Family Reference Manual; Microchip
[6] Serial HOWTO; David S.Lawyer original by Greg Hankins
http://www.ibiblio.org/mdw/HOWTO/Serial-HOWTO-3.html
[7] The RS232 Standard; Christopher E. Strangio
http://www.camiresearch.com/Data_Com_Basics/RS232_standard.html
[8] Serial Programming Guide for POSIX Compliant Operating Systems; Michael Sweet
http://www.rebel.net/~mad/serialtutor/rs232.html
[9] PC16550D Universal Asynchronous Receiver/Transmitter with FIFOs; National Semiconductor
https://www.ourpcb.com/what-happened-to-national-com.html
[10] Platform SDK: Device I/O, DCB; Microsoft
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/dcb_str.asp
[11] Serial Communications in Win32; Allen Denver

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp

Post a Comment

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

*