I have a PIC16F877 µController, connected via SPI to a MCP23S17 and the last it connected to an keypad and LCD screen, the distance between the µController and the MCP integrated circuit is 5m. My question is will it work or not? And if it does not work how can I resolve this problem. Is there a solution (like a Integrated Circuit or a trick)?


  • 1
    \$\begingroup\$ SPI is designed for on-PCB communications.. this is as terrible idea, perhaps you can find an alternative and more appropriate communication method which is designed for off-board communications or at least longer distance, like I2C \$\endgroup\$ – KyranF Apr 6 '15 at 20:14
  • 4
    \$\begingroup\$ @KyranF I2C is inter-integrated circuit, it is not designed for off board or long distance. An unassisted SPI bus would be better suited for off-board communication than an unassisted I2C bus would. \$\endgroup\$ – Samuel Apr 6 '15 at 20:19
  • \$\begingroup\$ @KyranF I'll second what Samuel said. Since I2C is an open-collector bus, plain I2C has more long-distance problems than plain SPI. \$\endgroup\$ – Nick Alexeev Apr 6 '15 at 20:33
  • \$\begingroup\$ I2C has many great additions that allow it to go quite a fair way. It's also voltage-invariant, making you able to chose higher and more noise-resistant voltage levels. \$\endgroup\$ – KyranF Apr 6 '15 at 20:50
  • \$\begingroup\$ If the OP has the option, going for something like RS232 or 485 (better) would beat trying to make on-PCB style comms such as SPI and I2C do something they aren't meant to.. \$\endgroup\$ – KyranF Apr 6 '15 at 20:54

In an answer on a Microchip forum, Jan Axelson, author of 'Serial Port Complete', claims a maximum cable length of 10' for the SPI bus. Other posts have mentioned the same figure. So your distance of 5m may or may not work since it is just a little longer.

Another answer on the same forum recommends using 120- ohm terminating resistors on the lines.

There are several recommendations in discussion of this topic that say a big factor is reducing the clock speed, down to as little as 100 kHz. Then look at your signals with an oscilloscope.

One way to increase the distance way beyond your requirements is to use digital isolators and twisted pair drivers as discussed in this article: "Extending the SPI bus for long-distance communication" It claims a distance of 100m (not a typo).

|improve this answer|||||

You could use LVDS drivers and receivers to convert the single-ended logic signals into differential signals. Most reliable for a single drop setup (from the board to the external board only), and it requires the grounds to be close to each other in potential.

Use twisted pairs (for example, Cat5 cable) and make sure you use appropriate terminations or it won't work reliably, if at all.


|improve this answer|||||

It's possible with translating the data between the modules by using a trans receiver drivers ex. RS485 something like this

enter image description here


You need to use couple of this trans receiver, the idea is for illustration only you can use any trans driver that pack dual drivers and best suit your need

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.