PDA

View Full Version : Problem to read a PCF 8574



Darklakebridge7
- 25th February 2007, 13:12
Hi everybody!

I have a problem with PCF8574. I would have the necessity to read the state of 8 connected buttons to a PCF8574 and subsequently to visualize the sequence read on a display LCD of it. Have I written this firmware but doesn't it work, where am I being wrong?

Thanks everybody!



@ DEVICE HS_OSC
@ DEVICE pic16F877A
define OSC 20
ADCON1 = 7

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_LINES 2

Symbol SDA = PORTC.0
SYMBOL SCL = PORTC.1
symbol INT = PORTC.2

DATAPCF VAR BYTE
clear

LCDOUT $fe,1,"Test read PCF: "

Loop:
if INT = 0 then ReadPCF
goto Loop

ReadPCF:
I2Cread SDA,SCL,%01110001,DATAPCF
LCDOUT $FE,$C0,"Data: ",bin dataPCF," "
PAUSE 1000
goto Loop

Darrel Taylor
- 25th February 2007, 14:06
The PCF8574 is a 100khz device.

At 20mhz, you'll need to add...
DEFINE I2C_SLOW 1
<BR>

Darklakebridge7
- 25th February 2007, 15:06
The PCF8574 is a 100khz device.

At 20mhz, you'll need to add...
DEFINE I2C_SLOW 1
<BR>


Hi Darrel! Thanks you very much for your fast answer! Have tried to add the command that you have signalled me, but have not improved the situation! Have tried to put DEFINE OSC 4 but the result is not improved! is it possible that the error is in the address ( %01110001) of the device?

Thanks very much

mister_e
- 25th February 2007, 21:22
I2Cread SDA,SCL,%01110001,[DATAPCF]

depending if you're using an A version the control byte may differ.

Assuming your 4.7K pull-up (or lower) are on the I2C BUS, and you also have some on the PCF i/o... it should work.

if i remind correctly, prior to be able to read read from this device, all i/o have to be at high level.

i know i forgot something...

Darklakebridge7
- 26th February 2007, 21:50
I2Cread SDA,SCL,%01110001,[DATAPCF]

depending if you're using an A version the control byte may differ.

Assuming your 4.7K pull-up (or lower) are on the I2C BUS, and you also have some on the PCF i/o... it should work.

if i remind correctly, prior to be able to read read from this device, all i/o have to be at high level.

i know i forgot something...


Dear Steve!
Thank you very much! I have resolved my problems! The problem was in the resistances from 10k that had inserted in the bus I2C, that didn't give some problem in writing but they didn't allow the reading! Have replaced her with two resistances 4K7 and the problem has been resolved!

Thank you very much!

mister_e
- 26th February 2007, 21:56
Bienvenue et bonne chance!