EEPROM Read & Program Functions

The EEPROM read and program functions are implemented and defined in eeprom.c and eeprom.h in the example source code SPI EEPROM.

EEPROM Read Single Byte:

The function eeprom_read_byte() reads one byte from the EEPROM from the given address location.

Prototype:

uint8_t eeprom_read_byte(uint16_t addr);

DataFlash Read Multiple Bytes:

The function eeprom_program_multiple_read() reads multiple bytes up to buff_length from given address and stores bytes in the given buffer.

Prototype:
void eeprom_program_multiple_read(uint16_t addr, uint8_t *buff, uint8_t buff_length);

In this function the sequence is: pull down the #SS wire, send op_code READ and send start address. Then continuously read data until the number of bytes read are equal to the given buff_length. Data is stored in the given buffer then the #SS wire is pulled up to stop the read process.

EEPROM Program Single Byte:

The function eeprom_program_byte programs a single byte to the given address.

Prototype:

void eeprom_program_byte(uint16_t addr, uint8_t byte);
EEPROM Program multiple Bytes:

This function writes multiple bytes up to buff_length from the given array. It starts writing from the given start address. In this function address and buff_length validations are done. The start address should be the start of the page address and buff_length should be within the limit. If validation fails, the function returns without writing anything.

If address and buffer length are valid, the total number of pages that needs to be written is calculated and the eeprom_page_write() function is called, which writes data to the page of a size up to PAGE_SIZE, 64 bytes.

Prototypes:
void eeprom_program_multiple_write(uint16_t addr, uint8_t *buff, uint8_t buff_length);
void eeprom_page_write(uint16_t addr, uint8_t *buff, uint8_t buff_length);

EEPROM erase functions:

Prototypes:

void eeprom_erase_chip();             /* Erase entire chip*/
void eeprom_erase_page(uint16_t addr);/* Erase page,address should be start of page address*/