PDA

View Full Version : PIC to PIC Serial Communication



v_merino
- 16th July 2004, 18:01
Hey all, can someone please show me how to successfully send a byte of data from one PIC to another PIC. Im using the SERIN and SEROUT commands but it doesnt seem like I'm doing it right. I get garbage results on the other end. Thanks for your help. This is the code I'm using:

'TX PIC:
Include "modedefs.bas"
pause 1000
SEROUT 0, T2400,[%11100010]
END

'RX PIC:
SERIN 3,T2400,10000,error,RX 'wait for signal for 10 seconds
LCDout #RX
goto finish

error:
LCDout $fe, 1 'clear screen
LCDout $fe, 2 'return home
Lcdout "Error"

finish:
end

Dwayne
- 19th July 2004, 14:59
Hello V_merino

VM>>
'TX PIC:
Include "modedefs.bas"
pause 1000
SEROUT 0, T2400,[%11100010]
END

'RX PIC:
SERIN 3,T2400,10000,error,RX 'wait for signal for 10 seconds
LCDout #RX
goto finish

error:
LCDout $fe, 1 'clear screen
LCDout $fe, 2 'return home
Lcdout "Error"

finish:
end
<<

Make sure your RX pin is a data pin in the TRIS registser, and make sure your TX pin is a output pin in the TRIS register.
I don't see any of this in your program.

Then I would try for the SIMPLER SERIN and SEROUT (until you can verify your data is actually being sent in good form..
Use
Serin Pin, T2400, RecDataword

Serout Pin, T2400, DataWord


With this verified, then put your "Flags and timers on". You could have "noise" going on from improper grounding, and that will give you trash.

carl_schell
- 21st July 2004, 08:27
v_merino -

One clarification I thought I would add to Dwayne's post [Hope you don't mind Dwayne :) ]

Remember that though you are sending Data in Binary format "[%11100010], you are receiving the data in the decimal version of 11100010, which is 226 I am sure you already knew this, but just thought I give you a reminder.

I double checked your code between two of my development boards and it worked perfectly for me no problem. The SerIn command will automatically take care of making your pin from an input.

One last thing you could double check is that your variable is declared properly. The reason I say this is that typically, I lable my PortC.7 pin RX, so when I popped your code into my template, i nearly forgot to change your data storage variable to a different name, (RX2).

ie:

RX var PortC.7 'Nickname for RS-232 RX Pin
RX2 var byte 'Storage variable for SerIn Data

Best Regards,

Carl
www.schellelectronics.com

Dwayne
- 21st July 2004, 14:47
Hello Carl,

Carl>>One clarification I thought I would add to Dwayne's post [Hope you don't mind Dwayne ]<<

Thanks Carl! appreciate it eee-men-slee!

Carl>Remember that though you are sending Data in Binary format "[%11100010], you are receiving the data in the decimal version of 11100010, which is 226 I am sure you already knew this, but just thought I give you a reminder. <<

I never bothered to look it up <g>. but 226 is a funny character that is garbage to most <g>

Carl>>I double checked your code between two of my development boards and it worked perfectly for me no problem. The SerIn command will automatically take care of making your pin from an input.<<

I guess I just don't trust something automatically making something a input for me <g>. It comes from the old Phillips Chips. So I assign it a input anyhow <g>.

I am down right now for the next 2 weeks or so... been down for about 1 1/2 weeks... bought a new house... as soon as I move in, I will be up and running again.

Thanks again for the help!

Dwayne

v_merino
- 23rd July 2004, 07:05
Thanks for all your help guys. I got it to work. Thanks again