Hi
I have a question about RS232 communication. I use the #RDA_int and when
I receive a character (for example 'd') on this port I send an answer to
sender(PC) and wait to receive next byte. But PC needs to send 2 bytes because
first byte be ignored. Now I want to ask why this takes place?
I want to send a INT16 and a INT8 from PC to PIC and make this protocol.
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
Posted: Mon Aug 22, 2011 8:03 pm
When you use a line like
buffer[0]=getc();
the getc() consumes the character in the buffer and another getc() won't get the same character but must wait for the next one to be received.
So if you have
if(getc()=='d')
followed by
if(getc()=='s')
you are comparing the FIRST character received to 'd' and the SECOND character received to 's'. If there is no second character yet the getc() function will wait all day for one to arrive.
I assume you really want something like:
buffer[0]=getc();
if(buffer[0] == 'd')
if(buffer[0] == 's') _________________ The search for better is endless. Instead simply find very good and get the job done.
mojsa2000
Joined: 18 May 2010 Posts: 78
Posted: Mon Aug 22, 2011 8:38 pm
Dear SherpaDoug
You're right. Thanks alot. I used your idea and my fault fixed.
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