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 support@ccsinfo.com

Help with RS232 problem.

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



Joined: 21 Oct 2003
Posts: 58

View user's profile Send private message

Help with RS232 problem.
PostPosted: Wed Jan 24, 2007 6:36 am     Reply with quote

I'm having a problem with my RS232. To try to solve the problem I decided to send the data on one pin (PIN E1) of my18F4580 and read it back into another (PIN E2). I wrote the following small test program
Code:

#include <18f4580>
#fuses HS,NOPROTECT,NOLVP,NOWDT
#use delay (clock=20000000)

int vbatt,packv;

void main()
{
vbatt = 0x55;
while(1)
{
#use rs232 (baud = 9600,float_high, bits = 8, xmit = PIN_E1,rcv = PIN_E2)
putc (vbatt);
packv = getc();
}
}

if I remove the packv = getc(); line the pic transmits fine, with the program as above the pic doesn't transmit at all.
What did I do wrong?

It's a pin to pin connection with a 1K pullup to the 5V supply, my compiler is version 3.245.

TIA

JFK[/code]
Guest








Re: Help with RS232 problem.
PostPosted: Wed Jan 24, 2007 7:35 am     Reply with quote

jfk1965 wrote:
I'm having a problem with my RS232. To try to solve the problem I decided to send the data on one pin (PIN E1) of my18F4580 and read it back into another (PIN E2). I wrote the following small test program
Code:

#include <18f4580>
#fuses HS,NOPROTECT,NOLVP,NOWDT
#use delay (clock=20000000)

int vbatt,packv;

void main()
{
vbatt = 0x55;
while(1)
{
#use rs232 (baud = 9600,float_high, bits = 8, xmit = PIN_E1,rcv = PIN_E2)
putc (vbatt);
packv = getc();
}
}

if I remove the packv = getc(); line the pic transmits fine, with the program as above the pic doesn't transmit at all.
What did I do wrong?

It's a pin to pin connection with a 1K pullup to the 5V supply, my compiler is version 3.245.

TIA

JFK[/code]



You must understand getc() waits while receive data. Your data has been sent 1 line before, and it is too late for getc(). If You want to get something send by the same device, you must use receiving by interrupts.
jfk1965



Joined: 21 Oct 2003
Posts: 58

View user's profile Send private message

PostPosted: Wed Jan 24, 2007 8:11 am     Reply with quote

OK thanks I think I've got a grasp of it now. Can I test for a kbhit with an if statement before I use the getc?

I will try it

JFK
Ttelmah
Guest







PostPosted: Wed Jan 24, 2007 9:36 am     Reply with quote

You can, but you will never see the character. The 'point', is that you are using a 'software' UART on these pins. This means the compiler can only do one thing at a time. Receive a character, _or_ transmit a character. there is no buffering. To receive a character, the code has to either be waiting for it to arrive (in getc), or check kbhit, in the first half of the bit time. To have buffering (where the character is automatically held for you till you read it), you need to be using the hardware UART pins.

Best Wishes
jfk1965



Joined: 21 Oct 2003
Posts: 58

View user's profile Send private message

PostPosted: Wed Jan 24, 2007 10:30 am     Reply with quote

Ttelmah wrote:
You can, but you will never see the character. The 'point', is that you are using a 'software' UART on these pins. This means the compiler can only do one thing at a time. Receive a character, _or_ transmit a character. there is no buffering. To receive a character, the code has to either be waiting for it to arrive (in getc), or check kbhit, in the first half of the bit time. To have buffering (where the character is automatically held for you till you read it), you need to be using the hardware UART pins.

Best Wishes


Thanks Ttelmah for that explanation,one more question if I may. To use the hardware UART is it just a case of changing the pins assignments for xmit and rcv in the #use 232 statement or do I have to do anything else like the setup_UART. Also will I need to use the 1K pull ups on the hardware UART like I did on the software uart or not?

thanks for your patience, I'm normally a power guy using pics to measure voltage and switch outputs based on the readings this is the first time I've used RS232 and it's provng a bit more difficult than I'd hoped.

JFK
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