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

Problem with aynchronous recption on PIC16F876

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








Problem with aynchronous recption on PIC16F876
PostPosted: Fri May 25, 2007 6:15 am     Reply with quote

My PIC must receive 3 bytes, sent by another one. When I turn the receiver on, If the serial signal has been pluged before, the program Crash...

When I turn the Receiver Pic on with the serail signal pluged, it works good, and then I plug the the serial signal form the other pic, and it works good....

How is it possible to make the receiver works good when turning it ON and plugged ?

I use an #int_rda to launch the recpetion... might it work with a KBHIT ?
Ttelmah
Guest







PostPosted: Fri May 25, 2007 7:07 am     Reply with quote

This is down to writing the program to handle unexpected events.
Remember that asynchronous serial at the PIC, 'idles high'. I'd suspect that when the other kit is plugged in, and not turned on, the line is being pulled low, so the PIC sees continuous '0' characters, and this then leads to the crash.
Your code should be writen to be able to handle this, since otherwise even after initialisation, patterns like this, could cause problems...
At boot, I'd suggest directly reading the serial receive line, and waiting till it does go high, before starting the main code.

Best Wishes
Joyce



Joined: 25 May 2007
Posts: 2
Location: Rennes (France)

View user's profile Send private message Visit poster's website

PostPosted: Fri May 25, 2007 7:47 am     Reply with quote

You're right, I've done a getc() at the beginning of the main code. It has enabled the receiver module to start well when the other one IS NOT plugged.

The level is still HIGH on the receive pin, because of an amplifier system.

And when the receiver module turns ON, and the signal is arriving on the receive pin, it crashes...

With the debugger window, we saw that it crashes only when doing a the first getc() programm.

I don't what to do actually...
tojape



Joined: 14 Jan 2007
Posts: 20
Location: Hungary

View user's profile Send private message

PostPosted: Fri May 25, 2007 9:24 am     Reply with quote

I agree with Ttelmah.
Every communication between two systems may contain corrupted data. You can not, moreover, may not! rely on the assumption that both sides will allways receive error free data. Instead, error handling will be the bigger part of a program section which uses communication.
The simpliest way to avoid the possibility of crashing beacause of corrupted data to form packets from the data stream.
A valid packet always has a header, the payload data, the footer and a checksum. There are a lot of protocols used worldwide for this purpose.
Apart from the approach above, the other cause might be an erroneous behaviour of the getc() function. I am not convinced that it handles frame and overflow errors correctly. Actually, don't use it at all. I wrote an interrupt driven, puffered getc instead.
If you need further information, feel free to contact me.
Best wishes
tojape
_________________
The computer helps solving the problems which would have never arised without computers
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