PDA

View Full Version : Problem with I2Cread and I2CWRITE function



Tony85
- 6th June 2006, 18:24
Hello,

I have read MELANIE'S FAQ (I2CRead & I2CWrite not working as expected) but my code always not working. Normaly I must have minute =12 but it give me 0

I am using 16F877A and 24LC64 (pin1, 2, 3, 4, 7 to the ground ; 8 to 5v ; SDA and SDL to 16F877A).

Any idea ?

---------------------------------------------------
My code :

DEFINE OSC 4
Include "modedefs.bas"
asm
ERRORLEVEL -306, -302
endasm

DEFINE LCD_DREG PORTD
DEFINE LCD_RSREG PORTA
DEFINE LCD_RWREG PORTA
DEFINE LCD_EREG PORTA
DEFINE LCD_RSBIT 2
DEFINE LCD_RWBIT 1
DEFINE LCD_EBIT 0
DEFINE LCD_DBIT 0
DEFINE LCD_BITS 8
DEFINE LCD_LINES 4

RETRO VAR PORTA.3
SCL VAR PORTC.3
SDA VAR PORTC.4

minute VAR word
adr var word

ADCON1=7
TRISA=%11100000
TRISB=%11110000
TRISD=%11110000

i2cdevice CON %10100000

High RETRO

MAIN:
adr=1
I2CWRITE PORTC.4,PORTC.3,i2cdevice,adr,[12]
pause 10
i2CREAD PORTC.4,PORTC.3,i2cdevice,adr,[minute]
pause 10
LCDOUT $FE,1
LCDOUT $FE,192,dec minute,"min "
end

mat janssen
- 6th June 2006, 19:02
Maybe you forgot 2 resistors ?? From SDA to Vcc and SCL to Vcc (4K7)

Tony85
- 6th June 2006, 19:17
Between 16F877 SDA pin and 24LC64 SDA pin I have a 330Ohms resistor and Between 16F877 SCL pin and 24LC64 SCL pin I have a 330Ohms resistor.

mat janssen
- 6th June 2006, 19:26
These are serie resistors, that is no problem. But you must put also 2 resistors from 4K7 to the + power of the PICCHIP and the SDA and SCL line. Kind of pullup resistors.

Tony85
- 6th June 2006, 19:30
as this ?

http://col2000.free.fr/copieur/cop-sche.gif

mat janssen
- 6th June 2006, 19:45
You used 10K resistors, lower them to 4K7. And put also a capacitor of 100 nF over each supply point of each ic, near each ic.
Is your oscillator running well? Because normally I put 22pF capacitors at a 4 MHz cristal.
Put also an extra elco (10uF) and a capacitor of 330nF near your 7805. This prevents oscillating of this component.

Tony85
- 6th June 2006, 19:51
I just have put 4.7k resistor and it work good

Thanks a lot

Tony

mat janssen
- 6th June 2006, 20:03
You'r welcome.
M