0.2.4 MCP23S17

This commit is contained in:
rob tillaart 2023-02-04 16:29:14 +01:00
parent 714e5368f7
commit 0c634c511d
12 changed files with 80 additions and 53 deletions

View File

@ -6,7 +6,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update

View File

@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6

View File

@ -10,7 +10,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:

View File

@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.2.4] - 2023-02-04
- update readme.md
- update GitHub actions
- update license 2023
## [0.2.3] - 2022-10-20
- add CHANGELOG.md
- add **enableControlRegister(uint8_t mask)**
@ -21,21 +27,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- add getAddress() + optimized (_address << 1)
- update readme.md
## [0.2.0] - 2022-06-28
## [0.2.0] - 2022-06-28
- fix #10 incorrect mask
----
## [0.1.3] - 2022-04-13
## [0.1.3] - 2022-04-13
- fix compiling for NANO33 BLE
## [0.1.2] - 2022-01-12
## [0.1.2] - 2022-01-12
- change the URL for library manager
## [0.1.1] - 2022-01-10
## [0.1.1] - 2022-01-10
- add 16 bit interface
## [0.1.0] - 2021-12-30
## [0.1.0] - 2021-12-30
- initial version (a 2019 version did not make it)

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2021-2022 Rob Tillaart
Copyright (c) 2021-2023 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,12 +1,10 @@
//
// FILE: MCP23S17.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.2.3
// VERSION: 0.2.4
// PURPOSE: Arduino library for SPI MCP23S17 16 channel port expander
// DATE: 2021-12-30
// URL: https://github.com/RobTillaart/MCP23S17
//
// HISTORY see changelog.md
#include "MCP23S17.h"
@ -47,7 +45,8 @@ bool MCP23S17::begin()
::pinMode(_select, OUTPUT);
::digitalWrite(_select, HIGH);
_spi_settings = SPISettings(_SPIspeed, MSBFIRST, SPI_MODE0); // 8 MHz - datasheet page 8
// 8 MHz - datasheet page 8
_spi_settings = SPISettings(_SPIspeed, MSBFIRST, SPI_MODE0);
if (_hwSPI)
{
@ -68,9 +67,9 @@ bool MCP23S17::begin()
if (! isConnected()) return false;
// disable address increment (datasheet P20
// SEQOP: Sequential Operation mode bit
// 1 = Sequential operation disabled, address pointer does not increment.
// 0 = Sequential operation enabled, address pointer increments.
// SEQOP: Sequential Operation mode bit
// 1 = Sequential operation disabled, address pointer does not increment.
// 0 = Sequential operation enabled, address pointer increments.
if (! writeReg(MCP23S17_IOCR, MCP23S17_IOCR_SEQOP)) return false;
// Force INPUT_PULLUP
@ -391,7 +390,7 @@ int MCP23S17::read8(uint8_t port)
}
_error = MCP23S17_OK;
if (port == 0) return readReg(MCP23S17_GPIO_A);
return readReg(MCP23S17_GPIO_B); // port == 1
return readReg(MCP23S17_GPIO_B); // port == 1
}
@ -606,7 +605,7 @@ bool MCP23S17::writeReg(uint8_t reg, uint8_t value)
{
_mySPI->beginTransaction(_spi_settings);
// _address already shifted
_mySPI->transfer(MCP23S17_WRITE_REG | _address );
_mySPI->transfer(MCP23S17_WRITE_REG | _address );
_mySPI->transfer(reg);
_mySPI->transfer(value);
_mySPI->endTransaction();
@ -675,5 +674,5 @@ uint8_t MCP23S17::swSPI_transfer(uint8_t val)
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -2,7 +2,7 @@
//
// FILE: MCP23S17.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.3
// VERSION: 0.2.4
// PURPOSE: Arduino library for SPI MCP23S17 16 channel port expander
// DATE: 2021-12-30
// URL: https://github.com/RobTillaart/MCP23S17
@ -12,7 +12,7 @@
#include "SPI.h"
#include "MCP23S17_registers.h"
#define MCP23S17_LIB_VERSION (F("0.2.3"))
#define MCP23S17_LIB_VERSION (F("0.2.4"))
// ERROR CODES
#define MCP23S17_OK 0x00
@ -32,9 +32,9 @@ const uint32_t MCP23S17_MAX_SPI_SPEED = 10000000;
class MCP23S17
{
public:
// SW SPI
// SOFTWARE SPI
MCP23S17(uint8_t select, uint8_t dataIn, uint8_t dataOut, uint8_t clock, uint8_t address = 0x00);
// HW SPI
// HARDWARE SPI
MCP23S17(uint8_t select, SPIClass* spi);
MCP23S17(uint8_t select, uint8_t address = 0x00, SPIClass* spi = &SPI);
@ -118,5 +118,5 @@ private:
};
// -- END OF FILE --
// -- END OF FILE --

View File

@ -42,5 +42,5 @@
#define MCP23S17_IOCR_NI 0x01 // Not implemented.
// -- END OF FILE --
// -- END OF FILE --

View File

@ -19,19 +19,39 @@ This IC is strongly related to the MCP23017 I2C port expander - https://github.c
Programming Interface is kept the same as much as possible.
#### Related
16 bit port expanders
- https://github.com/RobTillaart/MCP23017_RT
- https://github.com/RobTillaart/MCP23S17
- https://github.com/RobTillaart/PCF8575
8 bit port expanders
- https://github.com/RobTillaart/MCP23008
- https://github.com/RobTillaart/MCP23S08
- https://github.com/RobTillaart/PCF8574
## Interface
```cpp
#include "MCP23S17.h"
```
### Constructor
- **MCP23S17(uint8_t select, uint8_t dataIn, uint8_t dataOut, uint8_t clock, uint8_t address = 0x00)** constructor SW SPI.
- **MCP23S17(uint8_t select, SPIClass\* spi)** constructor HW SPI with explicit SPI interface selected.
- **MCP23S17(uint8_t select, uint8_t address = 0x00, SPIClass\* spi = &SPI)** constructor HW SPI with optional address pins and SPI interface.
- **MCP23S17(uint8_t select, uint8_t dataIn, uint8_t dataOut, uint8_t clock, uint8_t address = 0x00)** constructor SOFTWARE SPI.
- **MCP23S17(uint8_t select, SPIClass\* spi)** constructor HARDWARE SPI with explicit SPI interface selected.
- **MCP23S17(uint8_t select, uint8_t address = 0x00, SPIClass\* spi = &SPI)** constructor HARDWARE SPI with optional address pins and SPI interface.
- **bool begin()** returns true if successful.
- **bool isConnected()** returns true if connected, false otherwise. (dummy for compatibility reasons)
- **uint8_t getAddress()** returns the address set in the constructor.
Default = 0, range = 0..7.
The two constructors allow to call 4 different constructors.
The two hardware constructors allow to call 4 different constructors.
```cpp
- MCP23S17(10); // select pin only
@ -103,14 +123,15 @@ Read the datasheet carefully!
| constant | mask | description |
|:-----------------------|:------:|:--------------|
| MCP23S17_IOCR_BANK | 0x80 | Controls how the registers are addressed.
| MCP23S17_IOCR_MIRROR | 0x40 | INT Pins Mirror bit.
| MCP23S17_IOCR_SEQOP | 0x20 | Sequential Operation mode bit.
| MCP23S17_IOCR_DISSLW | 0x10 | Slew Rate control bit for SDA output.
| MCP23S17_IOCR_HAEN | 0x08 | Hardware Address Enable bit (MCP23S17 only).
| MCP23S17_IOCR_ODR | 0x04 | Configures the INT pin as an open-drain output.
| MCP23S17_IOCR_INTPOL | 0x02 | This bit sets the polarity of the INT output pin.
| MCP23S17_IOCR_NI | 0x01 | Not implemented.
| MCP23S17_IOCR_BANK | 0x80 | Controls how the registers are addressed.
| MCP23S17_IOCR_MIRROR | 0x40 | INT Pins Mirror bit.
| MCP23S17_IOCR_SEQOP | 0x20 | Sequential Operation mode bit.
| MCP23S17_IOCR_DISSLW | 0x10 | Slew Rate control bit for SDA output.
| MCP23S17_IOCR_HAEN | 0x08 | Hardware Address Enable bit (MCP23S17 only).
| MCP23S17_IOCR_ODR | 0x04 | Configures the INT pin as an open-drain output.
| MCP23S17_IOCR_INTPOL | 0x02 | This bit sets the polarity of the INT output pin.
| MCP23S17_IOCR_NI | 0x01 | Not implemented.
### Error codes
@ -119,14 +140,14 @@ If one of the above functions return false, there might be an error.
- **int lastError()** Above functions set an error flag that can be read with this function.
Reading it will reset the flag to **MCP23S17_OK**.
| NAME | VALUE | DESCRIPTION |
|:------------------------|:------:|:------------|
| MCP23S17_OK | 0x00 | No error |
| MCP23S17_PIN_ERROR | 0x81 |
| MCP23S17_I2C_ERROR | 0x82 | (compatibility)
| MCP23S17_VALUE_ERROR | 0x83 |
| MCP23S17_PORT_ERROR | 0x84 |
| MCP23S17_REGISTER_ERROR | 0xFF | low level.
| name | value | description |
|:--------------------------|:-------:|:--------------|
| MCP23S17_OK | 0x00 | No error |
| MCP23S17_PIN_ERROR | 0x81 |
| MCP23S17_I2C_ERROR | 0x82 | (compatibility)
| MCP23S17_VALUE_ERROR | 0x83 |
| MCP23S17_PORT_ERROR | 0x84 |
| MCP23S17_REGISTER_ERROR | 0xFF | low level.
## Operation
@ -136,16 +157,15 @@ See examples.
## Future
#### must
#### Must
- improve documentation
- references to I2C version?
#### should
#### Should
- keep functional in sync with MCP23017_RT
#### could
#### Could
- check need for writing in all functions (Polarity / pullup)
- check if bit mask changes.
@ -155,7 +175,7 @@ See examples.
- SW_SPI is roughly equal in performance as HW SPI on ESP32.
- investigate and reimplement the INPUT_PULLUP for pinMode() ?
#### wont
#### Wont
- check address range in constructor.

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/MCP23S17.git"
},
"version": "0.2.3",
"version": "0.2.4",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=MCP23S17
version=0.2.3
version=0.2.4
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for SPI MCP23S17 16 channel port expander 16 IO-lines

View File

@ -259,4 +259,6 @@ unittest(test_SPIspeed)
unittest_main()
// --------
// -- END OF FILE --