I2C interface with pcf8575 I/O expander

I am having weird results with the I2C expander I ordered the other day. It is configured for reading data on the inputs and transferring the data to the arduino. The problem is that it works about 20% of the time the other 80% of the time it returns zeros. my code is simply

Wire.requestFrom(32, 2); Serial.println("I2C"); Serial.println(Wire.receive(),BIN); Serial.println(Wire.receive(),BIN); Wire.endTransmission();

I didn't check for availability because it has no effect.

I placed the scope on SDA and SCL and I can see that it sometimes does not request data from device 32 but device 0 (I'm not running any other I2C code either). Has anyone else run into this problem? Are there any limitations on the number of times I can run this code

Have you got external pull up resistors of between 3k3 and 4k7? I know the internal pull ups are enabled but they are really not enough for a good waveform.

You should be able to run the code as many times as you want.

I wuz just gonna say the same thing.

Also make sure that pins A0,A1, and A2 on the 8575 are connected to ground to ensure your 8575 is listening to address 32(decimal).

Good idea with the pull-ups, but I still have the same problems. I also changed the frequency of the clock to 400 kHz, which requires some fairly low valued pull-ups. Right now I have two external 4.7 k resistors. With the original 10 k resistors the true pull up resistance is about 3.2 k. How much pull up do you think I would need for running at 400 kHz. The waveform itself looks pretty good, the peaks are slightly rounded on the rising edge taking about 420 ns to rise. Or maybe the waveform should be really square, I am not sure.

I also tied A0, A1, and A2 to ground

How much pull up do you think I would need for running at 400 kHz.

Pull ups are not frequency dependent. You will be better off running at the lower speed if you are having problems.

With the original 10 k resistors the true pull up resistance is about 3.2 k.

I am confused about what you mean by this.

The problem is that it works about 20% of the time

That is usually a sign that you need some better decoupling on the supply. For example I assume you have a 0.1uF close to the PCF chip already. For more on this see:- http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

meehanchr, Another important thing is to check whether your master and slave share a common ground. Otherwise you could get some very unexpected results, as well.

Thrown in a couple of decoupling caps on your breadboard, small ones like 0.1uF to connect between ground and +5V. I will often put one on each breadboard power rail, as close to the ICs as possible. Saves a lot of headaches.

Mike, Parallel resistance is calculated as follows:

So, 4.7K and 10K parallel would be 1/(1/4700 + 1/10000) = 3197 Ohm, as in 3K2 :)

Regards, Xander