Problems with driving external EEPROM M24256
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?
driving external EEPROM M24256
I spent some time reading the data sheet and the addressvar is word, have you tried to use a for next loop
for address = 1 to 5
ic2write statment
next address
this seems to work for me to write and read memory locations on the 24aa65 chip, and i did not have to split the address into upper and lower bytes.
Hum, I will think on it some more to day, if I can find my program I will upload the code I used..I know it is some where on the computer ??
Mike
driving external EEPROM M24256
Mr. Jerson is very right on , make sure that the address pins are ground and in fact I have all pins at ground execpt for the data and clock lines, exception is if there is more than one memory chip connected,
read section 5.34 and 5.35 in the PicBasic pro compiler book it has a very good discription of how these commands work... also read the data sheet. try to use an error rutine at the end of the i2c statment, it will let you know if the write or read is successfull..
good luck
Mike
example of some code
addres var word
w var byte
cont con %10100000
for addres = 1 to 255
i2cwrite portb.var,portb,var,cont,addres,[w], error
pause 150
next addres
for reading just put in the 12cwread for the write statment
error:
lcdout $fe,1, "error no ack received"
end
driving external EEPROM M24256
Hey ! glad to see that every thing worked out for you,, I was sorta worried my taking a different approch than Mr. Jerson would cause some confusion, but I see things worked out in the end..
good Luck
Mike
Need help about the writing and reading data on eeprom!
how to read and write data on the internal eeprom of 16f877a?
is there a need of interrupt disable?
because when i program a reading data it will out only on the lcd a 0 using the command READ passing through a variable, and on to the lcd..
on the writing data will cause an infinite loop...
thank you...advance