Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Problem in UART communication using PIC18F4550

Status
Not open for further replies.

abhishekdixit

Full Member level 2
Joined
Dec 30, 2011
Messages
124
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
India
Activity points
2,182
hello all,
I have a small project of UART Communication, in which I am receiving 11 bytes of data and just transmit it to hyper terminal. for which i am receving data from user and save it to the character array and after receiving it i transmit this array, in PROTEUS it is working fine, but when i apply it on Real Hardware, the packet which is transmitting is not transmit fully data, it lose some data. I have checked all the configure setting used for UART but still this problem is going on, Please help me what to do?
I am attaching my code here, if someone found any correction in it so please help me.

Code:
char SerialData[];

void UARTInit(void)
{
    TRISC = 0x80;
    TXSTA = 0x20;
    SPBRG = 77;
    TXSTAbits.TXEN=1;
    RCSTAbits.SPEN=1;
    RCSTAbits.CREN=1;
}

void UARTSend(void)
{
    unsigned char i=0;
    for(i=0;i<11;i++)
    {
        TXREG = SerialData[i];
        while(PIR1bits.TXIF==0);
        PIR1bits.TXIF=0;
        Delay1KTCYx(100);
    }
}

void UARTReceive(void)
{
    unsigned char i=0;
    for(i=0;i<11;i++)
    {
        while(PIR1bits.RCIF==0);
        SerialData[i] = RCREG;
        PIR1bits.RCIF=0;
    }
}

void main(void)
{
    TRISC =0x80;
    UARTInit();
    while(1)
    {
        UARTReceive();
        UARTSend();
    }
    return 0;
}

Regards,
Abhishek
 

You have initialized TRISC=0x80 twice,in your program.One,in the main function,and second time,in the UARTInit() function.That is the source of problem...maybe.Remove the initialization of TRISC in the main function and run the code again.It should work then..
 

Use UART Interrupt to receive Serial data and then in ISR itself retransmit the data.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top