Mega power up fails I2C - needs manual reset to work

Some bizarre power up I2C behavior from Mega. Uno tests OK. What gives?

I have an application where I power a Mega by 9V external supply to the Vin pin. At power up, I expect the Mega to activate selected outputs on an MCP23017 I/O expander IC used as an LED driver. When I apply power to the circuit, the Mega activates the IC, so the I2C addressing is working, but the outputs are garbled ( usually dumps all the signals to the lowest output on the IC ), then it hangs. I have learned the following:

  • Using an Uno instead of a Mega in the circuit works correctly every time.

  • Pressing the reset button makes it work correctly.

  • No amount of delays or I2C.begin/end/speed/pullup calls seems to fix the problem.

  • All diagnostics from the I2C library show no errors.

  • Putting a 1800uF capacitor between Vin and ground effects the garbled output but does not correct it.

  • Signal levels on the MCP23017 are correct.

I can work around the problem by using an Uno instead of the Mega. Also, forcing a software reset on power up corrects the output, but it is not clear to me how to set up a one-shot software reset for this application, except by flipping a bit in the Mega's EEPROM, which has some limitations.

If it was a timing issue, you would think a delay would work, since a simple reset does the trick. It seems to me that, with respect to I2C at least, the Mega does not power up on Vin to the same state as after a manual reset, as the Uno appears to.

Anybody have any info on this? I recall some threads on this problem, but I can't seem to find them.

vanduino:

  • No amount of delays or I2C.begin/end/speed/pullup calls seems to fix the problem.

What about actual physical pull-up resistors? What are you using there?

The MCP23017 chip has a /RESET line. You might attach that to a pin, and bring that high after a brief delay. Have you done that?

I have 3.5k pullup resistors between SDA & SCL and 5V. The reset pin on the MCP23017 is wired to 5V. I guess I could tie it to another pin and flip it after a delay. Not sure why that would be needed for the Mega and not the Uno.

It might be a while before I can do the rewire. I'll check in when I learn something.

Thanks