Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Unable to echo RX data on PC via Realterm using PIC18F4520 UART

Status
Not open for further replies.

PIC.man

New Member
Hi,

I'm fairly new to UART and i'm trying to do something fairly simple (or so i've been told) with a PIC18F4520 microcontroller.

I'm trying to send data via terminal software to the PIC and receive it back. I have no problems in getting data when its hardcoded onto the PIC (stored in variables and received through TXREG of the PIC) but when I try and send anything from the PC to the RX register RCREG I keep getting 0's and data never changes. I'm using a receive interrupt to do this. My code is shown below -

#include <delays.h>
#include <p18f4520.h>
#include <usart.h>

/****** Bit Variable Assignment *********/
#define LED_CHECK PORTBbits.RB2
void high_isr(void);
unsigned char receivedata;


/** Declare Interrupt Vector Sections ****************************/
#pragma code high_vector=0x08
void interrupt_at_high_vector(void)
{
_asm goto high_isr _endasm
}

/******************* MAIN ******************/
#pragma code
void main(void) {


//Enable TX register and set TX pins for transmission
TXSTA = 0b00100000; // Make Tx pin of PORTC and output pin
RCSTA = 0b10010000; // Enable the serial port of PIC18


//Set interrupt pins for USART
RCONbits.IPEN = 1; // Enable interrupt priorities
INTCONbits.GIEH = 1; // All GLOBAL interrupts are high priority
PIE1bits.RCIE = 1; // Enable Receive interrupt
IPR1bits.RCIP = 1; // Make the UART Rx interrupt a high priority interrupt

//Configure the USART
OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 51);


/***************** Main LOOP 2 - USART***********************/
LED_CHECK = 1;


while(1)
{
TXREG = receivedata;
while(!TXSTAbits.TRMT);
}

CloseUSART();

}

#pragma interrupt high_isr
void high_isr(void)
{
if(PIR1bits.RCIF)
{
receivedata = RCREG;
if (RCSTAbits.OERR==1) //check for overflow error
{ RCSTAbits.CREN=0; //if error present, reset OERR so that reception can continue
RCSTAbits.CREN=1;
LED_ERR = 1;
Delay10KTCYx(200);
LED_ERR = 0; }

else if(RCSTAbits.FERR == 1){ //Handling Framing error
char dummy, dummy1, dummy2;
TXSTAbits.TXEN=0;
TXSTAbits.TXEN=1;
dummy = RCREG;
dummy1 = RCREG;
dummy2 = RCREG;
LED_ERR = 1;
Delay10KTCYx(200);
LED_ERR = 0; }

PIR1bits.RCIF = 0;
TXSTAbits.TXEN=1;
}
}

I've checked baud rates on both sides and there seems to be no timing issue. I also have a Max232 circuit in between for the voltage level conversion.

As of now I have no idea whats wrong so any help would be greatly appreciated.

Thank you!
 
Last edited:
Hi,

I'm fairly new to UART and i'm trying to do something fairly simple (or so i've been told) with a PIC18F4520 microcontroller.

I'm trying to send data via terminal software to the PIC and receive it back. I have no problems in getting data when its hardcoded onto the PIC (stored in variables and received through TXREG of the PIC) but when I try and send anything from the PC to the RX register RCREG I keep getting 0's and data never changes. I'm using a receive interrupt to do this. My code is shown below -

#include <delays.h>
#include <p18f4520.h>
#include <usart.h>

/****** Bit Variable Assignment *********/
#define LED_CHECK PORTBbits.RB2
void high_isr(void);
unsigned char receivedata;


/** Declare Interrupt Vector Sections ****************************/
#pragma code high_vector=0x08
void interrupt_at_high_vector(void)
{
_asm goto high_isr _endasm
}

/******************* MAIN ******************/
#pragma code
void main(void) {


//Enable TX register and set TX pins for transmission
TXSTA = 0b00100000; // Make Tx pin of PORTC and output pin
RCSTA = 0b10010000; // Enable the serial port of PIC18


//Set interrupt pins for USART
RCONbits.IPEN = 1; // Enable interrupt priorities
INTCONbits.GIEH = 1; // All GLOBAL interrupts are high priority
PIE1bits.RCIE = 1; // Enable Receive interrupt
IPR1bits.RCIP = 1; // Make the UART Rx interrupt a high priority interrupt

//Configure the USART
OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 51);


/***************** Main LOOP 2 - USART***********************/
LED_CHECK = 1;


while(1)
{
TXREG = receivedata;
while(!TXSTAbits.TRMT);
}

CloseUSART();

}

