Connecting to a Microchip MCP23S17 (SPI) 16 bit I/O expander from a Boron

I need to connect to a MCP23S17 16 bit I/O expander from a Boron over SPI. I’m using the MCP23S17_bd78 library to do so. But upon calling the pinMode the Boron crashes, emitting the Red Flash SOS. Justing including the library is fine. And instantiating the library with MCP mcpExpander(0, 14) is also fine. It’s not until the pinMode is called that the crash occurs.

I have the MCP23S17 A0, A1 and A2 pins connected to ground. And Reset connected to 3.3V. VDD is also connected to 3.3v and VSS to ground. SS is connected to A5 (14) of the Boron. MOSI, MISO and SCK are connected to the primary SPI of the Boron. I’ve rechecked the wiring multiple times. I referenced the diagram located here (which is the Arduino library the Particle lib is based on): https://playground.arduino.cc/Main/MCP23S17/

The library is fairly old, last update on github occurred many years ago, so I assume the library isn’t ready for the Boron. As evidence of this look at line 66 of the MCP23S17.cpp file. SPI_CLOCK_DIV2 is used instead of something like SPI_CLOCK_DIV8 (the MCP23S17 requires a clock speed of less than 10MHz).

I changed the SPI_CLOCK_DIV2 to …DIV8 and recompiled. Still, the crash occurs.

At this point, I’m assuming the SPI library is just out of date. I wish I could switch over to the I2C version of the chip but thats not possible. Has anyone used this library with 3rd gen devices with any luck? Any ideas of alternatives, or specific SPI code to talk directly with the MCP23S17?

Thanks in advance

Does anyone

Have your used this library here
https://build.particle.io/libs/MCP23S17_bd78/0.0.1/tab/MCP23S17.cpp

because in that library DIV8 is used since SPARK is defined.

How many slow blinks are following the initial SOS signal?

Since you already have the sources of the library in your code, you could add some Serial.print() statements (with a delay(100) before any potentially fatal call to allow the output to get delivered) for debugging.

I’d also split out the constructor lines 61…70 into a MCP::begin() function that could/should an SPISettings object to allow for custom SPI settings.

And while at it I’d donate the constructor a take an SPIClass parameter to allow for a selectable SPI interface (e.g. SPI or SPI1).

1 Like

I’ll set up a debugging point tonight this evening. I had assumed SPARK was referring to the spark core, thanks for clarifying that.

10 red blinks after the SOS, apparently an assertion failure

So I broke the constructor lines into a ::begin() method. Now the constructor is just setting base properties.

The begin() method starts by setting the pinMode(_ss_pin, OUTPUT), followed by the SPI.begin and the rest of the lines.

Within the main .ino file I called the constructor of MCP. Then in setup() I call the begin method of the MCP instance.

This seems to be working. I’m getting an LED light lighting up from the MCP23S17 chip. Do keep in mind that the numbering of the pins are NOT as outlined in the datasheet. They are outlined on this document: https://playground.arduino.cc/Main/MCP23S17/ (scroll down to diagram chart). Top left (as indicated by the small physical indent dot on the chip) is 9. Going to 16. Top right begins with 8 going to 1.

I’ll do a pull request on github for breaking the constructor up into a ::begin() method.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.