Conflict between UART receive and transmit - RCREG seems to be loaded with TXREG con

Thread Starter

nikudnelog

Joined Feb 12, 2014
1
Hi,

I am writing code for UART communication between my pic18f2550 and a bluetooth module. I have implemented receive by interrupt and do a manual transmit in my main loop. I've noticed that when I am not transmitting the receive works well and I am able to properly read whatever is sent to me. However when I send data through the UART from my microcontroller it seems that whatever I write to TXREG is also written to RCREG. This has been stumping me for a while and I was wondering if anyone could shed some light on what might be causing this?

here is my uart set up:
void uart_Setup(void) // init UART module for 19200bps baud, start bit 1, stopbit 1, parity NONE
{
TRISCbits.TRISC7=1; //Make UART RX pin input
TRISCbits.TRISC6=0; //Make UART TX pin output

SPBRG = baud_rate_gen;
SPBRGH = baud_rate_gen>>8;

RCSTAbits.CREN=1; //1 = Enables receiver
RCSTAbits.SPEN=1; //1 = Serial port enabled (configures RX/DT and TX/CK pins as serial port pins)
BAUDCONbits.TXCKP=0; //not inverted
BAUDCONbits.BRG16=1;//1 = 16-bit Baud Rate Generator – SPBRGH and SPBRG

TXSTAbits.SYNC=0; //0 = Asynchronous mode
TXSTAbits.BRGH=1; //1 = High speed
TXSTAbits.TXEN=1; //1 = Transmit enabled

PIE1bits.TXIE=1;
PIE1bits.RCIE=1; //1 = Enables the EUSART receive interrupt

INTCONbits.PEIE=0; //Enable Peripheral Interrupt
PIR1bits.RCIF = 0;
PIR1bits.TXIF = 0;
}


here is my interrupt routine :

#pragma code isr=0x08
#pragma interrupt isr
void isr(void)
{
//Check if it is TMR0 Overflow ISR
if(INTCONbits.TMR0IE && INTCONbits.TMR0IF)
{
// TMR0 Overflow ISR
counter++; //Increment Over Flow Counter

if (counter==1000)
{
sample_flag=TRUE; //set sampling flag
counter=0;
}
TMR0L=131;//start timer from 131 always, 125 counts of timer equivalent to 1 ms (256-125=131)
//Clear Interrupt Flag
}
//
if (PIE1bits.RCIE && PIR1bits.RCIF)
{
USART_Status.val&=0xF2;
if(RCSTAbits.FERR)
{
USART_Status.FRAME_ERROR=1;
}
if(RCSTAbits.OERR)
{
USART_Status.OVERRUN_ERROR=1;
RCSTAbits.CREN=0;
RCSTAbits.CREN=1;
}
rec_byte=ReadUSART();
// if (rec_byte ==
LATCbits.LATC2=!LATCbits.LATC2;
dataToRead=TRUE;
}
//clear interrupt flags at end of ISR, RCIF automatically cleared when RCREG read
INTCONbits.TMR0IF=0;
}
#pragma code

Thanks in advance.
 
Top