Skip to content

Commit 40df8ff

Browse files
authored
Merge pull request #88 from alexmaurer-madis/master
Add enableAddrPins() for MCP23X08
2 parents bf7eddb + 25ae252 commit 40df8ff

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ To install, use the Arduino IDE Library Manager.
1616

1717
When using single pin operations such as _pinMode(pinId, dir)_ or _digitalRead(pinId)_ or _digitalWrite(pinId, val)_ then the pins are addressed using the ID's below. For example, for set the mode of _GPB0_ then use _pinMode(8, ...)_. **NOTE** The MCP23008 and MCP23S08 only have _GPAx_ pins.
1818

19-
MCP23x08 Pin # | MCP23x17 Pin # | Pin Name | Pin ID
20-
:-------------:|:--------------:|:--------:|:-------:
21-
10 | 21 | GPA0 | 0
22-
11 | 22 | GPA1 | 1
23-
12 | 23 | GPA2 | 2
24-
13 | 24 | GPA3 | 3
25-
14 | 25 | GPA4 | 4
26-
15 | 26 | GPA5 | 5
27-
16 | 27 | GPA6 | 6
28-
17 | 28 | GPA7 | 7
29-
-- | 1 | GPB0 | 8
30-
-- | 2 | GPB1 | 9
31-
-- | 3 | GPB2 | 10
32-
-- | 4 | GPB3 | 11
33-
-- | 5 | GPB4 | 12
34-
-- | 6 | GPB5 | 13
35-
-- | 7 | GPB6 | 14
36-
-- | 8 | GPB7 | 15
19+
| MCP23x08 Pin # | MCP23x17 Pin # | Pin Name | Pin ID |
20+
| :------------: | :------------: | :------: | :----: |
21+
| 10 | 21 | GPA0 | 0 |
22+
| 11 | 22 | GPA1 | 1 |
23+
| 12 | 23 | GPA2 | 2 |
24+
| 13 | 24 | GPA3 | 3 |
25+
| 14 | 25 | GPA4 | 4 |
26+
| 15 | 26 | GPA5 | 5 |
27+
| 16 | 27 | GPA6 | 6 |
28+
| 17 | 28 | GPA7 | 7 |
29+
| -- | 1 | GPB0 | 8 |
30+
| -- | 2 | GPB1 | 9 |
31+
| -- | 3 | GPB2 | 10 |
32+
| -- | 4 | GPB3 | 11 |
33+
| -- | 5 | GPB4 | 12 |
34+
| -- | 6 | GPB5 | 13 |
35+
| -- | 7 | GPB6 | 14 |
36+
| -- | 8 | GPB7 | 15 |
3737

3838
# Use of HW address pins for SPI device
3939

@@ -43,7 +43,7 @@ To use it provide HW address to begin_SPI(CS, SPI, HW_ADDR) function, and as a r
4343
Example:
4444
mcp.begin_SPI(10, &SPI, 0b101);
4545

46-
MCP23S08 uses addr pins by default. For MCP23S17 address recognition must be enabled by enableAddrPins() function. **NOTE** Calling enableAddrPins() will enable IOCON.HAEN bit for all active (CS low) devices on SPI bus.
46+
HW Address recognition must be enabled by enableAddrPins() function. **NOTE** Calling enableAddrPins() will enable IOCON.HAEN bit for all active (CS low) devices on SPI bus.
4747
**NOTE**
4848
There is hardware bug in the MCP23S17 chip, see "MCP23S17 Rev. A Silicon Errata".
4949
As a result, if using device with A2 = high, and not using addressing, hw address must be set to 0b1XX

src/Adafruit_MCP23X08.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,24 @@
99
@brief default ctor.
1010
*/
1111
/**************************************************************************/
12-
Adafruit_MCP23X08::Adafruit_MCP23X08() { pinCount = 8; }
12+
Adafruit_MCP23X08::Adafruit_MCP23X08() { pinCount = 8; }
13+
14+
/**************************************************************************/
15+
/*!
16+
@brief Enable usage of HW address pins (A0, A1) on MCP23S08
17+
18+
Send this message as first message after chip init.
19+
20+
By default HW address pins are disabled.
21+
(Register IOCON, bit HAEN = 0 on chip reset)
22+
*/
23+
/**************************************************************************/
24+
void Adafruit_MCP23X08::enableAddrPins() {
25+
if (!spi_dev) // I2C dev always use addr, only makes sense for SPI dev
26+
return;
27+
28+
Adafruit_BusIO_Register GPIOAddr(i2c_dev, spi_dev, MCP23XXX_SPIREG,
29+
getRegister(MCP23XXX_IOCON, 0), 2);
30+
31+
GPIOAddr.write((1 << 3), 1);
32+
}

src/Adafruit_MCP23X08.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
class Adafruit_MCP23X08 : public Adafruit_MCP23XXX {
1616
public:
1717
Adafruit_MCP23X08();
18+
19+
void enableAddrPins();
1820
};
1921

2022
#endif

0 commit comments

Comments
 (0)