Teensy 4.1 and MCP23S17 question

Sandro

Well-known member
Hi all, in my application I would connect n.6 MCP23S17 to my T4.1, with SPI1 bus, using these pins:
CS1: 38
MISO1: 39
MOSI1: 26
SCK1: 27

The purpose is reading Encoders and pushbutton; here is a sample of my schematics:
sample.png


My requirement are: 1) using the SPI1 bus; 2) read all 16 GPxy pins of a single chip with a single read. (i.e., a full 16-bit read).

I found two libraries, but none of them offers both functionalities:
  • with gpio_MCP23S17 library I can read all GPxy pins of a shifter chip with a single read, but I cannot configure the SPI bus;
  • with Adafruit_MCP23X17 library I can configure the SPI bus, but I cannot read all GPxy pins of a shifter with a single read.

Can anyone suggest another library, or how to make a custom version with one of the previous libraries?

Thank in advance
 
I found two libraries, but none of them offers both functionalities:
  • with gpio_MCP23S17 library I can read all GPxy pins of a shifter chip with a single read, but I cannot configure the SPI bus;
  • with Adafruit_MCP23X17 library I can configure the SPI bus, but I cannot read all GPxy pins of a shifter with a single read.
Can anyone suggest another library, or how to make a custom version with one of the previous libraries?

I googled "github MCP23S17 Arduino" and found this library, which seems to have what you want. I have used some of Rob's libraries and they work well.

 
To access each MCP23S17 individually, you must have 6 separate CS signals. And acivate only one during SPI transfer
 
To access each MCP23S17 individually, you must have 6 separate CS signals. And acivate only one during SPI transfer
Looks from the data sheet as if this is an unusual SPI part which is addressable. Note the A0/1/2 wiring on the posted schematic.
 
Solved.. I din't notice, Adafruit_MCP23X17 has a specific function, which reads all 16 pins:
uint16_t readGPIOAB();

I googled "github MCP23S17 Arduino" and found this library, which seems to have what you want. I have used some of Rob's libraries and they work well.

https://github.com/RobTillaart/MCP23S17
I know this library, and I'd like to use it, because it seems very simple and essential but I've not been able to configure SPI1 as "hardware SPI"
 
Last edited:
Seems easy enough - this looks like the constructor to use:

C++:
MCP23S17(int select, int address = 0x00, __SPI_CLASS__ * spi = &SPI);
Use &SPI1 for the last parameter.

In my case, the SPI1 bus is also used by the display, and managed somewhere inside Adafruit_ILI9341.h library
 
It ought to be possible to have multiple devices on one SPI bus, provided you don't try to access more than one at a time (e.g. by having async display updates running and then reading your encoders); that is kind of the point of SPI having a /CS line for each peripheral. The various Teensy accelerated display drivers do have some issues there, because they assume they know how they left the SPI bus configured, and get confused when it's been changed. If the Arduino display driver, or indeed any SPI-based driver, does the same, then there will be problems.

Best things, as always, is to try a simple example and see if it works! Of course, try each separately before you glue them together...
 
Back
Top