I am trying to use the USART to make two PIC16F877A microcontrollers communicate. When I look with an oscilloscope at the output on the TX pin of the MCU that's transmitting , I see the normal NRZ waveform, with the correct baud rate and voltage levels. However, as soon as I connect the TX pin to the RX pin of the other MCU, the voltage drops to almost zero, exactly as if there was a pull-down resistor in the chip. When I remove the MCU from its socket, I measure an infinite resistance between the RX pin on the board and the ground, so the pull-down must be happening in the MCU and not elsewhere in the circuit. I assume I'm not setting up the USART properly, but I can't find anything in the datasheet that explains this behavior.

Here is the receiving PIC's code :

#include <stdint.h>
#include <xc.h>
#include "config.h"  //Configuration bits

uint8_t buffer;

void setupUSART(void)
    TXSTAbits.BRGH=0; //Set baud rate generator to 9600bps for 3.6864MHz xtal

    TXSTAbits.SYNC=0; //Async mode
    RCSTAbits.SPEN = 1; //Enable USART on pins RC6&RC7

    RCSTAbits.CREN = 1; //Enable continuous receive   

void main(void)
    TRISB = 0; //output port, used to write to LCD
    TRISC = 0;
    PORTC = 0;

    LCDWriteCommand(0b00111000); //Function set : 8bits interface, 2lines display, 5*8 font
    LCDWriteCommand(0b00000110); //Entry mode set : increment cursor, no display shift
    LCDWriteCommand(0b00001100); //Display control : display on, cursor off, cursor blink off
    LCDWriteCommand(0b00000001); //Clear display & home cursor

            buffer = RCREG; //Store received data

            //Display the received char to the LCD



And the configurations bits :

#pragma config FOSC = XT        // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

Thank you.


1 Answer 1


Did you read the datasheet section on the UART?

enter image description here

  • 1
    \$\begingroup\$ Ah, thank you! I don't know how I missed this part; I must have read that chapter of the datasheet a half-dozen times while trying to make the UART work. It also explains why I only have the problem now : I switched from the PICF77 to the PIC16F877A, and the 16F77 doesn't care about the TRIS register when setting up the UART. \$\endgroup\$
    – hlouis
    Aug 5, 2015 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.