#pragma interrupt high_isr
void high_isr(void)
{
if(PIR1bits.RCIF)
{
receivedata = RCREG;
if (RCSTAbits.OERR==1) //check for overflow error
{ RCSTAbits.CREN=0; //if error present, reset OERR so that reception can continue
RCSTAbits.CREN=1;
LED_ERR = 1;
Delay10KTCYx(200);
LED_ERR = 0; }

else if(RCSTAbits.FERR == 1){ //Handling Framing error
char dummy, dummy1, dummy2;
TXSTAbits.TXEN=0;
TXSTAbits.TXEN=1;
dummy = RCREG;
dummy1 = RCREG;
dummy2 = RCREG;
LED_ERR = 1;
Delay10KTCYx(200);
LED_ERR = 0; }

PIR1bits.RCIF = 0;
TXSTAbits.TXEN=1;
}
}

I've checked baud rates on both sides and there seems to be no timing issue. I also have a Max232 circuit in between for the voltage level conversion.

As of now I have no idea whats wrong so any help would be greatly appreciated.

Thank you!

OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 51);



Looks like during the open you turn the int for receive back off. Do the OpenUSART first then fiddle with the bits.
 
Hi,

I'm fairly new to UART and i'm trying to do something fairly simple (or so i've been told) with a PIC18F4520 microcontroller.

I'm trying to send data via terminal software to the PIC and receive it back. I have no problems in getting data when its hardcoded onto the PIC (stored in variables and received through TXREG of the PIC) but when I try and send anything from the PC to the RX register RCREG I keep getting 0's and data never changes. I'm using a receive interrupt to do this. My code is shown below -

#include <delays.h>
#include <p18f4520.h>
#include <usart.h>

/****** Bit Variable Assignment *********/
#define LED_CHECK PORTBbits.RB2
void high_isr(void);
unsigned char receivedata;


/** Declare Interrupt Vector Sections ****************************/
#pragma code high_vector=0x08
void interrupt_at_high_vector(void)
{
_asm goto high_isr _endasm
}

/******************* MAIN ******************/
#pragma code
void main(void) {


//Enable TX register and set TX pins for transmission
TXSTA = 0b00100000; // Make Tx pin of PORTC and output pin
RCSTA = 0b10010000; // Enable the serial port of PIC18


You dont need this, the serial port is configured by the OpenUSART function.For enabling the pins, all you need to do is make them digital using ADCON1 and set TX pin to output using the TRIS registers.

//Set interrupt pins for USART
RCONbits.IPEN = 1; // Enable interrupt priorities
INTCONbits.PEIE=1;// add this to enable peripheral interrupts
INTCONbits.GIEH = 1; // All GLOBAL interrupts are high priority
PIE1bits.RCIE = 1; // Enable Receive interrupt..Not needed
IPR1bits.RCIP = 1; // Make the UART Rx interrupt a high priority interrupt




Also the default interrupt vector is high priority unless programmed otherwise.Should come after all initialization.

//Configure the USART
OpenUSART (USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 51);


/***************** Main LOOP 2 - USART***********************/
LED_CHECK = 1;


while(1)
{
TXREG = receivedata;
while(!TXSTAbits.TRMT);
}

CloseUSART();

}

#pragma interrupt high_isr
void high_isr(void)
{
if(PIR1bits.RCIF)
{
receivedata = RCREG;
if (RCSTAbits.OERR==1) //check for overflow error
{ RCSTAbits.CREN=0; //if error present, reset OERR so that reception can continue
RCSTAbits.CREN=1;
LED_ERR = 1;
Delay10KTCYx(200);
LED_ERR = 0; }

else if(RCSTAbits.FERR == 1){ //Handling Framing error
char dummy, dummy1, dummy2;
TXSTAbits.TXEN=0;
TXSTAbits.TXEN=1;
dummy = RCREG;
dummy1 = RCREG;
dummy2 = RCREG;
LED_ERR = 1;
Delay10KTCYx(200);
LED_ERR = 0; }

PIR1bits.RCIF = 0;
TXSTAbits.TXEN=1;
}
}

I've checked baud rates on both sides and there seems to be no timing issue. I also have a Max232 circuit in between for the voltage level conversion.

As of now I have no idea whats wrong so any help would be greatly appreciated.

Thank you!


These were some of the problems in your code. Am in a hurry, will give a detailed look when i come back. Also put an example for you k...:)
 
