SPI versus I2C GPIO expander

Could anyone offer advice as to why using the I2C version of a GPIO expander (MCP23017) rather than the SPI might be preferred? SPI works faster, albeit connection lengths need to be short.

And

  • SPI requires more pins
  • SPI has different modes which might interfere with other SPI devices if they don’t share the same mode, since on-the-fly mode switching does not always work smoothly

If I2C speed is fast enough, I’d go for the ease of use.

1 Like

I have been evaluating building boards for GPIO expansion and for current monitoring and control. SPI peripheral devices - I drive tft screens - these work really well and combining with say an SPI rfid tag reader and SD card reader all works fine. You have to keep the distance from the photon to the device really short to avoid problems. I get the point about the chip select pin for each peripheral with SPI whereas I2C is address space driven. For a GPIO expander I was wondering whether the slower speed of I2C would be an issue or not - responsiveness?

Could you expand on the SPI modes? Possible I have come across these but not appreciated. The other negative of SPI is that all devices need to work at the same clock speed - that might be much slower for for one than another.

@armor, SPI modes refer to which edge of the SCK the data is clocked on. I suggest you read:

It may be more useful if you describe what you want to do with the expanded GPIO. That way, our advice can be more specific. :smiley:

@armor you may want to look a https://www.controleverything.com/ they have a lot of boards that may help do what you want. Most are I2C, they have relays, current monitors, ADCs, DACs, multiplexors, XBee etc.

They have screw shields that help with connections, most modules work with Particle Photons, Electrons, Raspberry Pi’s, Omega Onions, Arduinos, and Beagle Bones.

I do recommend buying the electron versions of boards the you want to use for the main controller (It works with both the photon and the electron).

Chuck

1 Like

@carbuthn

Thanks for the link - I have seen this company and my question at the start of this thread came from wanting to understand from the Particle photon/electron community their experience with using each bus to inform me in deciding to use either SPI or I2C. Control Everything have standardised on I2C. I might ask them why.

Thanks for reminding me about Google and Wikipedia :grinning:! I really appreciate any insights. I have found comparisons of I2C and SPI but what I was after was some more Particle Photon/Electron specific experience sharing from the gurus. Is the I2C/Wire working OK in all circumstances. I have seen posts about problems - putting software and hardware together does I2C make more or less sense than SPI and in which situations.

As to what I want to do with expanded GPIO - the same as I am using GPIO for now - read digital and write digital switches/controls. Possibly, PWM control. I don’t think I am going to change my use of SPI for TFT displays and SD card reading because of the speed for such streaming but I2C for other register based comms to peripherals seems the way to go. Thanks again.