From d16c2c5bd02529985712393288ab249c2b9684b2 Mon Sep 17 00:00:00 2001 From: Geoff Smith Date: Sat, 1 Oct 2022 16:41:24 +1000 Subject: [PATCH 1/5] Use DeviceOpCode when setting HAEN --- MCP23S08.cpp | 10 ++-------- MCP23S08.h | 1 + 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/MCP23S08.cpp b/MCP23S08.cpp index fa75539..2f1f0f0 100644 --- a/MCP23S08.cpp +++ b/MCP23S08.cpp @@ -29,13 +29,7 @@ void MCP23S08::begin() { // 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); } } @@ -49,7 +43,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 } diff --git a/MCP23S08.h b/MCP23S08.h index b106b90..cd63c58 100644 --- a/MCP23S08.h +++ b/MCP23S08.h @@ -25,6 +25,7 @@ #define MCP23S08_INTCAP 0x08 #define MCP23S08_GPIO 0x09 #define MCP23S08_OLAT 0x0A +#define MCP23S08_IOCON_HAEN 0x08 class MCP23S08 { From 3b4157474bb573fc851c0894075e9c4064a28a81 Mon Sep 17 00:00:00 2001 From: Geoff Smith Date: Sat, 1 Oct 2022 16:51:21 +1000 Subject: [PATCH 2/5] Add #include "Arduino.h" --- MCP23S08.h | 1 + 1 file changed, 1 insertion(+) diff --git a/MCP23S08.h b/MCP23S08.h index cd63c58..b0e6b5c 100644 --- a/MCP23S08.h +++ b/MCP23S08.h @@ -10,6 +10,7 @@ #ifndef __MCP23S08_h__ #define __MCP23S08_h__ +#include "Arduino.h" #include From 3aca7d58c49ebe41b71e8464d5dc8a65dfe3bb4f Mon Sep 17 00:00:00 2001 From: Geoff Smith Date: Sun, 2 Oct 2022 13:33:31 +1100 Subject: [PATCH 3/5] Update MCP23S08.h --- MCP23S08.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCP23S08.h b/MCP23S08.h index b0e6b5c..3e96d96 100644 --- a/MCP23S08.h +++ b/MCP23S08.h @@ -10,7 +10,7 @@ #ifndef __MCP23S08_h__ #define __MCP23S08_h__ -#include "Arduino.h" +#include "Arduino.h" // Required for ESP32 devices. #include From f268760722c085a5f1fa44d5a397fe1dfda9861b Mon Sep 17 00:00:00 2001 From: Geoff Smith Date: Sun, 2 Oct 2022 13:39:05 +1100 Subject: [PATCH 4/5] Update MCP23S08.cpp Add comment. --- MCP23S08.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/MCP23S08.cpp b/MCP23S08.cpp index 2f1f0f0..982dd36 100644 --- a/MCP23S08.cpp +++ b/MCP23S08.cpp @@ -23,9 +23,11 @@ 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) { From 3b57813fb428f67eface79feb172c4d67e03b6bc Mon Sep 17 00:00:00 2001 From: Geoff Smith Date: Thu, 28 Sep 2023 15:31:25 +1000 Subject: [PATCH 5/5] Removes error squiggles in vscode. --- .vscode/settings.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..70e34ec --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "C_Cpp.errorSquiggles": "disabled" +} \ No newline at end of file