The PCF8574 to PCF8574 Blues

erdc

Member
I have successfully controlled a PCF8574A 8 bit I/O expander chip via i2c via a Picaxe in regards to its inputs and outputs. But when I try to send an output from one PCF8574A to an input to another PCF8574A it doesn’t seem to work.

If I take one of the inputs and tie it directly to +5v it will report it as such when I do a read (i.e. %00000001). But even when I measure +5v on an output pin from another PCF8574A and try to connect it to that same pin (with the +5v connection removed of course) it reports that there is no input signals. (i.e. %00000000). It also looks to be the same if I try to give it a high from a TTL 74LSxx chip as well, no input signals detected.

And yes, they all have the same common ground.


Edited by - erdc on 16/02/2007 16:18:19
 

Ralpht

New Member
I use the PCF8574AP both as inputs and outputs. I have not found any issue with the 8574 seeing inputs from another IC BUT:

Remember - to make the 8574 I/O pins act as input pins, you have to sent all ones to the chip first. (At least to all the pins you want to act as inputs).
That makes all the required I/O pins go Hi(1). To get the chip to sense an input you have to drive the I/O line Lo (0) otherwise it won't respond.
It sounded in you post that you were trying to drive the I/O lpins Hi, which they are already at.

 
 

Ralpht

New Member
Hi erdc.
From your post - "It also looks to be the same if I try to give it a high from a TTL 74LSxx chip as well, no input signals detected."

It sound to me like you are trying to get the 8574 to respond to a Hi input. The I/O pins are already Hi (1) for each pin that has to act as an input. You have to drive the I/O pin Lo (0) to get it to register as a change in its inputs, and to get the INT pin to then interrupt the main processor (assuming you use the INT pin).

I have a similar project where an PCF9574AP drives another PCF8574AP's inputs. No problem.

 

Ralpht

New Member
Sorry for the doubling up of my reply. Initially when I sent the first on the forum said it could not accept it. So I tried again. Only later did it actually show that it did accept my reply.
 

erdc

Member
I have first sent out all 1's, and even have a 10k resistor tied from in input pin to +5V. I then ground that pin and do a read, but it comes back with %00000000. It will only show “something” when I wire it directly to +5V. I checked to make sure I did not have my power and ground reversed, but then the chip would have of course not work at all.

Here is my code.


i2cslave %01110000, i2cfast, i2cword ' 1st chip's address
writei2c 0,(%00000000) ' sets 1st chip's I/O Low

