BlockoS / arduino-dataflash

Support for Atmel Dataflash for the Arduino
http://blockos.github.com/arduino-dataflash
23 stars 14 forks source link

PageRead question #16

Open thetazzbot opened 7 years ago

thetazzbot commented 7 years ago

Reading the datasheet for the AT45DB04D chip it talks about padding the stream with 4 "dont care" bits in between the opcode and the page address:

Main Memory Page Read

A Main Memory Page Read allows the user to read data directly from any one of the 2048 pages in the main memory, bypassing both of the data buffers and leaving the contents of the buffers unchanged.

To start a page read, an opcode of 52H or D2H must be clocked into the device fol-lowed by 24 address bits and 32 don’t care bits.

The first four bits of the 24-bit address sequence are reserved bits, the next 11 address bits (PA10 - PA0) specify the page address,and the next nine address bits (BA8 - BA0) specify the starting byte address within the page.

How are the "first four bits" handled below?

for this chip, m_buffersize comes out to 9, and therefore the inline function pageToHiU8 equates to 16-9 and 16-8 for pageToLoU8.

I'm just a bit confused how we're handling the four empty bits for this 4 megabit chip...

void DataFlash::pageRead(uint16_t page, uint16_t offset) { reEnable(); // Reset command decoder.

/* Send opcode */
SPI.transfer(DATAFLASH_PAGE_READ);

/* Address (page | offset)  */
SPI.transfer(pageToHiU8(page));  // aka page >> 7
SPI.transfer(pageToLoU8(page) | (uint8_t)(offset >> 8)); // aka page << 1 | offset>>8
SPI.transfer((uint8_t)(offset & 0xff));

/* 4 "don't care" bytes */
SPI.transfer(0);
SPI.transfer(0);
SPI.transfer(0);
SPI.transfer(0);

// Can't disable the chip here!

}

thetazzbot commented 7 years ago

Ok I should have done this before i posted, but I see it now. Through the magic of the bit shifting.

This piece shifts the bits far enough to the right to accommodate the 4 dont care bits SPI.transfer(pageToHiU8(page)); // aka page >> 7

so you get [4 dont care][4 addr bits][7 addr bits][1 offset bit][8 offset bits] so it comes out to [dont care][address][offset] = 24 bits [xxxx][xxxxxxxxxxx][xxxxxxxxx]

BlockoS commented 7 years ago

Cool you managed to sort it out. I remember it was a nightmare to get it right between the various chip size :)

thetazzbot commented 7 years ago

Yeah, I saw the bit table for m_infos and thought that was mighty clever! Bit shifting has been my week spot for a while...so I had to sketch it out to understand what was going on.

thetazzbot commented 7 years ago

Btw do you mind if I port this over to mbed? I'm using that chip on a Nucleo board and the library that is on mbed tagged with AT5DB04D actually is for the 16megabit chip which uses 3 dont care bits instead of 4... I like this library a lot better :) Thanks for sharing it with the world!

BlockoS commented 7 years ago

Not at all. Do as you please :)