I2C Interface Problem

kranenborg

Senior Member
Hi,

Lets take one step at a time and see if we get the 24LC256 working. The following code can be used to test it, if everything is OK it writes a clearly interpretable message on the terminal window (leave the programming cable in place, be sure that the terminal program is open at N4800 when you start executing):

Code:
;********************
;* 24LC256 chiptest *
;********************

SYMBOL Location = b0
SYMBOL Address = %10100000
SYMBOL Num_chars = 21
SYMBOL Reading_char = b1
;--------------------
Initialization:
	PAUSE 1000
	I2CSLAVE Address, I2CFAST, I2CWORD
	
Write_string:
	WRITEI2C 0,("Yes, It Works !!!!!!!")
	PAUSE 50
	
Read_string:
	FOR Location = 0 TO Num_chars
		READI2C Location,(Reading_char)
		SERTXD (Reading_char)
	NEXT
	END
The program first writes a text string to the EEPROM, then reads it back character by character and writes it to the terminal program on the PC.

I always use this version for testing an I2C bus in a project, since the EEPROM interface is very simple. Please see that you fully understand the code. I suggest to not proceed with the other chip until you've got this one working. Did you include the pullup resistors too?

Success!

/Jurjen
http://www.kranenborg.org/ee/picaxe
 

Dippy

Moderator
You can get some good clues from the Wizards> Data logger> mission thing.

I assume you've wired it up properly ? :)
 

kranenborg

Senior Member
As an addendum to my previous message I would like to remark that the PCF8574 is not the easiest one to interface with; it has a "short" I2C command sequence, and it cannot actively drive a load, only sink. I would opt for the more modern and much more powerful MCP23008 for example (but there are several options)

/Jurjen
 

LKK

New Member
THANK YOU VERY MUCH!!! The program works! I also tried to write my own version to see if I understand it, and it worked too. I would still like to know about the I/O expander chip, I don't think it stores the data in a special address so I am not sure how to do it.
 

kranenborg

Senior Member
Hi LKK,

Great to see it working. Concerning the I/O expander; what will it be used for, outputs, inputs, or both?

/Jurjen
 

LKK

New Member
I wanted it to drive an LED dot matrix, one for rows and another for columns. I can also use it to drive things such as an lcd that have more pins than a PICAXE.
 

kranenborg

Senior Member
OK, that gives sufficient information for some notes (that show why the PCF8574(A) is not ideal):

  1. Since the PCF8574 does not actively drive the outputs, you need to sink the current through the LEDs (i.e. anode connected to +, cathode connected to output pin via resistor), you light the LED by writing a ZERO bit to that port! I do not know whether this will fit your matrix idea; can you show or sketch us the hardware connection scheme? I have the impression that you may need an expander that can both sink and source actively on all outputs ... (but I may be wrong). In any application case, applying the PCF8574 with LEDs requires ALL LED anodes to be connected with Vcc!
  2. I just noticed from the datasheet that the PCF8574(A) is a 100kHz device (slow I2C speed). This implies that ALL devices on the same I2C bus MUST use this slow speed (No problem for your application though)
  3. Be aware that there are two versions of the chip, the A version has a different I2C address.
  4. The PCF8574(A) has only one data register that cannot be directly addressed via a location, you just write data directly after the i2c address. The write instruction should then be of the short form too, something like WRITEI2C (variable), instead of WRITEI2C location, (variable), see the programming guide.

I hope this gets you in the right direction

/Jurjen
 

LKK

New Member
Thank you very much for the detailed explanation. I might try some of your suggestions.
 

westaust55

Moderator
Using the PCF8574 to drive LED's

I have just built up a small module using the PCF8574 to drive a set of 8 LED’s.
A couple of corrections and some further thoughts to past posts.

1. If one device on the i2c bus is fast (400kHz) and other devices are Slow (100kHz) then each can communicate at the relevant speed. They are NOT all locked to the slow speed.
2. The PCF8574 has one ID (%0100xxx0) whereas the PCF8574A has a different ID (%0111xxx0) so in fact you can have eight of each device on a single i2c bus for a total of 16 8-bit IO expanders.
3. As mentioned, the PCF8574 are basically active low when used as outputs and can sink 25mA on each pin but only source 0.3mA on active high outputs.
4. If you tie all the LED anodes to Vdd/Vcc = 5Vdc (rather than Vss = 0V) and use inverted logic (ie a LO for On state instead of a HIGH) then all should likely work well.
5. I already had an assembled LED circuit which I had been driving with a 74HC595 shift register. To keep some compatibility and retain “normal” logic with Hi for On state, I have used a BC109 type transistor as an interface. This is giving me the results in terms of logic states. However the PCF8574 outputs are high in the reset or power on condition so my code needs to issue a commands on stating to turn off the LED’s.
 
Top