PDA

View Full Version : interfacing SPI with 2 pins?



modifyit
- 30th November 2005, 20:09
I'm using a 16F877a on a project I am working on and the PCB is already complete and I have 2 GPIOs left over and I need to hook up a device that only has a SPI interface. Does anyone know of a good way of achieving this? I was thinking about trying to find a I2C to SPI bridge, but wanted to know if there way a better way. By the way I do have 5v and ground available as well.

Thanks for any suggestions

Ron Marcus
- 30th November 2005, 20:23
Is your processor a master or slave? You can't select a slave device, but you can combine the shift in/ shift out functions to use the same clock line and data pin. I did this for some PIC to PIC comms. The clock line rode high, when the master wanted to communicate, it would hold the clock line low until the slave pulled the data line low momentarily. Communications then commenced. The master was using PBP with shiftout, and the slave was using assembly for an on screen display. It worked great.

modifyit
- 30th November 2005, 20:43
the pic16f877a would serve as the master in this case. I understand your suggestion and how it would work in pic to pic communications, but I am not sure if it will work with a slave SPI device. I'm trying to connect from the 877a to a Canbus controller MCP2515

Darrel Taylor
- 1st December 2005, 01:34
modifyit,

If you have an LCD in the device, you can multiplex the CLK and data lines with the data lines going to the display.

Actually, if there are any devices in the circuit that are only active with an "Enable" input, then their data lines can be used as well.

The only thing that can't be multiplexed are the CS/Enable pins themselves.
<br>

modifyit
- 1st December 2005, 19:33
I wish I had access to more pins, but all I readily have access to is GND,5V, and 2 GPIOs. I'm guessing it may just not be possible since I need to connect SI,SO,CS,and SCK to my SPI controller.

Darrel Taylor
- 1st December 2005, 20:24
Then you're probably stuck with putting another PIC in there.

Use something like a PIC16F630, and communicate serialy (2-pins), between the PIC's. Then the '630 can talk to the SPI device, with pins left over for other things if you need them.
<br>

modifyit
- 1st December 2005, 22:04
That's what I figured...thanks for the input