|
|
View previous topic :: View next topic |
Author |
Message |
jpage
Joined: 23 Jun 2004 Posts: 24
|
Code ideas for RS232 Data Transfer |
Posted: Tue Jul 27, 2004 10:17 am |
|
|
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
|
|
Posted: Tue Jul 27, 2004 12:03 pm |
|
|
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
|
RE:Code ideas for RS232 Data Transfer |
Posted: Wed Jul 28, 2004 9:10 am |
|
|
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
|
|
Posted: Wed Jul 28, 2004 10:30 am |
|
|
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
|
RE:Code ideas for RS232 Data Transfer |
Posted: Wed Jul 28, 2004 12:00 pm |
|
|
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. |
|
|
|
|
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
|