Problems with MCP23017 - Solved

Never really post on this forum for help, try to figure things out myself, posted this in the wrong forum to begin with. Here's the original post:

I've tried all sorts of things to get this to work. The most stable seems to be a 9V battery hooked into the Arduino as the power source, but it can stop working. Powered via USB it always seems to just randomly stop working quickly.

My code is simply a sketch to get an LED blinking (sets high all the GPIOA bits followed by delay and setting them low, etc).

/* Wiring

MCP23017 Pins
Pin 9  = Vdd  = 5V
Pin 10 = Vss  = Gnd

Pin 12 = SCL  = Arduino A5 (4.7K resistor to 5V)
Pin 13 = SDA  = Arduino A4 (4.7K resistor to 5V)

Pin 15 = A0   = Gnd
Pin 16 = A1   = Gnd
Pin 17 = A2   = Gnd

Pin 21 = GPA0 = Resistor -> LED -> Gnd

*/

//using raw addresses and hex values to ensure there are no other problems

#include "Wire.h"

void setup(){
  
  //Send initial configuration to MCP23017
  Wire.begin();
  
  Wire.beginTransmission(0x20); //opcode/address of chip
  Wire.send(0x12); //iocon
  Wire.send(0x20); //disable sequential addresses
  Wire.endTransmission();

  Wire.beginTransmission(0x20);
  Wire.send(0x00); //iodira
  Wire.send(0x00); //all 0's, all outputs
  Wire.send(0x00);
  Wire.endTransmission();

}

void turnOnLED()
{

  Wire.beginTransmission(0x20);
  Wire.send(0x12); // gpioa
  Wire.send(0xff);  // all high
  Wire.send(0xff); 
  Wire.endTransmission();
  
}

void turnOffLED()
{

  Wire.beginTransmission(0x20);
  Wire.send(0x12); // gpioa
  Wire.send(0x00); // all low
  Wire.send(0x00);
  Wire.endTransmission();
  
}

void loop(){

  turnOnLED();
  digitalWrite(13, HIGH);
  delay(100);
  turnOffLED();
  digitalWrite(13, LOW);
  delay(100);
  
}

There are 4.7k pull ups on the SDA and SCL lines. I guess my question is, why wouldn't this loop forever, why would it just stop for no reason.

Any help would be great!

EDIT: From what I'm reading there may be a problem with the wire library not dealing with ACK bits. Is there any work around for this?

Also, the chip is very touchy, if it stops responding, I have to manually reset it using the RESET pin, it works fine again after that...for awhile. The centipede library has the same problem as well with my setup.

SOLVED: Thanks to macegr, the /RESET pin was just flapping around in the wind and needs to be tied into the Vdd. Here is how I have it wired now: http://imgur.com/b3nFf.jpg (EDIT: put a 1K resistor in place of the yellow wire).

-Tweed

Here's a picture of my setup. The yellow wire I just recently put there to reset it if need be.

http://imgur.com/x26xH.jpg

-Tweed

Well there's your problem.

Read the description of the /RESET pin in the datasheet and it will tell you the pin needs to be externally biased. So you can't just leave it floating like that, you need to tie it to VCC with a resistor.

There are 4.7k pull ups on the SDA and SCL lines.

If you are still having problems try removing the 4.7k ohm pull-ups and replace them with 1k ohm (per the datasheet). This IC has a pretty high capacitance (135pF) on the I2C lines so reducing the pull-ups should help.

Mace, I love you man. I've been up and down that darn datasheet so many times, but I must have just completely missed that part. It seems to work just fine with it being tied to the 5V rail without a resistorEDIT: Put a 1K resistor from /RESET to Vdd just incase. What kind of resistor are you using?

Also, the project I'm working on needs to utilize pretty much the full function of the chip. I'd be happy to share my interrupt code with you for your centipede shield. (It will be interrupting on change from receiving input (high/low) from a 38 kHz IR receiver, the new 3 pin through hole one from sparkfun to be exact).

Anyways, thanks again, I have a lot of work to do today!

-Tweed