PDA

View Full Version : Simple Serial Comms.



koossa
- 23rd November 2007, 08:08
Good day Picers.

I am sending serial data from one pic to another using two 433Mhz RF Modules.
On the receiver side, I send some data (for debug purposes) to my PC.

My Transmitter Code:
<hr>
<code>
'************************************************* ***************
'* Name : Transmit.bas *
'************************************************* ***************

Include "modedefs.bas"

DEFINE OSC 4 ' Set the Xtal frequency
SerialOutPin VAR PORTC.2 ' Serial Out
LEDPin Var PORTC.3
DEFINE CHAR_PACING 1000

ADCON1 = 7
TRISC = %00000000 ' SET ALL PORT C TO OUTPUTS

Main:
&nbsp;&nbsp;PAUSE 5000
&nbsp;&nbsp;
&nbsp;&nbsp;serout2 SerialOutPin, 16780, [#1,#2,#3,#4,#5]
&nbsp;&nbsp;Pause 1000
&nbsp;&nbsp;HIGH LEDPin
&nbsp;&nbsp;Pause 1000
&nbsp;&nbsp;LOW LEDPin
&nbsp;&nbsp;PAUSE 1000
&nbsp;&nbsp;Goto Main
&nbsp;
END
</code>
<hr>

My Receiver Code :
<hr>
<code>
'************************************************* ***************
'* Name : Receiver.bas *
'************************************************* ***************

Include "modedefs.bas"

DEFINE OSC 4 ' Set the Xtal frequency
SerialInPin VAR PORTC.2 ' Serial Out
SerialOutPin VAR PORTB.7
LEDPin Var PORTC.3
CDPin VAR PORTD.2
CDPinState VAR Byte
DataReceived var byte[5]
I VAR BYTE
iLoopPin var byte
Data_ArrayCount var byte
ADCON1 = 7

Main:
Pause 5000
high LEDPin

Loop:
&nbsp;&nbsp;for Data_ArrayCount = 0 to 4
&nbsp;&nbsp;&nbsp;&nbsp;DataReceived[Data_ArrayCount] = 0
&nbsp;&nbsp;next Data_ArrayCount
&nbsp;&nbsp;
&nbsp;&nbsp;SERIN2 SerialInPin,396, 4000, SerialTimeout, [str DataReceived\5]
&nbsp;&nbsp;
&nbsp;&nbsp;if (DataReceived[0] = 1 and DataReceived[1] = 2 and DataReceived[2] = 3) then
&nbsp;&nbsp;&nbsp;&nbsp;serout2 SerialOutPin, 16780, ["DATA=======", 13, 10]
&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;serout2 SerialOutPin, 16780, ["JUNK:", #DataReceived[0], ":", #DataReceived[1], ":", #DataReceived[2],13,10]
&nbsp;&nbsp;endif
Goto LOOP

SerialTimeout:
&nbsp;&nbsp;serout2 SerialOutPin, 16780, ["TIMEOUT", 13, 10]
Goto LOOP
&nbsp;&nbsp;
END
</code>
<hr>


On the PC Side I get the following:
<hr>
JUNK:103:216:131
TIMEOUT
JUNK:103:216:131
TIMEOUT
JUNK:103:216:131
TIMEOUT
JUNK:103:216:131
TIMEOUT
JUNK:103:216:131
<hr>

Any idea what I'm doing wrong?

koossa
- 23rd November 2007, 08:12
Oops!

I see I have different baud rates on serin2 and serout2.