PDA

View Full Version : Serial Com Pic to Pic



uludere72
- 30th May 2005, 11:54
I found lost of example about serial communication . But stil i have problem with my project.

I want to use 16f877. I need 2 serial com.
i am going to build multi pic network.

main pic will ask question to other pic. they will answer it . main pic transmit these returned answer to device.

........

SlaveSelect=PORTB & $f0 ' Get the Slave Select by masking
Lcdout $fe, 1,bin SlaveSelect
pause 200
hserout[dec SlaveSelect]
hserout [26,13,10]

serout2 serialoutput, t9600, ["xyzSTATUS",hex SlaveSelect]

pause 500

serin2 serialinput, t9600,[WAIT ("xyz"),str datatodisplay \8]

Lcdout $fe, 1,str datatodisplay \8
hserout[str datatodisplay \8]
hserout [26,13,10]
pause 500

......

this works properly .
If one of my client Pic didn't send any responce

in this command line

serin2 serialinput, t9600,[WAIT ("xyz"),str datatodisplay \8]

program crash, It is waing for "xyz12345678" I want to skip this line if there isn't any response from the client in certain time . for example after the 1minute .

hserin has this property! but i am using that port for the other device...

cupajoe
- 30th May 2005, 15:45
Well now. You need two serial ports on a pic that only has one hardware uart. I recently overcame this same problem by using a triple dual channel analog mux/demux (CD4053) between the pic and the max202E. The 202 already has two channels and the 4053 has 3 pairs of switches. I use them for Tx, Rx, and two LEDs. I use a pin on the pic as an output called com. select (CMSL) to toggle which serial port the UART is connected to. I will attach a schematic if the chip with pin discriptors. This works well if you always listen to one port and then after you get data you switch to another. Some ideas if this isn't possible would be to have a pic send data until it gets an ack from the master. Then the master could poll the different pics.

Gotta go.

Hope this helps.

Joe Kupcha

mister_e
- 30th May 2005, 16:44
Use the SERIN2 timeout option. But i feel sure it can't provide that 1 minute delay. So have a Xsecond Timeout delay, once you jump to the Timeout label increment a counter, once the counter reach the right delay... Get out of you SERIN stuff.

uludere72
- 31st May 2005, 08:20
thanx your kind response..

serin serialinputpin, 396,2000,LineX,RX[0]

works with timeout delay . how can ı use serin2 with timeout delay ?

serin2 serialinputpin, 396,2000,LineX,RX[0] didn't work with timeout.

Melanie
- 31st May 2005, 08:50
If either...

1. There is noise on the line (in typical wireless applications)

or

2. The comms line idles in the wrong polarity

You will not timeout from SERIN.

If you did a SEARCH on SERIN and TIMEOUT you will discover a dozen threads on this issue.

uludere72
- 31st May 2005, 10:06
i solve my problem. thx a lot....

here is the solution

......


serout2 serialOutput, 396, ["Report ",hex SlaveSelect]
pause 200

serin2 serialInput, 396,2000,loop,[wait("+"),RX[0]]

If RX[0] != "+" Then ReadPic

loop:
.......
....


ReadPic:
Lcdout $fe, 1, "PIC Reading...."
counter = 1

while counter != 16 'receive 166 char.
serin2 serialinput, 396,[ RX[counter]]
counter = counter+1
Wend

Lcdout $fe, 1,str RX \16 ' recevied data
pause 1000
RX[0]=0
hserout["+",Str RX \15,"+"] ' transmit received data to the other port
hserout [13,10]
pause 100
goto StartPoint
Return