Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"C_Cpp.errorSquiggles": "disabled"
}
18 changes: 7 additions & 11 deletions MCP23S08.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@ MCP23S08::MCP23S08(SPIClass & spi,


void MCP23S08::begin() {
// Why do we initialize the pin here
// yet expect the spi bus to be initialized?
pinMode(csPin, OUTPUT);
/* Why do we initialize the pin here
yet expect the spi bus to be initialized?
Good question, not sure but, maybe the ESP32 SPI is not yet inialised.*/

pinMode(csPin, OUTPUT); // Required for ESP32 devices.

// enable chip hardware addresses
if (haen) {
spi.beginTransaction(spi_settings);
digitalWrite(csPin, LOW);
spi.transfer(0x40); // command write, address 0 (hardware addressing is disabled on POR)
spi.transfer(MCP23S08_IOCON);
spi.transfer(0x08);
digitalWrite(csPin, HIGH);
spi.endTransaction();
writeRegister(MCP23S08_IOCON, MCP23S08_IOCON_HAEN);
}
}

Expand All @@ -49,7 +45,7 @@ void MCP23S08::reset() {
spi.transfer(0xFF); // reset first register
for (uint8_t i = 0; i < MCP23S08_OLAT; i++) {
if (haen && (MCP23S08_IOCON == i))
spi.transfer(0x08); // enable hardware address (HAEN)
spi.transfer(MCP23S08_IOCON_HAEN); // enable hardware address (HAEN)
else
spi.transfer(0x00); // reset other 10 registers
}
Expand Down
2 changes: 2 additions & 0 deletions MCP23S08.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#ifndef __MCP23S08_h__
#define __MCP23S08_h__

#include "Arduino.h" // Required for ESP32 devices.
#include <SPI.h>


Expand All @@ -25,6 +26,7 @@
#define MCP23S08_INTCAP 0x08
#define MCP23S08_GPIO 0x09
#define MCP23S08_OLAT 0x0A
#define MCP23S08_IOCON_HAEN 0x08


class MCP23S08 {
Expand Down