blemasle / arduino-mcp23017

Complete support of MCP23017
MIT License
71 stars 40 forks source link

Problem in dual configuration #23

Closed FelixWeichselgartner closed 2 years ago

FelixWeichselgartner commented 2 years ago

Hi, so I'm experiencing a weird problem, that I can't identify correctly.

In the Arduino (I'm using an Arduino Uno, 2.2K pull-ups on I²C-bus) setup function I do the following configuration:

#define i2c_address_ioe_address 0x27
#define i2c_address_ioe_data_misc 0x20
MCP23017 mcp_address = MCP23017(i2c_address_ioe_address), mcp_data_misc = MCP23017(i2c_address_ioe_data_misc);
mcp_address.init();
mcp_data_misc.init();
mcp_address.portMode(MCP23017Port::A, 0); //Port A as output
mcp_address.portMode(MCP23017Port::B, 0); //Port B as output
mcp_data_misc.portMode(MCP23017Port::A, 0); //Port A as output
mcp_data_misc.portMode(MCP23017Port::B, 0b11110000); //Port A partly as output

In the loop, I have a test program, which turns each pin on individually (all others 0, the tested pin to one; I'm ignoring the ones that are configured as input ofc) to test if the output is working. I monitor the pin states with a 28 pin logic analyzer and therefore see which pin is working. To set the pin states I use the below functions.

uint16_t address = some_value;
mcp_address.write(address);
gpio->mcp_data_misc.writePort(MCP23017Port::A, data);
mcp_data_misc.digitalWrite(singlePin, 0);
mcp_data_misc.digitalWrite(singlePin, 1);

My issue is that if I write any pin to the mcp_address-module, pin 10 of the mcp_data_misc-module is not changing its state anymore.

Obviously, I thought this might be a PCB issue (schematic and layout of the PCB for reference). However, I tried 2 copies of the PCB and the issue persists.

One of those PCBs I already tested months ago with the MCP23017-library of WiringPi (obv. on a Raspberry Pi; I had level conversion there for 3.3V RPi GPIO to 5V MCP23017 levels) and back then all pins were working in a similar test.

So my question: Is there anything one has to keep in mind when working with multiple MCP23017? Has anybody experienced a similar issue? Is my configuration or the functions I use wrong?

TY for any help in advance.

FelixWeichselgartner commented 2 years ago

Btw. if the library completely works for me, I will probably do a port for the RPi in the future. I see a lack of good MCP23017-library with full functionality there.

FelixWeichselgartner commented 2 years ago

As it seems the problem was caused by some weird pointer error interaction.

I saved the MCP23017 objects in another object.

GPIO* gpio;

In the setup, I initialized the object.

This is good and works:

gpio = new GPIO();

This is bad and causes weird interactions:

*gpio = GPIO();