{"id":20989853,"url":"https://github.com/robtillaart/mcp23s08","last_synced_at":"2025-05-14T18:32:15.561Z","repository":{"id":45080749,"uuid":"446369143","full_name":"RobTillaart/MCP23S08","owner":"RobTillaart","description":"Arduino library for SPI MCP23S08 8 channel port expander","archived":false,"fork":false,"pushed_at":"2024-07-06T09:09:18.000Z","size":1515,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-07T18:27:16.220Z","etag":null,"topics":["arduino","input-output","spi"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobTillaart.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"RobTillaart","custom":"https://www.paypal.me/robtillaart"}},"created_at":"2022-01-10T10:03:39.000Z","updated_at":"2024-07-06T09:09:00.000Z","dependencies_parsed_at":"2023-11-13T17:25:08.539Z","dependency_job_id":"41475802-b6f9-466f-987a-635af4985ede","html_url":"https://github.com/RobTillaart/MCP23S08","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FMCP23S08","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FMCP23S08/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FMCP23S08/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FMCP23S08/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobTillaart","download_url":"https://codeload.github.com/RobTillaart/MCP23S08/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225305728,"owners_count":17453438,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","input-output","spi"],"created_at":"2024-11-19T06:26:25.611Z","updated_at":"2025-05-14T18:32:15.550Z","avatar_url":"https://github.com/RobTillaart.png","language":"C++","funding_links":["https://github.com/sponsors/RobTillaart","https://www.paypal.me/robtillaart"],"categories":[],"sub_categories":[],"readme":"\n[![Arduino CI](https://github.com/RobTillaart/MCP23S08/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)\n[![Arduino-lint](https://github.com/RobTillaart/MCP23S08/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/MCP23S08/actions/workflows/arduino-lint.yml)\n[![JSON check](https://github.com/RobTillaart/MCP23S08/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/MCP23S08/actions/workflows/jsoncheck.yml)\n[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/MCP23S08.svg)](https://github.com/RobTillaart/MCP23S08/issues)\n\n[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/MCP23S08/blob/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/RobTillaart/MCP23S08.svg?maxAge=3600)](https://github.com/RobTillaart/MCP23S08/releases)\n[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/MCP23S08.svg)](https://registry.platformio.org/libraries/robtillaart/MCP23S08)\n\n\n# MCP23S08\n\nArduino library for MCP23S08 8 channel SPI port expander.\n\n\n## Description\n\nThis library gives easy control over the 8 pins of a (SPI) MCP23S08 chip.\n\nThis IC is strongly related to the MCP23017 I2C port expander - https://github.com/RobTillaart/MCP23017_RT\nProgramming Interface is kept the same as much as possible.\n\nThe **write1(pin, value)** is optimized. \nIf a pin is not changed it will not be written again to save time.\n\n\n### 0.6.0 Breaking change\n\nFix #22, hardware SPI constructor.\nMakes previous versions obsolete.\n\n\n### 0.5.0 Breaking change\n\nVersion 0.5.0 introduced a breaking change to improve handling the SPI dependency.\nThe user has to call **SPI.begin()** or equivalent before calling **MCP.begin()**.\nOptionally the user can provide parameters to the **SPI.begin(...)**\n\n\n### 0.4.0 Breaking change\n\nThe version 0.4.0 has breaking changes in the interface. \nThe rationale is that the programming environment of the **Arduino ESP32 S3** \nboard uses a remapping by means of the include file **io_pin_remap.h**.\nThis file remaps the pins of several core Arduino functions. \nThe remapping is implemented by #define macros and these implement \"hard\" text \nreplacements without considering context. \nThe effect is that methods from this class (and several others) which have the same \nname as those Arduino core functions will be remapped into something not working.\n\nThe following library functions have been renamed:\n\n|  old name        |  new name    |  notes  |\n|:-----------------|:-------------|:--------|\n|  analogRead()    |  read()      |\n|  analogWrite()   |  write()     |\n|  pinMode()       |  pinMode1()  |\n|  digitalRead()   |  read1()     |\n|  digitalWrite()  |  write1()    |\n\n\n### 0.3.0 Breaking change\n\nThe version 0.3.0 has breaking changes in the interface. \nThe essence is removal of ESP32 specific code from the library. \nThis makes it possible to support the ESP32-S3 and other processors in the future. \nAlso it makes the library a bit simpler to maintain.\n\n\n### Related\n\n16 bit port expanders\n\n- https://github.com/RobTillaart/MCP23017_RT  I2C 16 IO lines.\n- https://github.com/RobTillaart/MCP23S17  SPI 16 IO lines.\n- https://github.com/RobTillaart/PCF8575  I2C 16 IO lines.\n- https://github.com/RobTillaart/PCA9671  I2C 16 IO lines. - successor PCF8575\n- https://github.com/RobTillaart/TCA9555  I2C 16 IO lines.\n\n\n8 bit port expanders\n\n- https://github.com/RobTillaart/MCP23008  I2C 8 IO lines.\n- https://github.com/RobTillaart/MCP23S08  SPI 8 IO lines.\n- https://github.com/RobTillaart/PCF8574  I2C 8 IO lines.\n- https://github.com/RobTillaart/TCA9554  I2C 8 IO lines.\n\n\n## Interface\n\n```cpp\n#include \"MCP23S08.h\"\n```\n\n\n### Constructor\n\n- **MCP23S08(uint8_t select, uint8_t dataIn, uint8_t dataOut, uint8_t clock, uint8_t address = 0x00)** constructor SOFTWARE SPI.\n- **MCP23S08(int select, SPIClassRP2040\\* spi)** constructor HARDWARE SPI with explicit SPI interface selected.\n- **MCP23S08(int select, SPIClass\\* spi)** constructor HARDWARE SPI with explicit SPI interface selected.\n- **MCP23S08(int select, int address = 0x00, SPIClassRP2040\\* spi = \u0026SPI)** constructor HARDWARE SPI with optional address pins and SPI interface.\n- **MCP23S08(int select, int address = 0x00, SPIClass\\* spi = \u0026SPI)** constructor HARDWARE SPI with optional address pins and SPI interface.\n- **bool begin(bool pullup = true)** initializes library, returns true if successful. \nDefault sets the pins to INPUT PULLUP.\nReturns false if not connected or a register could not be set.\n- **bool isConnected()** returns true if connected, false otherwise. (dummy for compatibility reasons)\n- **uint8_t getAddress()** returns the address set in the constructor. \nDefault = 0, range = 0..3.\n\n\nThe two hardware constructors allow to call 4 different constructors.\n\n```cpp\n- MCP23S08(10);            //  select pin only\n- MCP23S08(10, 7);         //  select pin + address pins\n- MCP23S08(10, 7, \u0026SPI2);  //  select pin + address pins + SPI port\n- MCP23S08(10, \u0026SPI2);     //  select pin + SPI port\n```\n\n\n#### Sharing SELECT lines\n\n(verified in MCP23S17 issue 19)  \nTechnically two chips could use the same SELECT pin and a different address. \nSince 0.2.0 the constructors allow to setup such a configuration.\nThe added value is that one can use up to 4 devices (= 32 IO lines) with only \nfour lines (MISO, MOSI, CLOCK, SELECT).\n\nI assume that this configuration is less used and IMHO not recommended.\nNB it is more difficult to detect which device is selected when debugging.\n\nTo use the hardware addresses the Hardware Address ENable register must be set.\nSee datasheet 1.6.6 ADDRESSING SPI DEVICES, need to set IOCON.HAEN.\n\nThe library supports two ways:\n```cpp\nMCP.enableControlRegister(MCP23S08_IOCR_HAEN);  //  or 0x08\nor\nMCP.enableHardwareAddress();  //  0.2.0 version and up\n```\n\nSee also **IO Control Register** section below.\n\n\n### Single pin interface\n\n- **bool pinMode1(uint8_t pin, uint8_t mode)** pin = 0..7. \nmode = INPUT, OUTPUT or INPUT_PULLUP. \nDo NOT use 0, 1 for mode as the 3 constants are (possibly) defined differently.\nReturns true if successful.\n- **bool write1(uint8_t pin, uint8_t value)** pin = 0..7, value = LOW(0) HIGH (!0). Returns true if successful.\n- **uint8_t read1(uint8_t pin)** pin = 0..7, returns LOW or HIGH, might set the lastError();\n- **bool setPolarity(uint8_t pin, bool reversed)** pin = 0..7, set reversed flag. Returns true if successful.\n- **bool getPolarity(uint8_t pin, bool \u0026reversed)** pin = 0..7, reads reversed flag. Returns true if successful.\n- **bool setPullup(uint8_t pin, bool pullup)** pin = 0..7, set pull-up flag. Returns true if successful.\n- **bool getPullup(uint8_t pin, bool \u0026pullup)** pin = 0..7, reads pull-up flag.Returns true if successful.\n\n\n### 8 pins interface\n\n- **bool pinMode8(uint8_t mask)** mask = 0..255. Returns true if successful.\nReturns true if successful.\n- **bool write8(uint8_t value)** value = 0..255. Returns true if successful.\nReturns true if successful.\n- **uint8_t read8()** reads 8 pins into one byte.\n- **bool setPolarity8(uint8_t mask)** sets polarity for 8 channels at once.\nReturns true if successful.\n- **bool getPolarity8(uint8_t \u0026mask)** reads polarity of 8 channels at once.\nReturns true if successful.\n- **bool setPullup8(uint8_t mask)** sets pull-up for 8 channels at once.\nReturns true if successful.\n- **bool getPullup8(uint8_t \u0026mask)** reads pull-up for 8 channels at once.\nReturns true if successful.\n\n\n### Interrupts (experimental 0.5.2)\n\nRead the datasheet for the details. Page 21.  \nNote: Error handling is limited.\n\npin = 0..7  \nmode = { RISING, FALLING, CHANGE }  \n- **bool enableInterrupt(uint8_t pin, uint8_t mode)** \nReturns true if successful.\nReturns MCP23S17_PIN_ERROR if pin \u003e 7.\n- **bool disableInterrupt(uint8_t pin)**\nReturns true if successful.\nReturns MCP23S17_PIN_ERROR if pin \u003e 7.\n\n\nDetermine which pins caused the Interrupt. (datasheet).\n- **uint8_t getInterruptFlagRegister()** Reads all 8 pins.\n- **uint8_t getInterruptCaptureRegister()** Reads all 8 pins.\nIs used to detect if multiple pins triggered an interrupt.\n\n\n- **bool setInterruptPolarity(uint8_t ipol)** polarity: 0 = LOW, 1 = HIGH, 2 = NONE/ODR\n- **uint8_t getInterruptPolarity()** return set value.\n\n\n### SPI\n\n- **void setSPIspeed(uint32_t speed)** set hardware speed (8Mb default).\n- **uint32_t getSPIspeed()** returns set speed.\n\n\n### Debugging\n\n- **bool usesHWSPI()** returns true = hardware SPI, false = software SPI.\n- **int lastError()** idem.\n\n\n### IO Control Register\n\nThe library supports setting bit fields in the IO control register.\nRead the datasheet carefully!\n\n- **bool enableControlRegister(uint8_t mask)** set IOCR bit fields\n- **bool disableControlRegister(uint8_t mask)** clear IOCR bit fields\n\n\n|  constant              |  mask  |  description  |\n|:-----------------------|:------:|:--------------|\n|  MCP23S08_IOCR_BANK    |  0x80  |  Controls how the registers are addressed.\n|  MCP23S08_IOCR_MIRROR  |  0x40  |  INT Pins Mirror bit.\n|  MCP23S08_IOCR_SEQOP   |  0x20  |  Sequential Operation mode bit.\n|  MCP23S08_IOCR_DISSLW  |  0x10  |  Slew Rate control bit for SDA output.\n|  MCP23S08_IOCR_HAEN    |  0x08  |  Hardware Address Enable bit (MCP23S17 only).\n|  MCP23S08_IOCR_ODR     |  0x04  |  Configures the INT pin as an open-drain output.\n|  MCP23S08_IOCR_INTPOL  |  0x02  |  This bit sets the polarity of the INT output pin.\n|  MCP23S08_IOCR_NI      |  0x01  |  Not implemented. \n\n\nTwo dedicated functions are added: (MCP23S08 only)\n\n- **bool enableHardwareAddress()** set IOCR_HAEN  bit.\n- **bool disableHardwareAddress()** clear IOCR_HAEN bit.\n\n\n### Error codes\n\nIf one of the above functions return false, there might be an error.\n\n- **int lastError()** Above functions set an error flag that can be read with this function.  \nReading it will reset the flag to **MCP23S08_OK**.\n\n|  name                     |  value  |  description  |\n|:--------------------------|:-------:|:--------------|\n|  MCP23S08_OK              |  0x00   |  No error     |\n|  MCP23S08_PIN_ERROR       |  0x81   |\n|  MCP23S08_SPI_ERROR       |  0x82   |\n|  MCP23S08_VALUE_ERROR     |  0x83   |\n|  MCP23S08_PORT_ERROR      |  0x84   |\n|  MCP23S08_REGISTER_ERROR  |  0xFF   |  low level.\n|  MCP23S08_INVALID_READ    |  0xFF   |  low level.\n\n\n## Future\n\n#### Must\n\n- keep documentation in sync with MCP23S17\n\n#### Should\n\n- keep functional in sync with MCP23017_RT and MCP23S17\n\n#### Could\n\n- ESP32 example code\n\n#### Wont\n\n\n## Support\n\nIf you appreciate my libraries, you can support the development and maintenance.\nImprove the quality of the libraries by providing issues and Pull Requests, or\ndonate through PayPal or GitHub sponsors.\n\nThank you,\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobtillaart%2Fmcp23s08","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobtillaart%2Fmcp23s08","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobtillaart%2Fmcp23s08/lists"}