PIC Specific RS232 IO

NEW! RCL-1 RS232 Level Converter in a DB9 backshell

There has been a lot of confusion on how the RX or TX pins should be set with regard to TRIS on the PICs with hardware USARTs, especially with regard to making them work in interrupt mode.

First, keep in mind that MPLAB [may] not (correctly or otherwise) simulate the USART Hardware.

Second, read the datasheets. They are tricky as hell and the details may be buried in there

From DS30292B-page 33 (the '873 datasheet section 3.3 PORTC and TRISC Registers):

When enabling peripheral functions, care should be taken in defining TRIS bits for each PORTC pin. Some peripherals override the TRIS bit to make a pin an output, while other peripherals override the TRIS bit to make a pin an input. Since the TRIS bit override is in effect while the peripheral is enabled, read-modify-write instructions (BSF, BCF, XORWF) with TRISC as destination should be avoided. The user should refer to the corresponding peripheral section for the correct TRIS bit settings.

From DS30292B-page 95 (the '873 datasheet section 10.0n on USART):

Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to be set in order to configure pins RC6/TX/CK and RC7/RX/DT as the Universal Synchronous Asynchro-nous Receiver Transmitter.

In Microchip lingo "set" means make the bit a 1 which would normally set the pin as an input. That isn't confusing with RX, but the requirement that the TRISC bit for the TX pin be set is rather counter-intuative.

Beyond the SPEN and TRIS setup, at least on some PIC's, the ANSEL bits can override the SPEN setting. So, even if SPEN is set, and TRIS is set for both RX and TX, if the associated pins are set as analog inputs, you may not receive any data.

PICUART.ZIP from http://redrival.com/mcgahee/  or http://mcgahee.freeservers.com is known to work and explains most of the common problems. The ZIP file only contains this ASM:  picuart.asm which is cached here since the mcgahee pages appear to have been lost.

the PICList.com SPBRG Calc (based on code from  Andy Kunz)

Automatic (asm macro) setting of the SPBRG, etc... values based on desired baud rate and processor speed from Olin Lathrop

.sti file generator for RS232 simulation in MPLAB

Calculating Parity

Detecting rising and falling edge events is a useful tool for "bit bang" or software only implementations of serial receive routines.

From the CHEAPIC tutorial:

Samples:

Also: RS232@, TTL to/from RS232@, TI Calc@ PIC C IO@ High speed serial IO pin sampleing

Books:

See also:

Books:

Questions:

Archive:

Code:

Comments:

Interested: