DataFlash Read & Program Functions

DataFlash functions are implemented and defined in dataflash.c and dataflash.h in the example source code.

DataFlash Read Single Byte:

The function dataflash_read_byte() reads one byte from the DataFlash from the given address location.

Prototype:

uint8_t dataflash_read_byte(uint32_t addr);

DataFlash Read Multiple Bytes:

Reading multiple bytes is performed using the following three functions. These functions are called from read_dataflash() in the example source code main.c

Prototype:
void dataflash_read_multiple_start(uint32_t addr);
void dataflash_read_multiple_continue(uint8_t *buff, uint8_t buff_length);
void dataflash_read_multiple_stop();

dataflash_read_multiple_start() pulls down the #SS wire, sends op_code READ and sends the start address.

dataflash_read_multiple_continue() continuously reads data until the number of bytes read are equal to the given buff_length. Data is stored in the given buffer.

dataflash_read_multiple_stop() pulls up the #SS wire to stop the read process.

DataFlash Program Single Byte:

The function dataflash_program_byte() programs a single byte to the given address.

Prototype:

void dataflash_program_byte(uint32_t addr, uint8_t byte);
DataFlash Program multiple Bytes:

Programming multiple bytes is performed using the following three functions. These function are called from write_to_dataflash() in the example source code main.c

Prototypes:
void dataflash_program_multiple_start(uint32_t addr);
uint8_t dataflash_program_multiple_continue(uint8_t *buff, uint8_t length);
void dataflash_program_multiple_stop();

Programming multiple bytes uses the AAI program instruction, which allows multiple bytes of data to be programmed without re-issuing the next sequential address location.

dataflash_program_multiple_start() calls AAI_program_start() function. It sends op_code EBSY and WREN, pulls down the #SS wire and sends the op_code OP_AAI_WORD_PROG. Then it sends the start address from where data needs to be read.

dataflash_program_multiple_continue() calls AAI_program_continue() to write word or byte depending on device selection. For devices SST25VF040B/SST25VF080B, a word is programmed and for devices SST25VF010A/SST25VF020 a byte is programmed. The function AAI_program_continue() is called until number of bytes written equals given length. When last byte is programmed, the function returns 0.

dataflash_program_multiple_stop() function calls AAI_program_stop(). It sends the stop sequence: sends op_code OP_WRDI and OP_DBSY.

Note: For op_codes description refer to dataflash.h or the device data sheet.

Data Flash read Device ID and Manufacturer’s ID functions:

Prototypes:

uint8_t dataflash_read_id(uint32_t addr); /* Use addresse ADD_DEV_ID :0x01 to Read Device ID */
uint32_t dataflash_jedec_id_read(); /*Reads  Manufacturer’s ID from address 0x00*/

Data Flash erase functions:

Prototypes:

void dataflash_erase_chip(void);              /* Erase entire chip*/
void dataflash_erase_sector_4k(uint32_t addr);/* Erase sector 4K*/
void dataflash_erase_block_32k(uint32_t addr);/* Erase sector 32K*/
void dataflash_erase_block_64k(uint32_t addr);/* Erase sector 64K*/