Thank you for the replies!

From both the comments it seems to me that the OpenUSART function and setting the pins are an either or thing. So I've changed my code as follows -

//Configure the USART
OpenUSART (USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 51);

//Set interrupt pins for USART
RCONbits.IPEN = 1; // Enable interrupt priorities
INTCONbits.PEIE=1; // add this to enable peripheral interrupts
INTCONbits.GIEH = 1; // All GLOBAL interrupts are high priority
IPR1bits.RCIP = 1; // Make the UART Rx interrupt a high priority interrupt

Here I have removed the TXSTA and RCSTA pin settings and moved the OpenUSART code up there.. I'll check this as soon as I can and let you know if it works! If there are any other suggestions (as you seem to have Syed) please don't hesitate to add.

Thanks!!
 
Last edited:
I dont see any configuration settings? You cant run a processor without any configuration settings.

Put this in the first pin configuration:

ADCON1=0x0f;
TRISCbits.TRIC6=0;


Also LED_ERR is not defined.
 
Last edited:
Ahh.. I think there were some mistakes in the copy-pasting. If you look at the initial post by me the LED_ERR macro is defined. I did define TRISCbits.TRIC6 = 0 initially but from what I read in the data sheet the the RC6 pin has to be set as an input. Either way its not defined in what I've put up here. I'll add this and see if it works.

Thanks for this!!!
 
Yes. Missed that.

What about the configuration settings?

Here is a working version of your code, i am highlighting the changes(additions)

Code:
#include <delays.h>
#include <p18f4520.h>
#include <usart.h>
[COLOR="Red"]#pragma config OSC=HSPLL,WDT=OFF,DEBUG=ON,LVP=OFF,IESO=OFF[/COLOR]// the config settings that i have used


/****** Bit Variable Assignment *********/
#define LED_CHECK PORTBbits.RB2
[COLOR="Red"]#define LED_ERR PORTBbits.RB3[/COLOR] //Arbitrarily Defined
void high_isr(void);
unsigned char receivedata;


/** Declare Interrupt Vector Sections ****************************/
#pragma code high_vector=0x00008
void interrupt_at_high_vector(void)
{
_asm goto high_isr _endasm
}

/******************* MAIN ******************/
#pragma code
void main(void) {

[COLOR="Red"]ADCON1=0x0f;
TRISBbits.TRISB2=0;
TRISBbits.TRISB3=0;[/COLOR]



//Configure the USART
OpenUSART (USART_TX_INT_OFF & [COLOR="Red"]USART_RX_INT_ON[/COLOR] & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 51);

[COLOR="Red"]//Set interrupt pins for USART
RCONbits.IPEN = 1; // Enable interrupt priorities
IPR1bits.RCIP = 1; // Make the UART Rx interrupt a high priority interrupt
[COLOR="Yellow"]INTCONbits.GIEL=1;// or INTCONbits.PEIE=1;[/COLOR]
INTCONbits.GIEH = 1; // All GLOBAL interrupts are high priority[/COLOR] //Brought Down


/***************** Main LOOP 2 - USART***********************/
LED_CHECK = 1;


while(1)
{
TXREG = receivedata;
while(!TXSTAbits.TRMT);
}

CloseUSART();

}

