View previous topic :: View next topic |
Author |
Message |
younus_noman
Joined: 04 Jul 2005 Posts: 9
|
RS-232 |
Posted: Mon Jul 04, 2005 1:55 pm |
|
|
I am trying to receive data serially over RS-232 through LAB VIEW.
Lab view sends 3 bytes plus a termination character (0D ) at the end to PIC16f876 controller. Some how i am not able to read that termination character (0D) using getc().
Is it necessary for me to send a carriage return and a line feed at the end to read the 4th termination character?
Any ideas?
Noman Younus |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 04, 2005 2:08 pm |
|
|
getc() does not do any filtering or exclusion of characters.
See the test program below. It receives a character with getc()
and then displays it as a hex value in the terminal window.
When I type "ABCD" into my terminal program and press
the Enter key on my PC, I get the following output:
Code: |
A 41
B 42
C 43
D 44
0D
|
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//========================
void main()
{
char c;
while(1)
{
c = getc();
printf(" %X\n\r", c);
}
} |
|
|
|
younus_noman
Joined: 04 Jul 2005 Posts: 9
|
|
Posted: Mon Jul 04, 2005 2:37 pm |
|
|
Thanks for your quick reply..
I tried the above code before and i am able to display the hex value.
but when i say printf("ABCD \r\n") it displays ABCD on the hyper terminal whereas if i say printf("ABCD") without using the line feed and carriage return then it just displays ABC i.e. it chops of the last byte and i am not sure y it does that
I also did PIC to PIC commnication and displayed the recevied data on my LCD.
MASTER PIC sends---- printf("ABCD \n\r);
SLAVE PIC receives and displays ABCD
If i receive 6 bytes it displays ABCDAB (using getchar)
Thanks
Noman Younus |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Jul 04, 2005 2:42 pm |
|
|
You must have a while(1) in your main. Most likely you do not, just the printf and nothing after that. What happens is that main finishes and there is a hidden sleep instruction in there. The last byte of data is still in the transmit buffer when the pic goes to sleep. Post your program if you don't understand what I am talking about. |
|
|
|