julianschuler / MCP23S08

Arduino library for the MCP23S08 SPI I/O expander
MIT License
1 stars 3 forks source link

Pins not latching #2

Closed steeley closed 1 year ago

steeley commented 3 years ago

Tested on Teensy 3.2, Arduino 1.8.13

Seems digitalWriteIO only works on 1 pin at a time. Is this correct?

if you set pin 0 high for example, and then set pin pin 4 high, pin 0 goes low.

Only this function seems to work for setting multiple pins: // set pin 0 and 4 expander.setOutputStates(B00010001);

fdxrate commented 3 years ago

I don't see this issue when setting pins high. From my experience, pins that are set HIGH stay high until either they are set LOW or there is a power-down.

This is the code I used to test the pins...

include

include

define CS_PIN 5

MCP23S08 expander(CS_PIN);

void setup() { SPI.begin(); expander.begin(); for (uint8_t pin = 0; pin < 8; pin++) { expander.pinModeIO(pin, OUTPUT); } expander.setOutputStates(B00000000); }

void loop() { expander.digitalWriteIO(0, HIGH); delay(1000); expander.digitalWriteIO(3, HIGH); delay(1000); }

monoidk commented 2 years ago

Function digitalWriteIO does a read-modify-write, reading current state from the MCP itself, rather than saving the expected settings locally. If your pins get reset, it seems likely your return channel (MCP -> MCU) is corrupted.

Doing a read-modify-write is simpler, more transparent and may be preferable than local state keeping if you have multiple instances controlling the MCP. OTOH, as seen, it is more vulnerable to read disturbances.

fdxrate commented 2 years ago

Moved to new issue...

monoidk commented 2 years ago

@fdxrate Perhaps it would be best to discuss this in a separate issue? Please create a separate issue and we will discuss it there.

BTW, block quotes are delimited with ```, and you can start the block with ```c++ to enable c++ syntax highlighting (use Preview to verify).

julianschuler commented 1 year ago

Sorry for the late answer (I wrongly assumed Github would send me a notification for new issues/PRs).

Can I close this issue or are there questions left not covered in the new one?

monoidk commented 1 year ago

I believe there are no open questions.