#pragma interrupt high_isr
void high_isr(void)
{
if(PIR1bits.RCIF)
{
receivedata = RCREG;

if (RCSTAbits.OERR==1) //check for overflow error
		{
			 RCSTAbits.CREN=0; //if error present, reset OERR so that reception can continue
			RCSTAbits.CREN=1;
			LED_ERR = 1;
			Delay10KTCYx(200);
			LED_ERR = 0; }

else if(RCSTAbits.FERR == 1){ //Handling Framing error
			char dummy, dummy1, dummy2;
			TXSTAbits.TXEN=0;
			TXSTAbits.TXEN=1;
			dummy = RCREG;
			dummy1 = RCREG;
			dummy2 = RCREG;
			LED_ERR = 1;
			Delay10KTCYx(200);
			LED_ERR = 0; }
			PIR1bits.RCIF = 0;
			TXSTAbits.TXEN=1;
}
}

Please see that the pins need to be configured as digital Input output using the ADCON1 register, the peripheral interrupts need to be enabled.
 
OK ive changed the code as follows -

#include <delays.h>
#include <p18f4520.h>
#include <usart.h>
#include "main.h"

/****** Bit Variable Assignment *********/
#define LED_CHECK PORTBbits.RB2
#define LED_ERR PORTBbits.RB1
#define LED_ERR1 PORTBbits.RB3

void high_isr(void);
unsigned char receivedata;


/** Declare Interrupt Vector Sections ****************************/
#pragma code high_vector=0x08
void interrupt_at_high_vector(void)
{
_asm goto high_isr _endasm
}

/******************* MAIN ******************/
#pragma code
void main(void) {

//Set PORT pins as I/O
TRISCbits.TRISC6 = 0; //Sets RC6 as output pin - TX
TRISCbits.TRISC7 = 1; //Sets RC7 as input pin - RX
TRISBbits.TRISB2 = 0; //Set LED 2 as output
TRISBbits.TRISB1 = 0;
TRISBbits.TRISB3 = 0;

ADCON1=0x0F;

//Set interrupt pins for USART
RCONbits.IPEN = 1; // Enable interrupt priorities
INTCONbits.PEIE= 1; // add this to enable peripheral interrupts
INTCONbits.GIEH = 1; // All GLOBAL interrupts are high priority
IPR1bits.RCIP = 1; // Make the UART Rx interrupt a high priority interrupt

//Configure the USART
OpenUSART (USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 51);

/***************** Main LOOP 2 - USART***********************/
LED_CHECK = 1;


while(1)
{
TXREG = receivedata;
while(!TXSTAbits.TRMT);
}


CloseUSART();

}

#pragma interrupt high_isr
void high_isr(void)
{
if(PIR1bits.RCIF)
{
receivedata = RCREG;

if (RCSTAbits.OERR==1) //check for overflow error
{
RCSTAbits.CREN=0; //if error present, reset OERR so that reception can continue
RCSTAbits.CREN=1;
LED_ERR = 1;
Delay10KTCYx(200);
LED_ERR = 0;
}

else if(RCSTAbits.FERR == 1) //Handling Framing error
{
char dummy, dummy1, dummy2;
dummy = RCREG;
dummy1 = RCREG;
dummy2 = RCREG;
TXSTAbits.TXEN=0;
TXSTAbits.TXEN=1;
LED_ERR1 = 1;
Delay10KTCYx(200);
LED_ERR1 = 0;
}

PIR1bits.RCIF = 0;
TXSTAbits.TXEN=1;
}
}

When I load this onto the microcontroller both the LED's (LED_ERR and LED_ERR1) light up!!!!! So a framing and an overrun error are occuring simultaneously... And they don't seem to be correcting themselves as they should be based on the code.

The output is a constant stream of ascii 'K' which I'm not sending. If i type something in the send box of the terminal it seems to have no effect.

Note - I think you posted your post while I was writing this up :p.. I'll make the changes you've provided and let you know how it goes. My configs are in a header file shown above. Dunno how i missed that before!!!!!
 
Last edited:
K. Turn off both the LED's in initialization, did you try the code i wrote? Its working here.
 
Last edited:
I tried your code. Unfortunately its still sending a continuous stream of ascii 'K' no matter what i try to send. I'm using realterm terminal software (realterm.sourceforge.net)
Which one are you using? maybe its got something to do with that.
 
