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

Code ideas for RS232 Data Transfer

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



Joined: 23 Jun 2004
Posts: 24

View user's profile Send private message

Code ideas for RS232 Data Transfer
PostPosted: Tue Jul 27, 2004 10:17 am     Reply with quote

Hi,

Just wanted to see if anyone had any helpful ideas in implementing RS232 data transfer.

I am writing a VB program to communicate with a design using the PIC18f4220.

I will be using VB to configure a RF Radio unit. The VB program will send (hex) data to the PIC's Hardware UART and then resend(or redirect) it through the Software UART which will send it to the Radio Unit's EE for configuration. I will also be doing the reverse to see how the Radio Unit EE is configured.

The data sent and received can be anywhere from 3 to 256 Bytes.

Thanks for any advice.


Code:


#include <18f4220.h>

#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT

#use delay (clock=20000000)


#use rs232(baud = 9600,xmit=PIN_C6,rcv=PIN_C7,Stream = PCHOST)
#use rs232(baud = 9600,xmit=PIN_B1,rcv=PIN_B0,Stream = RADIO)


SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Jul 27, 2004 12:03 pm     Reply with quote

If you are using an RF link plan to have lots of error detection and correction or resend capability.
_________________
The search for better is endless. Instead simply find very good and get the job done.
jpage



Joined: 23 Jun 2004
Posts: 24

View user's profile Send private message

RE:Code ideas for RS232 Data Transfer
PostPosted: Wed Jul 28, 2004 9:10 am     Reply with quote

Hi,

Thanks for the response.

Sorry for the confusion, but I think I may have not conveyed my request properly.

The communication I have between the PC, PIC, and RF radio is all hardwired. The RF communication is a separate issue.

I am sending or receiving serial data (RS232) between the PC, PIC and an onboard RF Radio.

The PC is using pins C6 and C7 (Hardware UART) to communicate with the PIC and pins B1 and B0 (Software UART) are used to communicate between the PIC and RF Radio Unit.

This would be the data flow:

Transmit EE Data:
From PC to MAX232 to PIN C7---> redirect data to PIN B2 --->Radio Receive Pin.

Receive EE Data:
From Radio Transmit Pin to PIN B1 ---> redirect data to PIN C6 ------>MAX232 ---> PC.

Just wanted to get and idea of the best way to handle the TX and RX data since I will have strings varying in size and since I will using the Stream option, is it just a matter doing something like
Code:


#include <18f4220.h>

#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT

#use delay (clock=20000000)


#use rs232(baud = 9600,xmit=PIN_C6,rcv=PIN_C7,Stream = PCHOST)
#use rs232(baud = 9600,xmit=PIN_B1,rcv=PIN_B2,Stream = RADIO)
.
.
.
data_in = fgetc(PCHOST);
.
.
.
fputs(data_in,RADIO);


to redirect the data?

Thanks for any advice.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jul 28, 2004 10:30 am     Reply with quote

Your suggestion is probably the easiest way to solve your problem, but it will only work when the baudrate to your radio is much faster than the baudrate to your PC. The hardware UART can only buffer up to 3 characters and when the baudrates of the PC is equal or greater than the baudrate of the radio you are very likely to lose characters.

Depending on the details of your transmitted data (message size, frequency of messages, etc) there are several ways to work around this problem:
1) Read a complete message from the PC in a buffer and then pass the complete message to the radio.
2) Introduce (hardware) flow-control to the PC.
3) Use interrupts on the UART for writing data to a circular buffer.
4) Other methods that I can't remember now.
5) A combination of the above.

Personally I like a combination of 2 and 3.
jpage



Joined: 23 Jun 2004
Posts: 24

View user's profile Send private message

RE:Code ideas for RS232 Data Transfer
PostPosted: Wed Jul 28, 2004 12:00 pm     Reply with quote

Thanks for the baudrate info. That is good to know.

I will probably try out your suggestions (1&2 or 2&3) and see how that works.

Fortunately I do have the ,CTS and RTS , hardware control.

I'll keep you posted.

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