Question

I'm attempting to talk a AT45DB081D chip over SPI using the following code:

void efContinuousArrayRead(unsigned char *data, unsigned int page, unsigned int offset, unsigned int length)
{
    unsigned int index;

    FLASH_SEL_ON

    SPIShift(0x03); 
    SPIShift((unsigned char)(page >> 7));
    SPIShift((unsigned char)((page << 1) | (offset >> 8)));
    SPIShift((unsigned char)(offset & 0xFF));

    for(index = 0; index < length; index++)
    {
        data[index] = SPIShift(0x00);
    }

    FLASH_SEL_OFF
}

I have several other commands working including:

  • Buffer 1/2 Read
  • Buffer 1/2 Write With / Without Page Erase
  • Main Memory to Buffer 1/2

Given that these other commands work, I am reasonably confident that FLASH_SEL_ON, SPIShift, etc are working as expected.

Note that I am able to read from Page 0, any offset. However, I am unable to read from any page other than 0. This leads me to believe that the problem revolves around my math for specifying the page is flawed.

In debugging, I have found that for page 1, offset 0, the 24 bit address is calculated as:

00000000 00000010 00000000

This looks correct according to the datasheet spec for the format of the address:

xxxPPPPP PPPPPPPB BBBBBBBB

where:

  • x unused
  • P page number
  • B offset

When I specify pageNumber = 0, I get the correct values back that I placed in there. However, when I specify pageNumber = 1, I get all 255 values instead of the values I placed there previously.

How do I specify the address for pages other than 0?

Was it helpful?

Solution

It turns out that this command was implemented fine. It was the other commands that weren't correct (e.g. MainMemoryPageToBufferTransfer). They were calculating the page number using the math for a chip operating in 256 byte mode. This chip is operating in 264 byte mode.

Changing my addressing for those commands from:

SPIShift(opcode); 
SPIShift(pageNumber >> 8); 
SPIShift((unsigned short)pageNumber, 0x00));

to:

SPIShift(opcode);
SPIShift((unsigned char)(pageNumber >> 7)); 
SPIShift((unsigned char)(pageNumber << 1), 0x00));

And that sorted it. My tests were passing because both the read and write operations were using the same flawed logic for specifying the page number, leading me to believe that they were working correctly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top