View previous topic :: View next topic |
Author |
Message |
butterfly
Joined: 04 Jun 2006 Posts: 35
|
RS 232 PROBLEM |
Posted: Wed Sep 27, 2006 6:15 am |
|
|
hi;
i'm using pic 16f877a. 4 mhz cristall osilator.in my progrm, i descibe serial port:
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8
my program is:
main() {
while(TRUE)
putc( getc()+1 );
}
WHEN I SEND A DDATA from my pc,i can see it on rc7 pin(recieve pin)..
why its not work.. any way that you can advice me?? |
|
|
butterfly
Joined: 04 Jun 2006 Posts: 35
|
|
Posted: Wed Sep 27, 2006 6:55 am |
|
|
when i use:
printf("start");
its working but when use
putc('x');
it is not working.. why could you tell me? |
|
|
bsodmike
Joined: 05 Aug 2006 Posts: 52
|
|
Posted: Wed Sep 27, 2006 7:41 am |
|
|
#use delay(clock=4000000); //missing ';'
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8 ); //this is missing.
It should work eitherway tbh. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Sep 27, 2006 10:08 am |
|
|
Quote: | use delay(clock=4000000); //missing ';'
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8 ); //this is missing. |
That's not true. #use statements do not get a semi-colon at the end.
If you test it, you will get these compiler errors:
Quote: | ** Error 104: Extra characters on preprocessor command line ";"
** Error 104: Extra characters on preprocessor command line ";"
2 Errors, 0 Warnings. |
If you're new to the compiler and you want to offer help, you should
test everything before you post. I'm not new to the compiler and
I still test almost everything before I make a post, just to be sure. |
|
|
bsodmike
Joined: 05 Aug 2006 Posts: 52
|
|
Posted: Wed Sep 27, 2006 10:35 am |
|
|
Ooops,
Sorry about that PCM, was on my Mac so couldn't test but I understand Would be nice if CCS released a Mac version heh.
He's at least missing this,
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) //this is missing.
...but it could just be a typo.
Would defining the ports as 'standard i/o' make much of a difference? |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Wed Sep 27, 2006 11:05 am |
|
|
Lets hope Butterfly has taken the time to wire up a level shifter before asking this board for help. The PC and the PIC communicate at different polarities and voltage levels further the baud rates must match as well as the parity and stop bits. The next thing to take into account is the extensive buffering that is hidden on the PC side of things. The PIC hardware buffering is only 2 chars deep so on the PIC receive side it is very easy to overrun it with a PC.
That's why a circular interrupt driven buffer is very often necessary to have any chance of making things reliable. After the transmission of single well spaced characters is proven do not expect that moving to receiving multiple un-spaced chars will work unless you have a circular buffer. Keep in mind the buffer isn't magic so if the chars arrive on average faster than you can process them expect trouble without flow control. |
|
|
bsodmike
Joined: 05 Aug 2006 Posts: 52
|
|
Posted: Wed Sep 27, 2006 11:14 am |
|
|
Yea, wireup a max232 if you are receiving spurious data, also don't forget to decouple your ICs. I'm guessing that you've breadboarded your circuit, and the stray track to track capacitances can get quite nasty.
Some people like to just connect to the db9 connector directly or via a 1K resistor - in this case you'd want to add INVERT to your RS232 #use line, but as Douglas has pointed out - this method can cause problems and isn't a great idea if you are after reliability. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Sep 27, 2006 11:58 am |
|
|
The INVERT feature doesn't work with the hardware UART (pins C6
and C7 in this case). It will only work with a software UART. |
|
|
|