Once again it doesnt seem to help. When I use the advanced serial port monitor i get the asii 'K' value over and over again, even if i try sending chars. Is it possible for you to send me a screen shot or something of how yours is working? I'm really stumped because everything seems to be right in the code.

Also another thing which I thought of trying is using pin settings (TXSTA and RCSTA etc) instead of OPENUsart. This is an either or situation right? so if I remove the OpenUSART function and use those instead it should still work?
 
Last edited:
Post your schematic, if you want to configure the serial port manually then ok, it wont make a difference. Also check if your serial software is performing a write to the serial port by shorting the TX and RX pins of the Serial Cable and then sending data, see if it appears on the read panel . There is nothing wrong with the program.
 
I'm a little unsure what you mean by shorting the TX and RX pins but I stored data as a variable in my program and sent it using the TXREG register. This is working fine.

By schematic you mean my hardware set up? I'm using a PICDEM 2+ board with PIC18F4520 microcontroller and a max232 chip in between the serial port connection. I dont think theres any problem with that because when I send hard coded data from the PIC as mentioned above it seems to work fine.

Edit - Ahh i get what you mean by short. I'll try it.
 
Last edited:
Yes the shorting process works. Its sending the correct data. So this means that the data is messing up somewhere on its waay to the PIC or somewhere on the way back.
 
I switched your code around a bit as I'm not sure what the UART library does and you were enabling interrupts before changing the priority. I also added a flag (gotData) so it only sends data after it receives it. AND, I removed the delays from your ISR, one way to get framing and overflow errors is to have a delay in your ISR.

Mike.
Code:
#include <delays.h>
#include <p18f4520.h>
#include <usart.h>
#include "main.h"

/****** Bit Variable Assignment *********/
#define LED_CHECK PORTBbits.RB2
#define LED_ERR PORTBbits.RB1
#define LED_ERR1 PORTBbits.RB3

void high_isr(void);
unsigned char receivedata;
unsigned char gotData;

/** Declare Interrupt Vector Sections ****************************/
#pragma code high_vector=0x08
void interrupt_at_high_vector(void)
{
_asm goto high_isr _endasm
}

/******************* MAIN ******************/
#pragma code
void main(void) {
    //Set PORT pins as I/O
    TRISCbits.TRISC6 = 0; //Sets RC6 as output pin - TX
    TRISCbits.TRISC7 = 1; //Sets RC7 as input pin - RX
    TRISBbits.TRISB2 = 0; //Set LED 2 as output
    TRISBbits.TRISB1 = 0;
    TRISBbits.TRISB3 = 0;
    
    ADCON1=0x0F;
    
    //Configure the USART
    OpenUSART (USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 51);
    
    //Set interrupt pins for USART 
    RCONbits.IPEN = 1; // Enable interrupt priorities
    IPR1bits.RCIP = 1; // Make the UART Rx interrupt a high priority interrupt
    INTCONbits.PEIE= 1; // add this to enable peripheral interrupts
    INTCONbits.GIEH = 1; // All GLOBAL interrupts are high priority
    
    /***************** Main LOOP 2 - USART***********************/
    LED_CHECK = 1;
    gotData=0;
    
    while(1)
    {
        if(gotData){
            gotData=0;
            TXREG = receivedata;
            while(!TXSTAbits.TRMT);
        }
    }
    
    
    CloseUSART();
    
}

#pragma interrupt high_isr
void high_isr(void)
{
    if(PIR1bits.RCIF)
    { 
        receivedata = RCREG;
        gotData=1;
        if (RCSTAbits.OERR==1) //check for overflow error
        { 
            RCSTAbits.CREN=0; //if error present, reset OERR so that reception can continue
            RCSTAbits.CREN=1;
            LED_ERR = 1;
            //Delay10KTCYx(200);
            LED_ERR = 0;
        }
    
        else if(RCSTAbits.FERR == 1) //Handling Framing error 
        { 
            char dummy, dummy1, dummy2; 
            dummy = RCREG; 
            dummy1 = RCREG; 
            dummy2 = RCREG; 
            TXSTAbits.TXEN=0; 
            TXSTAbits.TXEN=1; 
            LED_ERR1 = 1;
            //Delay10KTCYx(200);
            LED_ERR1 = 0; 
        }

        PIR1bits.RCIF = 0;
        TXSTAbits.TXEN=1;
    }
}
 
