Hi!

I'm using PIC18F2320 to drive EEPROM M24256. Here is the code to write variable to the address 1.

'--------------------------------
DEFINE OSC 4
Include "modedefs.bas"

CVRCON = 0 ' No reference
CMCON = 7 ' No comparator
TRISA = %00000000 ' Set PORTA pins into output
TRISB = %00000000 ' Set PORTB pins into output
TRISC = %00000000 ' Set PORTC pins into output

addr var word ' Address of EEPROM
val var byte ' Value of writable variable
val2 var byte ' Value of readable variable
DPIN var PORTC.4 ' Serial Data pin
CPIN var PORTC.5 ' Clock pin
cont var byte ' Control

Pause 1

val = 14 ' Starting value
val2 = 5 ' Starting value
addr = 1 ' Address

loop:

cont = %10100000 'Control is set to write

I2Cwrite DPIN, CPIN, cont, addr, [val] 'Writes value to EEPROM address 1
Pauseus 30

cont = %10100001 'Control is set to read

I2Cread DPIN, CPIN, cont, addr, [val2] ' Read EEPROM Contents
serout PORTC.6, N9600, [val2] ' Value to serial port

Goto loop ' Forever

The problem is that readed value "val2" is always zero. I think that, there is no writing into memory done. The "Control" format is based on datasheet of M24256. For reading I need to invert the first bit. In schematic all connections should be ok, as I've checked it many times. The clock and data pins aren't pulled up through resistors as PIC output isn't with open-collector. Could anybody tell, what I'm missing in code to write some variable into memory?