CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

pic 18f452 and serial communication problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
brahme.girish



Joined: 20 Jun 2010
Posts: 7

View user's profile Send private message

pic 18f452 and serial communication problem
PostPosted: Mon Jun 21, 2010 11:24 pm     Reply with quote

dear all,

I developed a project using Pic18f452. I am using CCS version 4.084.
In my project I am using two timers interrupt for different purpose.
And serial interrupt #int_RDA for data transmission from pc.
The code is like this
Code:

#use rs232(baud =9600,xmit = Pin_c6, rcv = pin_c7)
#int_RDA

void RDA_isr()
{
    data[i++] = getc();
    if(i>=50)
    {
       i = 0;
    }
}

void main()
{

}

Usually my code including all above works very fine. But when I switch ON or OFF my pc controller get hang. As its rcv pin get low (normally when pc is it is at -9v). I use Max232 for communication. I also try to use enable pin but the problem is same.

I can't use watchdog as if controller get hang then watchdog will reset. And both my timers will get reset. And I don't want to reset my timers. As after reseting timer all my other events will be restarted, which should be restarted only when user (customer) want.

So please any one will help me? Please I am at end of my project.

Thanx in advance,

girish.
CC



Joined: 22 Jun 2010
Posts: 2

View user's profile Send private message

PostPosted: Tue Jun 22, 2010 1:51 am     Reply with quote

Try putting

if (!kbhit())
return;

in your INT_RDA routine.
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Tue Jun 22, 2010 2:06 am     Reply with quote

Won't help.
INT_RDA, will only get called when the interrupt flag is set, which means a character has been received. kbhit will be true. If you return without reading the character, you will just get another interrupt... :(

Key thing, add the keyword 'ERRORS' to the #use RS232 statement. I suspect this is what is 'missing'. Without this, if a framing error or overrun error occurs, the RX side of the UART _will_ get hung.

Then modify the interrupt handler as:
Code:

#int_RDA
void RDA_isr(void)
{
    int8 temp;
    temp=getc();
    if ((RS232_ERRORS & 6)!=0) return;
    data[i++] = temp;
    if(i>=50)
    {
       i = 0;
    }
}

This will throw away incoming characters, if the framing error, or overrun error bits get set, avoiding possible problems with the receive code while this is happening. Depending on where in the character the PIC 'is' when PC power goes off, one or both of these will be set for the garbage characters being received, when the line at the PIC is in the 'break' condition (dates from the wire being 'broken', which is what the chip sees if the other end is off).

Best Wishes
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Jun 22, 2010 8:46 am     Reply with quote

FYI-

Microchip considers the 18F452 a mature product and recommends using the 18F4520 in new designs. It is pin-for-pin compatible.

I always put ERRORS in my #use rs232() declaration to make sure it doesn't hang up.
brahme.girish



Joined: 20 Jun 2010
Posts: 7

View user's profile Send private message

PostPosted: Wed Jun 23, 2010 12:36 am     Reply with quote

hi Ttelmah,

Thanx for your valuable reply. I have done exactly same like below as you suggested. It is working very fine. No matter how many times you switch OFF or ON computer.
Code:

#int_RDA
void RDA_isr(void)
{
    int8 temp;

    temp=getc();
    if ((RS232_ERRORS & 6)!=0) return;
    data[i++] = temp;

    if(i>=50)
    {
       i = 0;
    }
}

Thanx once again,

Regards

girish.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group