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

RS 232 PROBLEM

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



Joined: 04 Jun 2006
Posts: 35

View user's profile Send private message

RS 232 PROBLEM
PostPosted: Wed Sep 27, 2006 6:15 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Sep 27, 2006 6:55 am     Reply with quote

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

View user's profile Send private message Visit poster's website AIM Address MSN Messenger

PostPosted: Wed Sep 27, 2006 7:41 am     Reply with quote

#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

View user's profile Send private message

PostPosted: Wed Sep 27, 2006 10:08 am     Reply with quote

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

View user's profile Send private message Visit poster's website AIM Address MSN Messenger

PostPosted: Wed Sep 27, 2006 10:35 am     Reply with quote

Ooops,

Sorry about that PCM, was on my Mac so couldn't test but I understand Smile 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

View user's profile Send private message AIM Address

PostPosted: Wed Sep 27, 2006 11:05 am     Reply with quote

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

View user's profile Send private message Visit poster's website AIM Address MSN Messenger

PostPosted: Wed Sep 27, 2006 11:14 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Sep 27, 2006 11:58 am     Reply with quote

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.
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