PDA

View Full Version : Haw to connect two pic?



edysan
- 19th August 2007, 10:28
Good day.

I need a suggestion about haw to connect a pic18f2520 (master) with 2 or 3 pic16f876 (slave).
The serial out/in of master are use to connect it to PC.
I was thinking to simulate a I2c connection.

Can any one help me?

Thanks (form Italy)

mat janssen
- 19th August 2007, 12:56
I2C in PBP cannot do master slave.
Just connect them as a serieel port without RS232 ic's.
The master serialout to both slave's serial in and the slave serial out's to the master serial in.
Don't forget to put the slave serial out's in the input mode when doing nothing. Set the slave serial out only to serial out if you have been asked to tell something.

edysan
- 19th August 2007, 13:20
Thanks, I will try this.

I will try to do a better description about what I wont realize, maybe It is an other way.

I have already a pic18f2550 connected with almost all pins, and a internal software with several function.
I need to read 2 or 3 more value, which one are coming from a pic16f876. This value are byte type.
I was thinking to connect all pic's in this way.
When I need the last value I will activate a pin from pic18f2550 like issue, and pic16f876 will respond with his value.

edysan

edysan
- 22nd August 2007, 11:21
I have try the Mat Janssen suggestion, but think is a little bit complicated.

Have anyone some other idea?

Thanks.

mackrackit
- 22nd August 2007, 11:44
Try SERIN2/SEROUT2. Use two pins on each PIC. One pin to SEROUT2 and one to SERIN2. I suggest SERIN2/SEROUT2 because of the time out option.

When PIC #1 is ready for data it will send a signal to PIC #2 from PIN_X.
PIC #2 receives the signal for data on PIN_X.
PIC#2 will then send data one PIN_Y.
PIC#1 receives data on PIN_Y.

BobK
- 23rd August 2007, 03:50
Hi Edysan,

It's not hard to do. What Matt and Dave are telling you is the way to go. I have a display board that is connected to 20 other boards in a card cage. ONE wire is the Serial I/O line. Another wire is the busy line. ALL boards including the display board are programmed as inputs. There is one pull up resistor for this line. The BUSY line is the key to the whole process. If a board wants to send a "byte" sized message to the display board, he first checks the status of the busy line. If it is low then the board stays in a loop checking for the low to go back to high. Once the busy line is free, he makes the busy line low and sends his signal and clears the busy line when finished. Just remember, you make each board an input. The SEROUT2 command makes the pin an output. When done "talking" you make the pin an input again. (TRISB.7 = 1 for example makes B7 an input)

I hope this makes sense. The display board simply stays in a loop looking for the busy line to go low. Once it does it gets the "message", it then makes the busy line low until it's done sending a time stamped message to a printer. Once that's done, then it releases the busy line waiting for the next message.

A gentleman by the name of Steve Collins has a program called "SixPICs" available on the melabs website. MisterE also has posted a similar type of program here on this forum. Steve's (MisterE) program uses a code to address each board. The slaves just sit and wait for their code to be sent out, then they respond. These systems can be made to "talk" to each board in a polling type fashion. The Master sends out the code for a specific board. When that board hears its name, it answers, and waits for the message. When done the Master calls for then next board. It will take you a while to get this going. Start with one to one communications then add another board. It was very frustrating for me but Steve Collins called me and explained how to do it and I was off and running after that.

The two examples I've mentioned should help get you going.

HTH,

BobK

PS Make sure there is a 1K resistor in series with each Serial I/O pin to prevent accidents.

BobK
- 23rd August 2007, 03:52
Sorry for the double posting.

edysan
- 24th August 2007, 08:45
Thanks.

Is exactly what I need.