arduino-dataflash
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Atmel Dataflash library for Arduino.

Modules

 Chip erase command prevention.
 
 SPI transfer speed control.
 
 Default pin connections.
 Default pin values for Chip Select (CS), Reset (RS) and Write Protec (WP).
 
 Status register format.
 The status register can be used to determine device state (ready/busy) or to retrieve the result of an operation.
 
 Special sectors ID.
 The following list gives the number of pages per sector (P) for the AT45 family:
 
 Dataflash commands opcodes
 Dataflash command opcode list.
 
 Dataflash flash size.
 For each flash memory IC these definitions give the page size, block size, sector size and total size in bytes, the number of pages, blocks and sectors, and the number of pages in sector 0A (the remaining pages of the first sector are in sector 0b).
 

Classes

class  DataFlash
 AT45DBxxxD Atmel Dataflash device. More...
 
struct  DataFlash::AddressingInfos
 Dataflash read/write addressing infos. More...
 
struct  DataFlash::ID
 ID structure. More...
 

Functions

 DataFlash::DataFlash ()
 Constructor.
 
 DataFlash::~DataFlash ()
 Destructor.
 
void DataFlash::setup (int8_t csPin, int8_t resetPin=-1, int8_t wpPin=-1)
 Set pin use, with defaults for reset and write-protect if not specified as argument.
 
void DataFlash::begin ()
 Initialise SPI interface for use with the Dataflash, allowing shared use with other SPI devices (which must however use a different chip select pin).
 
void DataFlash::end ()
 Restore SPI configuration, so it can be used by other SPI devices.
 
void DataFlash::reEnable ()
 Disable (deselect) Dataflash, then enable (select) it again.
 
void DataFlash::autoErase ()
 Set erase mode to automatic (default).
 
void DataFlash::manualErase ()
 Set erase mode to manual.
 
uint8_t DataFlash::isReady ()
 Return whether the chip has completed the current operation and is ready for the next.
 
void DataFlash::waitUntilReady ()
 Wait until the chip is ready.
 
uint8_t DataFlash::status ()
 Read status register.
 
void DataFlash::readID (DataFlash::ID &id)
 Read Manufacturer and Device ID.
 
void DataFlash::pageRead (uint16_t page, uint16_t offset=0)
 A main memory page read allows the user to read data directly from any one of the pages in the main memory, bypassing both of the data buffers and leaving the contents of the buffers unchanged.
 
void DataFlash::arrayRead (uint16_t page, uint16_t offset=0)
 Sequentially read a continuous stream of data at the currently set speed.
 
void DataFlash::bufferRead (uint8_t bufferNum, uint16_t offset=0)
 Read the content of one of the SRAM data buffer at the currently set speed.
 
void DataFlash::bufferWrite (uint8_t bufferNum, uint16_t offset)
 Write data to one of the SRAM data buffers at the currently set speed.
 
void DataFlash::bufferToPage (uint8_t bufferNum, uint16_t page)
 Transfer data from buffer 0 or 1 to a main memory page, erasing the page first if auto-erase is set.
 
void DataFlash::pageToBuffer (uint16_t page, uint8_t bufferNum)
 Transfer a page of data from main memory to buffer 0 or 1.
 
void DataFlash::pageErase (uint16_t page)
 Erase a page in the main memory array.
 
void DataFlash::blockErase (uint16_t block)
 Erase a block of pages in a single operation.
 
void DataFlash::sectorErase (int8_t sector)
 Erase a sector of blocks in a single operation.
 
void DataFlash::beginPageWriteThroughBuffer (uint16_t page, uint16_t offset, uint8_t bufferNum)
 This a combination of Buffer Write and Buffer to Page with Built-in Erase.
 
int8_t DataFlash::isPageEqualBuffer (uint16_t page, uint8_t bufferNum)
 Compare a page of data in main memory to the data in buffer 0 or 1.
 
void DataFlash::deepPowerDown ()
 Put the device into the lowest power consumption mode.
 
void DataFlash::resumeFromDeepPowerDown ()
 Takes the device out of Deep Power-down mode.
 
void DataFlash::hardReset ()
 Reset device via the reset pin.
 
void DataFlash::enable ()
 Enable (select) Dataflash.
 
void DataFlash::disable ()
 Disable (deselect) Dataflash.
 
