MCU to I/O Expander via SPI

Parts in this Question:
MCU P/N MC9S12DG256CPVE
I/O Expander P/N MCP23S17-E/ML

New to using I/O expanders. When connecting I/O expanders via SPI I believe you need 4 pins:

All I/O Expanders can connect to a common SCK, MISO, and MOSI pin. Meaning only 1 each of these pins are needed even if you had say 6 I/O expanders.

Each I/O expander must have its own dedicated SS pin on the MCU.

  1. Am I interpreting the above correctly?

  2. When reading the MCU data sheet. Section 2.3 calls out generic functionality of each pin. For example, section 2.3.21 says, “PH7 is a general-purpose input or output pin. It can be configured to generate an interrupt causing the MCU to exit STOP or WAIT mode. It can be configured as slave select pin SS of the Serial Peripheral Interface 2 (SPI2).” Are all pins limited to the description called out in the data sheet, or if it says general purpose can I say use other pins as SS pins that don’t call it out in the description? Such as 2.3.19, “PE1 is a general-purpose input pin and the maskable interrupt request input that provides a means of applying asynchronous interrupt requests. This will wake up the MCU from STOP or WAIT mode.”

Hi @manchester49123 ,

The SS pin interrupt is typically used when the MCU’s SPI bus is slave (i.e. the SS pin is input). For the IO-expander, you will configure the SPI I/F as master, thus you can use any GPIO pins for the SS’s.

Cheers, heke

1 Like

Greetings @manchester49123 ,
Yes, your assumptions are correct AFAIK.
Just make sure that only one expander is selected at any time, to prevent race condition at the MISO line.
Also make sure that all the expanders are powered up.
Pay some attention to the GPIO that has the SS as alternative function. I do not know how is it with the MCU that you are using, but e.g. AVR has a nasty feature that when the GPIO for SS is configured as input and it is driven low, the SPI I/F becomes automagically slave.
Cheers, heke

3 Likes