![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
tmach
Joined: 20 Dec 2003 Posts: 14
|
RS232 receive |
Posted: Sun Mar 07, 2004 2:44 pm |
|
|
Hello,
I want to setup RS232 communication between two 16F874A pic's. Both the pics are running from a 20MHz osc in HS mode. The Tx port of the Master is connected to the Rx port of the slave.
The master sends the serial data @15200bps using the following command:
printf("%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X", Tx1_L,Tx1_H,Rx1_L,Rx1_H,Tx2_L,Tx2_H,Rx2_L,
Rx2_H,CH0_L,CH0_H, CH1_L,CH1_H,CH2_L,CH2_H,CH4_L,CH4_H,CH5_L,
CH5_H,CH6_L,CH6_H);
I need to collect this data. I can also select the slave before the master starts the transmission using a strobe signal connected to external interrupt pin of the slave. Please advice if this is possible.
Thanks.
mach |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
Re: RS232 receive |
Posted: Sun Mar 07, 2004 3:48 pm |
|
|
tmach wrote: | Hello,
I want to setup RS232 communication between two 16F874A pic's. Both the pics are running from a 20MHz osc in HS mode. The Tx port of the Master is connected to the Rx port of the slave.
The master sends the serial data @15200bps using the following command:
printf("%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X", Tx1_L,Tx1_H,Rx1_L,Rx1_H,Tx2_L,Tx2_H,Rx2_L,
Rx2_H,CH0_L,CH0_H, CH1_L,CH1_H,CH2_L,CH2_H,CH4_L,CH4_H,CH5_L,
CH5_H,CH6_L,CH6_H);
I need to collect this data. I can also select the slave before the master starts the transmission using a strobe signal connected to external interrupt pin of the slave. Please advice if this is possible.
Thanks.
mach |
Switch to using %02X for each variable. This way two characters are sent for each variable, where the 'as shown' version, will 'lose' digits if there is a leading zero.
Then _given your synchronisation allready mentioned_ (otherwise consider adding a 'header' so the data is recognised), you can just pull 'pairs' of digits into successive variables. So something like:
Code: |
#define fromhex(x) ((x>'9')?((x & 0xF)+10):(x-'0')
int8 gettwodigits() {
int8 val1;
int8 val2;
val1=getc();
val2=getc();
return(fromhex(val2)+fromhex(val1)*16);
}
|
Call this as many times as necessary to pull all the variables.
Personally, I'd consider using buffered serial I/O, and adding a 'timeout', so that the system will recover cleanly, if the data is corrupted.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Ernest LKL Guest
|
Using PIC to acquire serial data from PC |
Posted: Tue Mar 30, 2004 2:58 am |
|
|
Hello,
I am having some problem trying to acquire a stream of serial data from a software in PC. Looking at the results using Hyperterminal, the software will output the readings of the sensors (termistor & humidity sensor) every 100 ms.
eg.:
"Temperature: 23.7 C Humidity: 61.3 %"
So, how can I actually acquire the values of the temperature and humidy using PIC 16F877A? How do we segregate the values and the text?
How do we implement the buffering for the serial data and adding a timeout?
Thanks a lot in advance.
Ernest |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|