void DataFlash::writeProtect ()
 Enable write protection.
 
void DataFlash::readWrite ()
 Disable write protection.
 
int8_t DataFlash::chipSelectPin () const
 Get chip Select (CS) pin.
 
int8_t DataFlash::resetPin () const
 Get reset (RESET) pin.
 
int8_t DataFlash::writeProtectPin () const
 Get write protect (WP) pin.
 
uint8_t DataFlash::pageToHiU8 (uint16_t page) const
 Compute page address hi byte.
 
uint8_t DataFlash::pageToLoU8 (uint16_t page) const
 Compute page address lo byte.
 
void DataFlash::endAndWait ()
 Same as waitUntilReady.
 

Variables

static const AddressingInfos DataFlash::m_infos
 

Detailed Description

Function Documentation

void DataFlash::arrayRead ( uint16_t  page,
uint16_t  offset = 0 
)

Sequentially read a continuous stream of data at the currently set speed.

Reading past the end of the last page wraps around to the beginning of the first page. The chip must remain enabled by this function; it is the user's responsibility to disable the chip when finished reading.

Parameters
pagePage of the main memory where the sequential read will start.
offsetStarting byte address within the page (default value: 0).
Note
The legacy mode is not needed and not supported.
void DataFlash::autoErase ( )

Set erase mode to automatic (default).

void DataFlash::begin ( )

Initialise SPI interface for use with the Dataflash, allowing shared use with other SPI devices (which must however use a different chip select pin).

Initialise SPI interface for use with the Dataflash, allowing shared use with other SPI devices (which must however use a different chipselect pin).

void DataFlash::beginPageWriteThroughBuffer ( uint16_t  page,
uint16_t  offset,
uint8_t  bufferNum 
)

This a combination of Buffer Write and Buffer to Page with Built-in Erase.

The global erase flag .manual_erase() is ignored. Writing past the end of the page wraps around to the beginning of the page.

Note
You must call endAndWait in order to start transferring data from buffer to page.
Parameters
pagePage to which the content of the buffer is written.
offsetStarting byte address within the buffer.
bufferNumBuffer to use (0 or 1).
Warning
UNTESTED
void DataFlash::blockErase ( uint16_t  block)

Erase a block of pages in a single operation.

Parameters
blockBlock to erase.
Warning
UNTESTED
void DataFlash::bufferRead ( uint8_t  bufferNum,
uint16_t  offset = 0 
)

Read the content of one of the SRAM data buffer at the currently set speed.

Reading past the end of the buffer wraps around to the beginning. The chip must remain enabled by this function; it is the user's responsibility to disable the chip when finished reading.

Parameters
bufferNumBuffer to read (0 or 1).
offsetStarting byte within the buffer (default value: 0).
void DataFlash::bufferToPage ( uint8_t  bufferNum,
uint16_t  page 
)

Transfer data from buffer 0 or 1 to a main memory page, erasing the page first if auto-erase is set.

If erase is manual, the page must have been erased previously using one of the erase commands.

Parameters
bufferNumBuffer to use (0 or 1).
pagePage to which the content of the buffer is written.
void DataFlash::bufferWrite ( uint8_t  bufferNum,
uint16_t  offset 
)

Write data to one of the SRAM data buffers at the currently set speed.

Writing past the end of the buffer wraps around to the beginning. The chip must remain enabled by this function; it is the user's responsibility to disable the chip when finished reading.

Parameters
bufferNumBuffer to read (0 or 1).
offsetStarting byte within the buffer (default value: 0).
int8_t DataFlash::chipSelectPin ( ) const
inline

Get chip Select (CS) pin.

DataFlash::DataFlash ( )

Constructor.

Constructor This is not a good place to set the pins, because that causes hardware to be initialised in the variable declaration part a long time before setup() is called by the Arduino start-up code.

void DataFlash::deepPowerDown ( )

Put the device into the lowest power consumption mode.

Once the device has entered the Deep Power-down mode, all instructions are ignored except the Resume from Deep Power-down command.

Warning
UNTESTED
void DataFlash::disable ( )
inline

Disable (deselect) Dataflash.

Disable device with chipselect.

void DataFlash::enable ( )
inline

Enable (select) Dataflash.

Enable device with chipselect.

void DataFlash::end ( )

Restore SPI configuration, so it can be used by other SPI devices.