I switched your code around a bit as I'm not sure what the UART library does and you were enabling interrupts before changing the priority. I also added a flag (gotData) so it only sends data after it receives it. AND, I removed the delays from your ISR, one way to get framing and overflow errors is to have a delay in your ISR.

Mike.
Code:
#include <delays.h>
#include <p18f4520.h>
#include <usart.h>
#include "main.h"

/****** Bit Variable Assignment *********/
#define LED_CHECK PORTBbits.RB2
#define LED_ERR PORTBbits.RB1
#define LED_ERR1 PORTBbits.RB3

void high_isr(void);
unsigned char receivedata;
unsigned char gotData;

/** Declare Interrupt Vector Sections ****************************/
#pragma code high_vector=0x08
void interrupt_at_high_vector(void)
{
_asm goto high_isr _endasm
}

/******************* MAIN ******************/
#pragma code
void main(void) {
    //Set PORT pins as I/O
    TRISCbits.TRISC6 = 0; //Sets RC6 as output pin - TX
    TRISCbits.TRISC7 = 1; //Sets RC7 as input pin - RX
    TRISBbits.TRISB2 = 0; //Set LED 2 as output
    TRISBbits.TRISB1 = 0;
    TRISBbits.TRISB3 = 0;
    
    ADCON1=0x0F;
    
    //Configure the USART
    OpenUSART (USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 51);
    
    //Set interrupt pins for USART 
    RCONbits.IPEN = 1; // Enable interrupt priorities
    IPR1bits.RCIP = 1; // Make the UART Rx interrupt a high priority interrupt
    INTCONbits.PEIE= 1; // add this to enable peripheral interrupts
    INTCONbits.GIEH = 1; // All GLOBAL interrupts are high priority
    
    /***************** Main LOOP 2 - USART***********************/
    LED_CHECK = 1;
    gotData=0;
    
    while(1)
    {
        if(gotData){
            gotData=0;
            TXREG = receivedata;
            while(!TXSTAbits.TRMT);
        }
    }
    
    
    CloseUSART();
    
}

#pragma interrupt high_isr
void high_isr(void)
{
    if(PIR1bits.RCIF)
    { 
        receivedata = RCREG;
        gotData=1;
        if (RCSTAbits.OERR==1) //check for overflow error
        { 
            RCSTAbits.CREN=0; //if error present, reset OERR so that reception can continue
            RCSTAbits.CREN=1;
            LED_ERR = 1;
            //Delay10KTCYx(200);
            LED_ERR = 0;
        }
    
        else if(RCSTAbits.FERR == 1) //Handling Framing error 
        { 
            char dummy, dummy1, dummy2; 
            dummy = RCREG; 
            dummy1 = RCREG; 
            dummy2 = RCREG; 
           [B] TXSTAbits.TXEN=0; 
            TXSTAbits.TXEN=1; [/B] not needed
            LED_ERR1 = 1;
            //Delay10KTCYx(200);
            LED_ERR1 = 0; 
        }

        PIR1bits.RCIF = 0;
        [B]TXSTAbits.TXEN=1;[/B] not needed
    }
}

Hi Mike, nice additions, another thing i noticed that he has read the RCREG 3 times to clear the framing error, it only needs to be read once and the next byte is to be received, but reading it 2 times is k i guess( covers the "receiving part"). Also one doesnt need to mess with the TXEN bit(not that it makes a problem since he is making it high again). Even in the ISR,it need not be messed with its already high. These are not corrections just optimizations.
 
The gotData thing was a pretty good suggestion but still no dice :(

I tried it and the one thing it tells me is that my interrupt is probably not firing!! My screen is a complete blank so I think it never goes into the gotData loop which means even when I send something the flags not being raised maybe or something is making the interrupt not fire.

Is there any way to check the interrupts?
 
Last edited:
Meaning this -

TRISCbits.TRISC6 = 1; //Sets RC6 as output pin - TX ??

I just tried it but still no response.
 
Status
Not open for further replies.

Latest threads

Back
Top