Arduino Playground is read-only starting December 31st, 2018. For more info please look at this Forum Post

DataFlash is a protocol for flash memory data storage on top of SPI. As of 2014, DataFlash chips are available in tiny 8-pin packages that hold up to 64 Mbit (8 megabyte) per package. ("The Explosive World of Serial Flash"; Wikipedia: DataFlash).

Mark Limbrick has added this update in 2015 to the previous dataflash library code to resolve a number of errors preventing proper functioning. I have updated the c++ and dataflash.h files and provided a new simple working example. This has been tested on the current AT45DB161D and all functions are now available and working correctly.

You are advised not to use the sector protection register op-codes, as this could lead to the flash device becoming inaccessible.

The "dataflash" library is a library for dataflash memory. Dataflash is essentially external FLASH memory on a chip; this library lets you make the Arduino talk to that external memory chip and store values or data there, for applications like datalogging or simple audio recording and playback.

The code is from the atmel butterfly, ported to gcc by Martin Thomas. It has been changed to c++ so it can be used as a library for arduino. You can download the library here http://forum.arduino.cc/index.php?topic=298022.0. Put the dataflash.cpp dataflash.h files in a folder renamed 'dataflash' in your arduino folder/libraries/ directory and (re)start arduino. You can ask your question in this http://forum.arduino.cc/index.php?topic=298022.0 in the forum.

This chip is not available in a DIL package so you have to put it on a small pcb, like this. Connect it like this:

dataflash  arduino
pin 1 -- pin 11
pin 2 -- pin 13
pin 3 -- pin  8
pin 4 -- pin 10
pin 5 -- pin  7
pin 6 -- V (3.3v to 3.6v)
pin 7 -- ground
pin 8 -- pin 12

It is 5 volt tolerant on input and output pins, but needs 3.3 volt on its VCC pin. You cannot power it with 5 volts from an Arduino. Two small silicon PIN diodes in series give a simple approximate 3.1 to 3.6 volt supply which works, but is not well regulated. When writing data a larger current of about 7mA is used by the device. The voltage minimum is about 3.1 volt, any lower and the Arduino input may not recognise a 'high' input. If you have an Arduino with onboard 3.3 volt regulator you can also get 3.3 volt from there. The other connections for SPI are directly connected.

I have attached a small example with some comments. Copy the example to your arduino sketch directory, add the dataflash library and it should work. The code in the library is commented but for convenience I copied it below.

 
Function name : Buffer_To_PageNE
Returns :       None
Parameters :    BufferNo -> Decides usage of either buffer 1 or 2
                PageAdr ->Address of page to be transferred to buffer
Purpose :       Transfers a page from Dataflash SRAM buffer to flash with no page erase.
                This is much quicker but Page_Erase must have been used beforehand.

Function name : Page_To_Buffer
Returns :	None
Parameters :    BufferNo -> Decides usage of either buffer 1 or 2
	        PageAdr	-> Address of page to be transferred to buffer
Purpose :	Transfers a page from flash to Dataflash SRAM buffer

Function name : Buffer_Read_Byte
Returns :	One read byte (any value)
Parameters :	BufferNo -> Decides usage of either buffer 1 or 2
		IntPageAdr -> Internal page address
Purpose :	Reads one byte from one of the Dataflash internal SRAM buffers

Function name : Buffer_Read_Str
Returns :	None
Parameters :	BufferNo -> Decides usage of either buffer 1 or 2
		IntPageAdr -> Internal page address No_of_bytes	-> Number of bytes 
to be read 
		*BufferPtr -> address of buffer to be used for read bytes
Purpose :	Reads one or more bytes from one of the Dataflash internal SRAM buffers,
and puts read bytes into buffer pointed to by *BufferPtr

Function name : Buffer_Write_Enable
Returns :	None
Parameters :	IntPageAdr -> Internal page address to start writing from
		BufferAdr -> Decides usage of either buffer 1 or 2
Purpose :	Enables continous write functionality to one of the Dataflash buffers
buffers. NOTE : User must ensure that CS goes high to terminate this mode before 
accessing other Dataflash functionalities

Function name : Buffer_Write_Byte
Returns :	None
Parameters :	IntPageAdr -> Internal page address to write byte to
		BufferAdr	->	Decides usage of either buffer 1 or 2
		Data -> Data byte to be written
Purpose :	Writes one byte to one of the Dataflash internal SRAM buffers

Function name : Buffer_Write_Str
Returns :	None
Parameters :	BufferNo -> Decides usage of either buffer 1 or 2
		IntPageAdr -> Internal page address
		No_of_bytes -> Number of bytes to be written
		*BufferPtr -> address of buffer to be used for copy of bytes from AVR
buffer to Dataflash buffer 1 (or 2)
Purpose :	Copies one or more bytes to one of the Dataflash internal SRAM buffers
from AVR SRAM buffer pointed to by *BufferPtr

Function name : Buffer_To_Page
Returns :	None
Parameters :	BufferAdr -> Decides usage of either buffer 1 or 2
		PageAdr	 -> Address of flash page to be programmed
Purpose :	Transfers a page from Dataflash SRAM buffer to flash

Function name : Cont_Flash_Read_Enable
Returns :	None
Parameters :	PageAdr	-> Address of flash page where cont.read starts from
		IntPageAdr -> Internal page address where cont.read starts from
Purpose :	Initiates a continuous read from a location in the DataFlash

Function name : Page_Buffer_Compare
Returns :	0 match, 1 if mismatch
Parameters :	BufferAdr -> Decides usage of either buffer 1 or 2
		PageAdr	-> Address of flash page to be compared with buffer
Purpose :	comparte Buffer with Flash-Page

Function name : Page_Erase
Returns :	None
Parameters :	PageAdr	-> Address of flash page to be erased
Purpose :	Sets all bits in the given page (all bytes are 0xff)