Shop OBEX P1 Docs P2 Docs Learn Events
Serial EEPROM Driver Code — Parallax Forums

Serial EEPROM Driver Code

Dave HeinDave Hein Posts: 6,347
edited 2006-06-30 23:06 in General Discussion
Does anybody have SX source code for reading and writing a serial EEPROM?· I want to interface to an Atmel 24C512 64Kx8 EEPROM.· I have·read the·specs for the EEPROM, and it looks like it might take a few hours to write the driver.· However, I'm concerned that it might take a much longer time to debug the code.· I'm hoping to save a few hours or days by porting existing code.

Comments

  • BamseBamse Posts: 561
    edited 2006-06-16 20:19
    Would it help to write a program in SX/B (use I2C.SXB as a template, it comes with the SXKey software), compile it and then look at the SRC file under C:\Program Files\Parallax Inc\SX-Key v3.1\Compilers\SXB\Output Files...

    The only difference in the commands I saw is that 24C512 is using two address bytes in stead of one for 24LC16.
    The I2C.SXB code is a demo of read/write to the 24LC16.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Living on the planet Earth might be expensive but it includes a free trip around the sun every year...

    Experience level:
    [noparse][[/noparse] ] Let's connect the motor to pin 1, it's a 6V motor so it should be fine.
    [noparse][[/noparse] ] OK, I got my resistors hooked up with the LEDs.
    [noparse][[/noparse]X] I got the Motor hooked up with the H-bridge and the 555 is supplying the PWM.
    [noparse][[/noparse] ] Now, if I can only program the BOE-BOT to interface with he Flux Capacitor.
    [noparse][[/noparse] ] I dream in SX28 assembler...

    /Bamse
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2006-06-16 22:35
    Dave,

    to handle serial EEPROMS, like the 24C512 you may use the information about I²C code available for the SX at www.parallax.com/dl/appnt/sx/An29.pdf. Note that this descriebes a full implementation of an I²C multi-master system which you may not need, so your code could be less complicated.

    As Bamse suggested, using SX/B's I²C function to generate a code template is a good idea, and as he also mentioned, the "large" EEPROMS require a two-bytes address. When writing to the EEPROM, it is also important to take care of address page boundaries, any you may not write more than 16 bytes at a time. Also note that while the EEPROM transfers write data to its memory cells, it cannot respond tp new commands. You may either insert a delay after a write, or better do an "acknowledge polling", i.e. run a program loop which re-tries to send a new write address to the EEPROM as long as the EEPROM does not acknowledge this command. You will find more information on these topics in the 24C512 datasheet.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    Günther

    Post Edited (Guenther Daubach) : 6/16/2006 10:40:42 PM GMT
  • Dave HeinDave Hein Posts: 6,347
    edited 2006-06-17 03:15
    Bamse and G
  • Dave HeinDave Hein Posts: 6,347
    edited 2006-06-23 15:30
    I completed my driver routines for the 24C512 EEPROM. I have attached the files. I now realize that there is a lot of information available on the I2C bus, which is the protocol used by the EEPROM chip. G
  • dkemppaidkemppai Posts: 315
    edited 2006-06-29 16:43
    Guenther Daubach said...
    Dave,

    to handle serial EEPROMS, like the 24C512 you may use the information about I²C code available for the SX at www.parallax.com/dl/appnt/sx/An29.pdf. Note that this descriebes a full implementation of an I²C multi-master system which you may not need, so your code could be less complicated.

    As Bamse suggested, using SX/B's I²C function to generate a code template is a good idea, and as he also mentioned, the "large" EEPROMS require a two-bytes address. When writing to the EEPROM, it is also important to take care of address page boundaries, any you may not write more than 16 bytes at a time. Also note that while the EEPROM transfers write data to its memory cells, it cannot respond tp new commands. You may either insert a delay after a write, or better do an "acknowledge polling", i.e. run a program loop which re-tries to send a new write address to the EEPROM as long as the EEPROM does not acknowledge this command. You will find more information on these topics in the 24C512 datasheet.

    Hi,

    The larger Atmel EEPROMs can be difficult to work with. You need to watch the EEPROM page size when doing a write, and watch data in the page for a partial page write. You will become intimately familiar with that datasheet.

    I have some code for an AT25F1024 EEPROM, but it would take me a few days to dig it out of my main program. Because of the speed at which I needed to write data to the EEPROM, I had to include a FIFO to buffer to buffer data written between physical page writes. There is a delay between starting a write on a page, and when you can access the chip again. Depending on your application, that delay could be significant...

    -Dan



    ·
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2006-06-30 23:06
    Hi Dan,

    all types of serial EEPROMs require a certain delay following a write. The data you send to the EEPROM for write is first buffered in an EEPROM-internal RAM, and then transferred into the EEPROM cells. This transfer, and the write operation requires some time, and this is what requires the delay. The EEPROM datasheets recommend to do an "acknowledge poll" to check if the EEPROM is ready to receive more write data.

    So, after setting up the base address for a write, and sending the bytes to be written, I enter into a loop where I try to set up the base address for the next write. While the EEPROM is still busy storing the previous chunk of data, it does not acknowledge this command, so I stay in this loop until I receive an acknowledge from the EEPROM. This indicates that it is ready for the next page of data, and that it also has set the next base address. I then send the data bytes for the next page.

    Using a FIFO buffer may only be necessary when the data to be stored in the EEPROM comes in from some other source (maybe through a serial receiver) that can't be halted while the 'WriteToEEPROM' code loops for polling the EEPROM to return an acknowledge.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
Sign In or Register to comment.