Go Down

Topic: Having trouble with a AT25640B EEPROM (Read 594 times) previous topic - next topic

Plecto

Jun 29, 2013, 10:45 pm Last Edit: Jun 29, 2013, 10:48 pm by Plecto Reason: 1
Hi. I'm trying to write and read data from a AT25640B EEPROM, but I can't seem to pull it off. I can set the status register and then read the status register so I am communicating with it, but setting the status register can be difficult also, sometimes it doesn't work, but I haven't figured out what I'm doing differently. The datasheet can be found here: http://pdf1.alldatasheet.com/datasheet-pdf/view/257047/ATMEL/AT25640B.html.

The WP pin and HOLD pin is connected to +V to assure that it can be written to. Here is the code that I have written:

Code: [Select]
if (l==1) {
   digitalWrite(7, LOW);
   SPI.transfer(0x06);
   SPI.transfer(0x02);
   SPI.transfer(0x00);
   SPI.transfer(0x00);
   SPI.transfer(0xAA);
   digitalWrite(7, HIGH);
   delay(10);
   l=0;
 }


The chip has several write protection bits. By setting the WEN bit HIGH, it should be write enabled, WPEN bit is 0 (which shouldn't matter since the WP pin is pulled HIGH) and BP1 and BP0 is also 0 which shouldn't make any of the blocks protected. The first transfer is 0x06 which is the WREN command, it should set the write enable latch. The datasheet says:
Quote
WRITE ENABLE (WREN): The device will power up in the write disable state when VCC is
applied. All programming instructions must therefore be preceded by a Write Enable instruction.

The next transfer is 0x02 which is the "write data to memory array" command. This is followed by 2x 0x00 which should set the address to 0x0000. This is what the datasheet has to say about writing data:
Quote
WRITE SEQUENCE (WRITE): In order to program the AT25320B/640B, two separate instructions
must be executed. First, the device must be write enabled via the WREN instruction.
Then a write (WRITE) instruction may be executed. Also, the address of the memory location(s)
to be programmed must be outside the protected address field location selected by the block
write protection level. During an internal write cycle, all commands will be ignored except the
RDSR instruction.

A write instruction requires the following sequence. After the CS line is pulled low to select the
device, the WRITE op-code is transmitted via the SI line followed by the byte address (A15-A0)
and the data (D7-D0) to be programmed (see Table 2-6). Programming will start after the CS pin
is brought high. The low-to-high transition of the CS pin must occur during the SCK low-time
immediately after clocking in the D0 (LSB) data bit.
The READY/BUSY status of the device can be determined by initiating a read status register
(RDSR) instruction. If Bit 0 = "1", the write cycle is still in progress. If Bit 0 = "0", the write cycle
has ended. Only the RDSR instruction is enabled during the write programming cycle.
The AT25320B/640B is capable of a 32-byte page write operation. After each byte of data is
received, the five low-order address bits are internally incremented by one; the high-order bits of
the address will remain constant. If more than 32 bytes of data are transmitted, the address
counter will roll over and the previously written data will be overwritten. The AT25320B/640B is
automatically returned to the write disable state at the completion of a write cycle.



It might be that the code works, but that I can't read it back (it just returns 0xFF regardless of the address), but I've tried to read the RDY bit, but it's constantly 0 indicating that no wiring is in progress. I feel that I have done everything the datasheet say I have to do, so I'm not sure why it isn't working :( Can anyone help me out?

el_supremo

You must do the WREN as a separate command.
Code: [Select]

    // WREN command
    digitalWrite(7, LOW);
    SPI.transfer(0x06);
    digitalWrite(7, HIGH);

    // WREN delay - some chips need a delay after a WREN
    delay(10);

    // Write command
    digitalWrite(7, LOW);
    SPI.transfer(0x02);
    SPI.transfer(0x00);
    SPI.transfer(0x00);
    SPI.transfer(0xAA);
    digitalWrite(7, HIGH);


Pete

Plecto


Go Up