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.

[PIC] Problem in interfacing Serial Communication at high speed(10 ms time, 9600 baud rate)

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 everyone,
I am interfacing with Serial Communication at PIC18F4550 micro controller, in which i am using 9600 baud rate, my hardware connections are perfectly OK. and my code is also working on that hardware at normal speed.
but their is a problem that when i receive string at the speed of 10ms, then my controller goes in hang state. i used already watchdog timer in my code due to this my controller restart when it goes in hang condition, but i am unable to understand that why it happens? am i sending serial string very fast or i have to do some corrections in my code?
please help me


Regards,
Abhishek
 

post your code to help you better.
 

hello,
I am posting my code in which i have shown my Serial Communication.

Code:
void UART_init()
{
    TRISC =0x87;
    TXSTA=0x20;
    SPBRG=77;
    RCSTAbits.CREN=1;
    RCSTAbits.SPEN=1;
    TXSTAbits.TXEN=1;
    PIE1bits.RCIE=1;
   // PIE1bits.TXIE=1;
    INTCONbits.PEIE=1;
    INTCONbits.GIE=1;
}

Code:
void RC_ISR(void)
{
    if(PIR1bits.RCIF==1)
    {
        switch(i)
        {
            case 0:
                serial_packet[i++]=RCREG;
                break;
            case 1:
                serial_packet[i++]=RCREG;
                break;
            case 2:
                serial_packet[i++]=RCREG;
                break;
            case 3:
                serial_packet[i++]=RCREG;
                break;
            case 4:
                serial_packet[i++]=RCREG;
                break;
            case 5:
                serial_packet[i++]=RCREG;
                break;
            case 6:
                serial_packet[i++]=RCREG;
                break;
            case 7:
                serial_packet[i++]=RCREG;
                break;
            case 8:
                serial_packet[i++]=RCREG;
                break;
            case 9:
                serial_packet[i++]=RCREG;
                break;
            case 10:
            {
                serial_packet[i++]=RCREG;
                i=0;
                receive_data=1;
                break;
            }
        }

        PIR1bits.RCIF=0;
    }
}

Code:
void TX_ISR(void)
{
      if(receive_data==1)
    {
       for(i=0;i<11;i++)
        {
            TXREG=serial_packet[i];
            if(PIR1bits.TXIF==1)
            PIR1bits.TXIF=0;
            Delay10KTCYx(2);
        }
        receive_data=0;
        i=0;
    }
}

Code:
void main(void)
{
    TRISD=0x40;
    PORTD=0x40;
    LATD=0x40;
    TRISAbits.TRISA1=0;
    PORTAbits.RA1=0;
    LATAbits.LATA1=0;
       
    UART_init();
    while(1)
    {
     	    if(receive_data==1)
            {
                 TX_ISR();
                 receive_data=0;
            }
          

    }
}

my be this will help to understand my problem.
 

If i understand your code correctly then I don't know what you want to do with your receiver ISR logic but i assume you are waiting there for receiving the 10 char string or data then transmit your data.so what if 10 chars not received means if you received more or less then 10 chars then what's controller action?

Second I guess your ISR function is not UART inturrupts but polling.If that so no calling of RC_ISR(); function in main().

you can check your clock fuse settings are fine.
 
Last edited:

May be OERR error or FERR error is happening.....
 

hello,
your guess is right, but if you are asking that if i receive less than 10 char then do nothing.
and second thing is that my RC_ISR is in UART interrupt function, so i don't need to call it in main function.

Thank You
 

hello,
your guess is right, but if you are asking that if i receive less than 10 char then do nothing.

then I think your array index i will not reset to 0 suppose received data is 8 then as per your code it do nothing.now next time it reads 10 char then it will take action after 2 char or go to i =18 then it still do noting.Correct me If i am wrong.

and if your logic works with low baud rate and not with higher then please check your fuse are sets for high speed clock or baud rate.
 

hello,
i have checked my code, it works with low speed perfectly. apart from it i also make i to zero manually, so as you told about the fuse bits for high baud rate, where can i check this??
please tell me.
 

you can find fuse for clock in your datasheet and for using it then you can refer to your compiler manual.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top