728x90

728x90

Sunday, February 15, 2026

ATMega644P SPI and MCP23S17 GPIO Expansion Example

Overview 

The MCP23S17 is an SPI 16-bit (two ports) bi-directional GPIO expansion chip. Its TWI version is the MCP23017. It's rich of functions, data direction, control, distinct input and output registers, programmable weak pull up resistors, interrupt capabilities etc. Its configuration setting is very similar to most of PIC micro-controller since it is produced by Microchip Technology.

It contains two 8-bit bi-directional port, GPA and GPB. Both of them are programmable with additional interrupt features. Its two interrupt flag pins correspond to each ports. 

ATMega644P SPI and MCP23S17 GPIO Expansion Example
MCP23S17-E/SP

 The SPI version of this chip is very similar to the I2C version.

ATMega644P SPI and MCP23S17 GPIO Expansion Example

Package Types

Its SPI interface is bi-directional since it's a general purpose I/O chip. Its four SPI pins are Chip Select(CS), Serial Clock(SCK), Serial In(SI) and Serial Out(SO). Its three optional address pins are A2:A0. We can connect them to GND to set the SPI slave write address to 0x40 and 0x41 for read address.

ATMega644P SPI and MCP23S17 GPIO Expansion Example
Functional Block Diagram

 The programmer must configure the following registers to get a proper operation.

ATMega644P SPI and MCP23S17 GPIO Expansion Example
Register Addressed

 By default we don't set the IOCON register the default bank is BANK0 ranges from 0x00 to 0x15. For example the IODIRB locates at 0x01 and its output register OLATB locates at 0x15.

ATMega644P SPI and MCP23S17 GPIO Expansion Example
SPI ADDRESSING REGISTERS

 The idle state of CS pin is high.

ATMega644 and MCP23S17 SPI Programming

The write operations contain three data bytes, slave write address, register address and data. For example to make GPIOA as output we must do the following step:

  1. Set CS pin low
  2. Send its slave address 0x40 (A2:A0=0)
  3. Send IODIRA address 0x00
  4. Send data direction 0x00 that is output direction
  5. Clear CS pin 

The read operation also contains three data bytes, slave read address, register address, any data and read operation.

 

 

 

No comments:

Post a Comment

320x50

Search This Blog

tyro-728x90