i2cslave %01110010, i2cfast, i2cword '2nd chip's address
writei2c 0,(%11111111) ' sets 2nd chip's I/O High
pause 50
readi2c 0,(b0) ' read 2nd chip's I/O
sertxd(#b0,CR,LF)

Thanks for your help, it is greatly apppriciated.
 

Technical

Technical Support
Staff member
Try this:

i2cslave %01110000, i2cfast, i2cbyte' 1st chip's address
writei2c (%00000000) ' sets 1st chip's I/O Low

i2cslave %01110010, i2cfast, i2cbyte' '2nd chip's address
writei2c (%11111111) ' sets 2nd chip's I/O High
pause 50
readi2c (b0) ' read 2nd chip's I/O
sertxd(#b0,CR,LF)

 

erdc

Member
I tried your code Technical, but it just reports %00000000. The input pin is tied to +5V via a 10k resistor, but do I need any thing on the output pin of the other chip?

It DOES NOT however report correctly when I hard wire the inputs directly to +5V. Which it does do with my original code.

Edited by - erdc on 19/02/2007 22:27:20
 

Technical

Technical Support
Staff member
This chip does not use any address byte (or address word as in your first program) like eeproms do. Your original code actually outputs unwanted address bytes like this:

writei2c 0,(%00000000)
= slave - write 0 - write 0 - write 0

writei2c 0,(%11111111)
= slave - write 0 - write 0 - write 255

readi2c 0,(b0)
= slave - write 0 - write 0 - read b0

what you need to do is just
slave - write 0
= writei2c (%00000000)

slave - read
= readi2c (b0)

The datasheet states pins must be written high before they are read. You can achieve this with (in i2cbyte mode)

readi2c 255,(b0)
= slave - write 255 - read b0
 

Ralpht

New Member
Hi again,
I was going to suggest doing something similar to what Technical told you to do and it should work. I'm still coming to grips with Picaxe code (I normally use AVR's and BASCOM and the syntax is very different). It initially looked to me like you were reading the Ist chip in error, but I may be wrong there.
I'm assuming that you have a 10K resistor to Hi (=5V) and a switch to ground. Whenever the switch is pressed a Lo (gnd) will be put on the input pin of the chip. Are you holding the input pin(s) low or is it a pulse that you are trying to read? The 8574 will only respond to a Lo on its inputs(even though the data sheet hints that it will also respond to a Hi)and when the Lo is removed it will revert back to a Hi on the input. It does not latch it's inputs. Try putting a 10K resistor on the INT pin (13) to +5V and monitor it. When you pull the input line Lo the INT pin should go from Hi to Lo for the duration you are applying the Lo input. This will at least confirm the 8574 is operating and is not faulty. Having it only respond when you tie an input to +5V may be a sign that the chip is faulty. Try modifying your code so it responds to the INT pin on the 8574 to see if that makes a difference. But from what I know of the 8574 and I've used a lot of them, it seems to be faulty or there is a subtle wiring error there somewhere.
 

erdc

Member
OK got it ot work BUT it is real weired how I have to do it.

I first execute this code;

--------------------------------------------
i2cslave %01110000, i2cfast, i2cbyte' 1st chip's address
writei2c (%00000000) ' sets 1st chip's I/O Low

i2cslave %01110010, i2cfast, i2cbyte' '2nd chip's address
writei2c (%11111111) ' sets 2nd chip's I/O High
-------------------------------------------

But then for some reason I get the following "text" displayed in the serial terminal window;

ððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððZæ

I then load and execute this code;
-------------------------------
i2cslave %01110010, i2cfast, i2cbyte' '2nd chip's address
readi2c (b0) ' read 2nd chip's I/O
sertxd(#b0,CR,LF)
-----------------------------------

And it reports correctly. BUT if I try to make it all in one code, such as;
-----------------------
i2cslave %01110000, i2cfast, i2cbyte' 1st chip's address
writei2c (%00000000) ' sets 1st chip's I/O Low

i2cslave %01110010, i2cfast, i2cbyte' '2nd chip's address
writei2c (%11111111) ' sets 2nd chip's I/O High

pause 50
readi2c (b0) ' read 2nd chip's I/O
sertxd(#b0,CR,LF)
------------------------

It reports back %00000000.

RalphTeichel, I have an outpin of one chip conected up to an input of another chip.
 

erdc

Member
OK< got it to work in just one program. What I did was just to add the same "i2cslave" command right after the "writei2c" command.

i2cslave %01110000, i2cfast, i2cbyte' 1st chip's address
writei2c (%00000000) ' sets 1st chip's I/O Low

i2cslave %01110010, i2cfast, i2cbyte' '2nd chip's address
writei2c (%11111111) ' sets 2nd chip's I/O High

i2cslave %01110010, i2cfast, i2cbyte' '2nd chip's address
readi2c (b0) ' read 2nd chip's I/O
sertxd(#b0,CR,LF)
 

Ralpht

New Member
It's excellent that you finally got it to work. Of course! I should have realised it earlier - to talk to the chip you have to address it first, then read the data from the "input" chip. (Or write data).
Where you said you have the 'outpin of one chip connected to the input of another chip' do you mean the output of the first 8574 is connected to the input of the second?
 

hippy

Technical Support
Staff member
<i>But then for some reason I get the following &quot;text&quot; displayed in the serial terminal window;

&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;&#240;Z&#230; </i>

That looks like the sort of 'rubbish' which gets sent when the PICAXE resets.
 
Top