PIC Specific RS232

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

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

Second, read the datasheets.

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.

The bottom line, don't do read-modify-write operations on a TRIS register that is controlling pins with another active peripheral, such as the TRISC register when using the UART or CCP.

Finally, PICUART.ZIP from http://redrival.com/mcgahee/  or http://mcgahee.freeservers.com is known to work and explains most of the common problems.

Samples:

rs232@ TTL to/from RS232@ TI Calc@ PIC C IO@

See also:

cover "Serial PIC'n : PIC Microcontroller Serial Communications" by David Benson

Comments:

Code: