Open riverwilliams94 opened 6 years ago
its not wiring its a code issue, actually an errata with the SPI chips, the first 4 (0,1,2,3) should work fine but 4,5,6,and 7 require a different opcode to initialize. did you tie all reset pins high? diagrams? please use code brackets when posting code, the errata may not apply to you, it may be something else
void MCP23S17::begin() { _spi->begin(); ::pinMode(_cs, OUTPUT); ::digitalWrite(_cs, HIGH); uint8_t cmd = 0b01000000; ::digitalWrite(_cs, LOW); _spi->transfer(cmd); _spi->transfer(IOCONA); _spi->transfer(0x18); ::digitalWrite(_cs, HIGH); writeAll(); }
Issue looks to be here, the library is writing the first opcode but not the second. Also make sure your addresslines are properly configured via appropriate pullups/pulldowns
You then must apply both (0b01000000) OPCODE (in begin(), BUT, the begin should ALSO include OPCODE 0b01001110 (0x4F) to initialize chips 0 -> 3 for OPCODE 0x40 and 4-> 7 for OPCODE 0x4E
Tony
for a quick "software" addressing fix to the errata, in the CPP file you could duplicate the ::writeAll function code and modify the second 0b01000000 to 0b1001110, so when the ::writeAll function runs it does both OPCODE writes to the chips (if the hardware address pins are tied low/high properly and reset is tied high), it should work..... The chips don't care if you write both opcodes to them.
Here's my code, modified from the example code provided
The thing is, Bank3.digitalWrite(i, 1) does not appear to work. Instead, it follows and logic of the first 2. Ex: if Bank1.digitalWrite(i,1) and Bank2.digitalWrite(i,1) then Bank3's pins are pulled high. If either bank1 or bank2's pins are written low, then bank3's pins are pulled low, regardless of what Bank3's digitalWrite says.
I have triple checked my wiring and don't notice any issues
Also, I'm running this code on an ESP32 Devkit