Disable device and restore SPI configuration.

void DataFlash::endAndWait ( )
inline

Same as waitUntilReady.

Todo:
This method will be removed.
void DataFlash::hardReset ( )

Reset device via the reset pin.

If no reset pint was specified (with begin()), this does nothing.

int8_t DataFlash::isPageEqualBuffer ( uint16_t  page,
uint8_t  bufferNum 
)

Compare a page of data in main memory to the data in buffer 0 or 1.

Parameters
pagePage to compare.
bufferNumBuffer number (0 or 1).
Returns
  • true If the page and the buffer contains the same data.
  • false Otherwise.
uint8_t DataFlash::isReady ( )

Return whether the chip has completed the current operation and is ready for the next.

Set transfer speed (33MHz = low, 66MHz = high).

Note that in some situations read/write access to one of the buffers is permitted although the chip is busy.

Note: Arduino supports 20MHz max, so using "high" is actually slower because additional bytes have to be transferred for no benefit. Return whether the chip has completed the current operation and is ready for the next. Note that in some situations read/write access to one of the buffers is permitted although the chip is busy.

void DataFlash::manualErase ( )

Set erase mode to manual.

User must erase pages first, using one of the erase commands.

void DataFlash::pageErase ( uint16_t  page)

Erase a page in the main memory array.

Parameters
pagePage to erase.
void DataFlash::pageRead ( uint16_t  page,
uint16_t  offset = 0 
)

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

Reading past the end of the page wraps around to the beginning of the page. The chip must remain enabled by this function; it is the user's responsibility to disable the chip when finished reading.

Parameters
pagePage of the main memory to read.
offsetStarting byte address within the page (default value: 0).
void DataFlash::pageToBuffer ( uint16_t  page,
uint8_t  bufferNum 
)

Transfer a page of data from main memory to buffer 0 or 1.

Parameters
pageMain memory page to transfer.
bufferNumBuffer (0 or 1) to which the data is written.
uint8_t DataFlash::pageToHiU8 ( uint16_t  page) const
inlineprivate

Compute page address hi byte.

Compute page address high byte.

uint8_t DataFlash::pageToLoU8 ( uint16_t  page) const
inlineprivate

Compute page address lo byte.

Compute page address low byte.

void DataFlash::readID ( DataFlash::ID id)

Read Manufacturer and Device ID.

Note
If id.extendedInfoLength is not equal to zero, successive calls to SPI.transfer() return the extended device information bytes.
Parameters
idID structure.
void DataFlash::readWrite ( )
inline

Disable write protection.

void DataFlash::reEnable ( )

Disable (deselect) Dataflash, then enable (select) it again.

int8_t DataFlash::resetPin ( ) const
inline

Get reset (RESET) pin.

void DataFlash::resumeFromDeepPowerDown ( )

Takes the device out of Deep Power-down mode.

Warning
UNTESTED
void DataFlash::sectorErase ( int8_t  sector)

Erase a sector of blocks in a single operation.

Parameters
sectorSector to erase.
void DataFlash::setup ( int8_t  csPin,
int8_t  resetPin = -1,
int8_t  wpPin = -1 
)

Set pin use, with defaults for reset and write-protect if not specified as argument.

Set SPI transfer speed to "low" (can be changed with .speed() ).

Note
This must be called the first time; afterwards .begin() can be called without arguments.
Parameters
csPinChip select (Slave select) pin.
resetPinReset pin, optional (default none).
wpPinWrite protect pin, optional (default none).
uint8_t DataFlash::status ( )

Read status register.

Returns
The content of the status register.
void DataFlash::waitUntilReady ( )

Wait until the chip is ready.

Perform a low-to-high transition on the CS pin and then poll the status register until the Dataflash is ready for the next operation.

void DataFlash::writeProtect ( )
inline

Enable write protection.

int8_t DataFlash::writeProtectPin ( ) const
inline

Get write protect (WP) pin.

DataFlash::~DataFlash ( )

Destructor.

Variable Documentation

const DataFlash::AddressingInfos DataFlash::m_infos
staticprivate
Initial value:
=
{
{ 9, 9, 9, 9, 10, 10, 11 },
{ 9, 10, 11, 12, 12, 13, 13 },
{ 2, 3, 3, 4, 4, 6, 5 }
}
See Also
AddressingInfos