Serial EEPROM

Status
Not open for further replies.

i2c2k

New Member
hi!

i've got a 24aa64 i2c-eeprom from microchip and wanted to programm it using the following code (ccs-c-compiler, PIC18F458):

Code:
#use i2c(master, scl=PIN_C3, sda=PIN_C4, slow, force_hw)

......

//write
i2c_start();
i2c_write(0b10100000); //control byte
i2c_write(0b00000000); //adr hi
i2c_write(0b00000000); //adr lo
i2c_write('h'); //data 0
i2c_write('e'); //data 1
i2c_write('l'); //data 2
i2c_write('l'); //data 3
i2c_write('o'); //data 4
i2c_stop();

//read
i2c_start();
i2c_write(0b10100000); //control byte (set address)
i2c_write(0b00000000); //adr hi
i2c_write(0b00000000); //adr lo

i2c_start();
i2c_write(0b10100001); //control byte (read data)
printf("Data from EEPROM: %c", i2c_read());
printf("%c", i2c_read());
printf("%c", i2c_read());
printf("%c", i2c_read());
printf("%c\n", i2c_read());
i2c_stop();


does anybody know, why it doesn't work or is there any sample file for writing/reading from/to serial eeprom? the ex_extee.c is not really a help...

thank you!

cya
i2c2k
[/code]
 
I have not seen or used the CCS C-compiler but I'll have a guess at this
Scratch that idea. Hang-on a sec and I'll download a datasheet for the EEPROM.


it seems as though you have stepped on the read address in your read routine by issuing another i2c_start(). I would try the following:


Note: Lines in Red have been changed Lines in Green have been inserted


//read
// i2c_start();
// i2c_write(0b10100000); //control byte (set address)
// i2c_write(0b00000000); //adr hi
// i2c_write(0b00000000); //adr lo


i2c_start();
i2c_write(0b10100001); //control byte (read data)
i2c_write(0b00000000); //adr hi
i2c_write(0b00000000); //adr lo

printf("Data from EEPROM: %c", i2c_read());
printf("%c", i2c_read());
printf("%c", i2c_read());
printf("%c", i2c_read());
printf("%c\n", i2c_read());
i2c_stop();
 
thanks for your reply, but i found the solution elsewhere:
i found out, that a second call of i2c_start() does not cause a restart-condition (stop and then start) but a stop-condition. this means, i'd have to either call i2c_start() one again or use start - data - stop - start - ...

cya
i2c2k
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…