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
SPBRG=5;
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;
setupUSART();
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
while(1)
{
if(PIR1bits.RCIF)
{
buffer = RCREG; //Store received data
//Display the received char to the LCD
LCDWriteCommand(1);
LCDWriteASCII(buffer);
}
}
}
And the configurations bits :
// CONFIG
#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.