Adafruit MCP23017 library and MCP23S17 addressing

Hello.
I want to use Adafruit MCP23017 library to control MCP23S17 (SPI version also it's supported in this library) but I don't now it is possible to use couple of mcp23S17 with one CS pin. I dont know how to set software address to each of expander (physically I set address by pins A0,A1,A2). It is possible with this library?

From the datasheet

3.3.2 ADDRESSING SPI DEVICES
(MCP23S17)
The MCP23S17 is a slave SPI device. The slave
address contains four fixed bits and three user-defined
hardware address bits (if enabled via IOCON.HAEN)
(pins A2, A1 and A0) with the read/write bit filling out
the control byte. Figure 3-5 shows the control byte
format. The address pins should be externally biased
even if disabled (IOCON.HAEN = 0).

So several SPI devices can be controlled with a single /CS pin. Look at Figure 3-5: SPI CONTROL BYTE FORMAT

You will need to study the Adafruit library source code to see how it handles SPI devices.

I have only used MCP23017 I2C version. And only with Wire.h not with Adafruit library.

David.

I know that it's possible but i think not with this library...

Hi, @pawel3410

What model Arduino are you using?
What is your project?
What 23017 modules do you have?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

From the header

bool begin_SPI(uint8_t cs_pin, SPIClass *theSPI = &SPI);

So it expects you to use a different /CS for each 23S17 device.

Quite honestly, these libraries make life difficult.

It is much easier to write your own code for I2C using Wire.h
Or your own code for SPI using SPI.h

Let's face it. A Port expander requires nothing more than write_value_to_register() and read_value_from_register() functions.

If you have multiple devices, you add a device argument.

David.

p.s. Google found https://github.com/MajenkoLibraries/MCP23S17

MCP23S17(SPIClass &spi, uint8_t cs, uint8_t addr);

which looks as if it uses the address pins.

Hi, @pawel3410
In hindsight for your application, MCP23017, the I2C version would have been better?

Are you committed to the SPI version or can you get the I2C version?

What is your project?
What is the application?
What pins do you have spare?
What model Arduino are you using?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

@TomGeorge
I alredy have expanders with MCP23S17 so I can't change it. I'm writing program for ESP32. My firsh chose was Adafruit library because its support expanders on I2C and SPI. First I want to use existing expanders module wits SPI and later change them for I2C. With this library it schould be easy, without big change in program after change expanders. But not situation is more complicated because this SPI adressing.

Sorry I didn't read your last post.

The library suggested by @david_prentice has an example in it called EchoInput which apparently uses 2 MCP23S17 devices:

// Create an object for each chip
// Bank1 uses address 0: Pins A0,A1,A2 ground.
// Bank2 uses address 1: Pin A0=VCC, A1,A2 ground.
// Increase the addresses by 2 for each BA value.
MCP23S17 Bank1(&SPI, chipSelect, 0);
MCP23S17 Bank2(&SPI, chipSelect, 1);

I've not used that library but give it a go.