2.3 EEPROM Off-chip Device Driver

2.3.1 Introduction

The MCC Melody EEPROM Library provides an API interface to support basic EEPROM read and write functionality. The library supports the on-chip EEPROM and various off-chip EEPROM devices that can be connected by their required communication protocol. Its configurable settings include:

  • EEPROM Device Type (On-chip/Off-chip)
  • Communication protocol settings (for Off-chip EEPROM)
  • EEPROM size/density

2.3.1.1 How to use the EEPROM Off-chip Driver

2.3.1.1.1 I2C EEPROM Use Cases

The MCC Melody EEPROM Library supports a selection of I2C EEPROM devices with the following features:

  • I2C Dependency:
    • A selection of I2C peripherals for sending and receiving data.
    • Selectable I2C Clock frequencies provided by the MCU.
  • Allows user-selectable EEPROM configurations:
    • A selection of EEPROM sizes and Page write buffer sizes to choose from based on the table below.
    • Customizable I2C address based on the EEPROM's physical address pins.

EEPROM Word Address Construction:

When you write to an EEPROM device, after the I2C device address. the word address is sent. There is some variation between specifc EEPROM devices, in terms of constructing their word addresses. Sometimes the hardware bit addressing pins A0-A2 are disabled and are used as part of the word address. For A0-A2, in the table below, dashes ('-') represent hardware configurable address bits, i.e. pins that can be tied to Vcc or GND to fix the last bits of the I2C device address. Similarly, in the table Axx represents the word address bit number.
Table 2-14. I2C EEPROM Word Address Construction by EEPROM Size
EEPROM SIZE WORD ADDR LEN DEVICE ID A2 A1 A0 R/W WORD ADDR MSB WORD ADDR LSB
2Kbit 8 0xA - - - R/W - A7-A0
4Kbit 9 0xA - - A8 R/W - A7-A0
8Kbit 10 0xA - A9 A8 R/W - A7-A0
16Kbit 11 0xA A10 A9 A8 R/W - A7-A0
32Kbit 12 0xA - - - R/W A11-A8 A7-A0
64Kbit 13 0xA - - - R/W A12-A8 A7-A0
128Kbit 14 0xA - - - R/W A13-A8 A7-A0
256Kbit 15 0xA - - - R/W A14-A8 A7-A0
512Kbit 16 0xA - - - R/W A15-A8 A7-A0
1Mbit 17 0xA - - A16 R/W A15-A8 A7-A0
2Mbit 18 0xA - A17 A16 R/W A15-A8 A7-A0

2.3.2 Module Documentation

2.3.2.1 EEPROM

This file contains API prototypes for the EEPROM driver.

2.3.2.1.1 Module description

This file contains API prototypes for the EEPROM driver.

Version: EEPROM Driver Version 1.0.0
Data structures
Functions
  • static void EEPROM_UpdateWriteData (uint16_t dataLength, uint16_t pageCounter)

    Updates the write operation parameters.

  • static uint8_t EEPROM_WordAddressLowGet (uint32_t address)

    Gets the lower byte of the word address from the target memory address.

  • static uint8_t EEPROM_WordAddressHighGet (uint32_t address)

    Gets the upper byte of the word address from the target memory address.

  • static uint8_t EEPROM_DeviceAddressGet (uint32_t address)

    Gets the device address of the EEPROM.

  • static void EEPROM_Tasks (void)

    Performs the read and write operations of the driver.

  • static void EEPROM_Close (void)

    Resets the EEPROM status.

  • bool EEPROM_ByteWrite (uint32_t address, uint8_t *data)

    Writes a byte of data to a specified address in the EEPROM device.

  • bool EEPROM_ByteRead (uint32_t address, uint8_t *data)

    Reads a byte of data from a specified address in the EEPROM device.

  • bool EEPROM_IsBusy (void)

    Checks if the EEPROM device is busy.

  • bool EEPROM_SequentialWrite (uint32_t address, uint8_t *data, size_t dataLength)

    Writes n-bytes of data to a specified start address in the EEPROM device.

  • bool EEPROM_SequentialRead (uint32_t address, uint8_t *data, size_t dataLength)

    Reads n-bytes of data from a specified start address in the EEPROM device.

  • bool EEPROM_PageWrite (uint32_t address, uint8_t *data)

    Writes the data to an entire page of the EEPROM device.

  • bool EEPROM_PageRead (uint32_t address, uint8_t *data)

    Reads the data of an entire page of the EEPROM device.

  • EEPROM_STATUS_t EEPROM_ErrorGet (void)

    Checks the type of the error encountered in the EEPROM operation.

2.3.2.1.2 Function Documentation

EEPROM_ByteRead()

bool EEPROM_ByteRead (uint32_t address, uint8_t * data)

Reads a byte of data from a specified address in the EEPROM device.

Parameters:
uint32_t

address - The data is read from this EEPROM address.

uint8_t*

data - Pointer to user-defined data buffer that holds the data read from the EEPROM device.

Return values:
True

- Read operation is successful.

False

- Read operation is unsuccessful.

EEPROM_ByteWrite()

bool EEPROM_ByteWrite (uint32_t address, uint8_t * data)

Writes a byte of data to a specified address in the EEPROM device.

Parameters:
uint32_t

address - The data is written at this EEPROM address.

uint8_t*

data - Pointer to a byte of user-defined data that will be written to the EEPROM device.

Return values:
True

- Write operation is successful.

False

- Write operation is unsuccessful.

EEPROM_Close()

static void EEPROM_Close (void )[static]

Resets the EEPROM status.

Parameters:
None.
Returns:

None.

EEPROM_DeviceAddressGet()

static uint8_t EEPROM_DeviceAddressGet (uint32_t address)[static]

Gets the device address of the EEPROM.

Parameters:
uint32_t

address - The I2C address frame where the device address is taken from.

Returns:

The 8-bit device address.

EEPROM_ErrorGet()

EEPROM_STATUS_t EEPROM_ErrorGet (void )

Checks the type of the error encountered in the EEPROM operation.

Parameters:
None.
Returns:

EEPROM status code.

EEPROM_IsBusy()

bool EEPROM_IsBusy (void )

Checks if the EEPROM device is busy.

Parameters:
None.
Return values:
True

- The device is busy.

False

- The device is not busy.

EEPROM_PageRead()

bool EEPROM_PageRead (uint32_t address, uint8_t * data)

Reads the data of an entire page of the EEPROM device.

Parameters:
uint32_t

address - The data is read from this EEPROM address.

uint8_t*

data - Pointer to user-defined data buffer that holds the data read from the EEPROM device.

Return values:
True

- Read operation is successful.

False

- Read operation is unsuccessful.

EEPROM_PageWrite()

bool EEPROM_PageWrite (uint32_t address, uint8_t * data)

Writes the data to an entire page of the EEPROM device.

Parameters:
uint32_t

address - The data is written at this EEPROM address.

uint8_t*

data - Pointer to user-defined data that will be written to the EEPROM device.

Return values:
True

- Write operation is successful.

False

- Write operation is unsuccessful.

EEPROM_SequentialRead()

bool EEPROM_SequentialRead (uint32_t address, uint8_t * data, size_t dataLength)

Reads n-bytes of data from a specified start address in the EEPROM device.

Parameters:
uint32_t

address - The data is read from this EEPROM address.

uint8_t*

data - Pointer to user-defined data buffer that holds the data read from the EEPROM device.

size_t

dataLength - Length of the data read from the EEPROM in bytes.

Return values:
True

- Read operation is successful.

False

- Read operation is unsuccessful.

EEPROM_SequentialWrite()

bool EEPROM_SequentialWrite (uint32_t address, uint8_t * data, size_t dataLength)

Writes n-bytes of data to a specified start address in the EEPROM device.

Parameters:
uint32_t

address - The data is written at this target memory address.

uint8_t*

data - Pointer to user-defined data that will be written to the EEPROM device.

size_t

dataLength - Length of the data written to the EEPROM in bytes.

Return values:
True

- Write operation is successful.

False

- Write operation is unsuccessful.

EEPROM_Tasks()

static void EEPROM_Tasks (void )[static]

Performs the read and write operations of the driver.

Parameters:
None.
Returns:

None.

EEPROM_UpdateWriteData()

static void EEPROM_UpdateWriteData (uint16_t dataLength, uint16_t pageCounter)[static]

Updates the write operation parameters.

Parameters:
size_t

dataLength - Length of the data written to the EEPROM in bytes.

uint16_t

pageCounter - Counts the pages that is written on.

Returns:

None.

EEPROM_WordAddressHighGet()

static uint8_t EEPROM_WordAddressHighGet (uint32_t address)[static]

Gets the upper byte of the word address from the target memory address.

Parameters:
uint32_t

address - The target memory address where the upper byte of the memory address is taken from.

Returns:

The upper byte of the word address.

EEPROM_WordAddressLowGet()

static uint8_t EEPROM_WordAddressLowGet (uint32_t address)[static]

Gets the lower byte of the word address from the target memory address.

Parameters:
uint32_t

address - The target memory address where the low byte of the memory address is taken from.

Returns:

The lower byte of the word address.

2.3.2.1.3 Enumeration Type Documentation

EEPROM_STATUS

enum EEPROM_STATUS

Enumeration of the EEPROM driver status codes.

EEPROM_NO_ERROR
EEPROM_ERROR
EEPROM_I2C_TIMEOUT
EEPROM_INVALID_PARAMETER
EEPROM_NULL_ERROR
EEPROM_COM_ERROR

2.3.2.2 EEPROM_I2C

This file contains constants and API declarations for the EEPROM device.

2.3.2.2.1 Module description

This file contains constants and API declarations for the EEPROM device.

To ensure that the C driver runs properly, do not modify the I2C API prototypes. Refer to eeprom_i2c.c to configure the I2C interface implementation.

Version: EEPROM Driver Version 1.0.0
Functions
  • uint8_t EEPROM_I2C_Write (uint8_t deviceAddress, uint8_t *data, size_t writeLength)

    Writes the data to the EEPROM via the I2C bus.

  • uint8_t EEPROM_I2C_Read (uint8_t deviceAddress, uint8_t *eepromAddress, size_t addressLength, uint8_t *readData, size_t readLength)

    Reads the data from the EEPROM via the I2C bus.

  • bool EEPROM_AckPoll (uint8_t deviceAddress)

    Checks if the data sent was acknowledged by the EEPROM device.

Variables
  • static const i2c_host_interface_t * EEPROM_I2C = &I2C1

    An instance of the I2C Host driver interface for the EEPROM device.

2.3.2.2.2 Function Documentation

EEPROM_AckPoll()

bool EEPROM_AckPoll (uint8_t deviceAddress)

Checks if the data sent was acknowledged by the EEPROM device.

Precondition:

Initialize the I2C Host and the EEPROM device.

Parameters:
deviceAddress

- The EEPROM device address.

Return values:
True

- Acknowledged by the EEPROM device.

False

- Not acknowledged by the EEPROM device.

EEPROM_I2C_Read()

uint8_t EEPROM_I2C_Read (uint8_t deviceAddress, uint8_t * eepromAddress, size_t addressLength, uint8_t * readData, size_t readLength)

Reads the data from the EEPROM via the I2C bus.

Precondition:

Initialize the I2C Host and the EEPROM device.

Parameters:
uint8_t

deviceAddress - The EEPROM device address.

uint8_t*

eepromAddress - Pointer to the data buffer that holds the target memory address of the EEPROM.

size_t

addressLength - Length of the target memory address in bytes.

uint8_t

*readData - Pointer to the data buffer that holds the data read from the EEPROM.

size_t

readLength - Length of the data read from the EEPROM in bytes.

Returns:

EEPROM I2C status code.

EEPROM_I2C_Write()

uint8_t EEPROM_I2C_Write (uint8_t deviceAddress, uint8_t * data, size_t writeLength)

Writes the data to the EEPROM via the I2C bus.

Precondition:

Initialize the I2C Host and the EEPROM device.

Parameters:
uint8_t

deviceAddress - The EEPROM device address.

uint8_t*

data - Pointer to the data buffer that holds the target memory address and data of the EEPROM.

size_t

writeLength - Length of the target memory address and data in bytes.

Returns:

EEPROM I2C status code.

2.3.2.2.3 Variable Documentation

EEPROM_I2C

* EEPROM_I2C = &I2C1[static]

An instance of the I2C Host driver interface for the EEPROM device.

2.3.3 Class Documentation

2.3.3.1 EEPROM_DEVICE_CONTEXT Struct Reference

Contains the EEPROM driver context used in the API routines.

2.3.3.1.2 Member Data Documentation

The documentation for this struct was generated from the following file:

source/source-files/

eeprom_i2c_types.h

busy

bool EEPROM_DEVICE_CONTEXT::busy

Sets the software busy flag.

dataBuffer

uint8_t EEPROM_DEVICE_CONTEXT::dataBuffer[EEPROM_I2C_PAGESIZE]

Holds the data address buffer for the read and write operation.

deviceAddress

uint8_t EEPROM_DEVICE_CONTEXT::deviceAddress

Sets the I2C address of the device.

errorState

EEPROM_STATUS_t EEPROM_DEVICE_CONTEXT::errorState

Sets the error state of the operation.

firstWrite

bool EEPROM_DEVICE_CONTEXT::firstWrite

Sets the write operation flag.

readLength

size_t EEPROM_DEVICE_CONTEXT::readLength

Sets the read buffer length for the read operation.

readPtr

uint8_t* EEPROM_DEVICE_CONTEXT::readPtr

Pointer to read buffer for the read operation.

startAddress

uint32_t EEPROM_DEVICE_CONTEXT::startAddress

Sets the starting word address of the device.

switchToRead

bool EEPROM_DEVICE_CONTEXT::switchToRead

Sets the operation from Write to Read mode.

wordAddress

uint8_t EEPROM_DEVICE_CONTEXT::wordAddress[EEPROM_I2C_WORD_LEN_BYTES]

Holds the word address buffer for the device operation.

writeLength

size_t EEPROM_DEVICE_CONTEXT::writeLength

Sets the write buffer length for the write operation.

writePtr

uint8_t* EEPROM_DEVICE_CONTEXT::writePtr

Pointer to write buffer for the write operation.

2.3.3.2 eeprom_interface Struct Reference

Creates an instance of the EEPROM interface for the devices.

2.3.3.2.1 Detailed Description

Defines the EEPROM interface.

#include <eeprom_interface.h>

Public Attributes
  • bool(* SequentialWrite )(uint32_t address, uint8_t *data, size_t dataLength)

  • bool(* SequentialRead )(uint32_t address, uint8_t *data, size_t dataLength)

  • bool(* PageWrite )(uint32_t address, uint8_t *data)

  • bool(* PageRead )(uint32_t address, uint8_t *data)

  • bool(* ByteWrite )(uint32_t address, uint8_t *data)

  • bool(* ByteRead )(uint32_t address, uint8_t *data)

  • bool(* IsBusy )(void)

2.3.3.2.2 Member Data Documentation

The documentation for this struct was generated from the following file:

source/source-files/

eeprom_interface.h

ByteRead

bool(* EEPROM_INTERFACE::ByteRead) (uint32_t address, uint8_t *data)

ByteWrite

bool(* EEPROM_INTERFACE::ByteWrite) (uint32_t address, uint8_t *data)

IsBusy

bool(* EEPROM_INTERFACE::IsBusy) (void)

PageRead

bool(* EEPROM_INTERFACE::PageRead) (uint32_t address, uint8_t *data)

PageWrite

bool(* EEPROM_INTERFACE::PageWrite) (uint32_t address, uint8_t *data)

SequentialRead

bool(* EEPROM_INTERFACE::SequentialRead) (uint32_t address, uint8_t *data, size_t dataLength)

SequentialWrite

bool(* EEPROM_INTERFACE::SequentialWrite) (uint32_t address, uint8_t *data, size_t dataLength)

2.3.4 File Documentation

2.3.4.1 source/source-files/eeprom.c File Reference

Contains API definitions for the EEPROM driver.

#include "../../eeprom-lib/eeprom.h"
#include "../../eeprom-lib/eeprom_interface.h"
#include "../../eeprom-lib/eeprom_i2c_config.h"
#include "../../eeprom-lib/eeprom_i2c_types.h"
#include "../../eeprom-lib/eeprom_i2c.h"
#include <stdlib.h>

2.3.4.1.1 Functions

  • static void EEPROM_UpdateWriteData (uint16_t dataLength, uint16_t pageCounter)

    Updates the write operation parameters.

  • static uint8_t EEPROM_WordAddressLowGet (uint32_t address)

    Gets the lower byte of the word address from the target memory address.

  • static uint8_t EEPROM_WordAddressHighGet (uint32_t address)

    Gets the upper byte of the word address from the target memory address.

  • static uint8_t EEPROM_DeviceAddressGet (uint32_t address)

    Gets the device address of the EEPROM.

  • static void EEPROM_Tasks (void)

    Performs the read and write operations of the driver.

  • static void EEPROM_Close (void)

    Resets the EEPROM status.

  • bool EEPROM_SequentialWrite (uint32_t address, uint8_t *data, size_t dataLength)

    Writes n-bytes of data to a specified start address in the EEPROM device.

  • bool EEPROM_SequentialRead (uint32_t address, uint8_t *data, size_t dataLength)

    Reads n-bytes of data from a specified start address in the EEPROM device.

  • bool EEPROM_PageWrite (uint32_t address, uint8_t *data)

    Writes the data to an entire page of the EEPROM device.

  • bool EEPROM_PageRead (uint32_t address, uint8_t *data)

    Reads the data of an entire page of the EEPROM device.

  • bool EEPROM_ByteWrite (uint32_t address, uint8_t *data)

    Writes a byte of data to a specified address in the EEPROM device.

  • bool EEPROM_ByteRead (uint32_t address, uint8_t *data)

    Reads a byte of data from a specified address in the EEPROM device.

  • EEPROM_STATUS_t EEPROM_ErrorGet (void)

    Checks the type of the error encountered in the EEPROM operation.

  • bool EEPROM_IsBusy (void)

    Checks if the EEPROM device is busy.

2.3.4.1.2 Macros

  • #define MIN(a, b) ((a) < (b) ? (a) : (b))

2.3.4.1.4 Detailed Description

Contains API definitions for the EEPROM driver.

EEPROM generated driver source file.

Version: EEPROM Driver Version 1.0.0

2.3.4.1.5 Macro Definition Documentation

MIN

#define MIN( a, b) ((a) < (b) ? (a) : (b))

Computes the minimum of a and b.

2.3.4.2 source/source-files/eeprom.h File Reference

#include "eeprom_interface.h"

2.3.4.2.1 Functions

  • bool EEPROM_ByteWrite (uint32_t address, uint8_t *data)

    Writes a byte of data to a specified address in the EEPROM device.

  • bool EEPROM_ByteRead (uint32_t address, uint8_t *data)

    Reads a byte of data from a specified address in the EEPROM device.

  • bool EEPROM_IsBusy (void)

    Checks if the EEPROM device is busy.

  • bool EEPROM_SequentialWrite (uint32_t address, uint8_t *data, size_t dataLength)

    Writes n-bytes of data to a specified start address in the EEPROM device.

  • bool EEPROM_SequentialRead (uint32_t address, uint8_t *data, size_t dataLength)

    Reads n-bytes of data from a specified start address in the EEPROM device.

  • bool EEPROM_PageWrite (uint32_t address, uint8_t *data)

    Writes the data to an entire page of the EEPROM device.

  • bool EEPROM_PageRead (uint32_t address, uint8_t *data)

    Reads the data of an entire page of the EEPROM device.

  • EEPROM_STATUS_t EEPROM_ErrorGet (void)

    Checks the type of the error encountered in the EEPROM operation.

2.3.4.2.3 Detailed Description

EEPROM generated driver header file.

2.3.4.2.4 Variable Documentation

2.3.4.3 source/source-files/eeprom_i2c.c File Reference

This file contains API definitions for the EEPROM interface. This file can be modified to support other I2C drivers.

#include "../../eeprom-lib/eeprom_i2c_types.h"
#include "../../eeprom-lib/eeprom_i2c_config.h"
#include "../../eeprom-lib/eeprom_i2c.h"
#include "../../i2c_host/i2c1.h"

2.3.4.3.1 Functions

  • uint8_t EEPROM_I2C_Write (uint8_t deviceAddress, uint8_t *data, size_t writeLength)

    Writes the data to the EEPROM via the I2C bus.

  • uint8_t EEPROM_I2C_Read (uint8_t deviceAddress, uint8_t *eepromAddress, size_t addressLength, uint8_t *readData, size_t readLength)

    Reads the data from the EEPROM via the I2C bus.

  • bool EEPROM_AckPoll (uint8_t deviceAddress)

    Checks if the data sent was acknowledged by the EEPROM device.

2.3.4.3.3 Variables

  • static const i2c_host_interface_t * EEPROM_I2C = &I2C1

    An instance of the I2C Host driver interface for the EEPROM device.

2.3.4.3.4 Detailed Description

This file contains API definitions for the EEPROM interface. This file can be modified to support other I2C drivers.

EEPROM generated driver I2C interface source file.

Version: EEPROM Driver Version 1.0.0

2.3.4.3.5 Macro Definition Documentation

EEPROM_I2C_ERROR

#define EEPROM_I2C_ERROR (1U)

EEPROM_I2C_NO_ERROR

#define EEPROM_I2C_NO_ERROR (0U)

2.3.4.4 source/source-files/eeprom_i2c.h File Reference

#include <stddef.h>

2.3.4.4.1 Functions

  • uint8_t EEPROM_I2C_Write (uint8_t deviceAddress, uint8_t *data, size_t writeLength)

    Writes the data to the EEPROM via the I2C bus.

  • uint8_t EEPROM_I2C_Read (uint8_t deviceAddress, uint8_t *eepromAddress, size_t addressLength, uint8_t *readData, size_t readLength)

    Reads the data from the EEPROM via the I2C bus.

  • bool EEPROM_AckPoll (uint8_t deviceAddress)

    Checks if the data sent was acknowledged by the EEPROM device.

2.3.4.4.3 Detailed Description

EEPROM generated driver I2C interface header file.

2.3.4.4.4 Macro Definition Documentation

EEPROM_I2C_ERROR

#define EEPROM_I2C_ERROR (1U)

EEPROM_I2C_NO_ERROR

#define EEPROM_I2C_NO_ERROR (0U)

2.3.4.5 source/source-files/eeprom_i2c_config.h File Reference

This file contains device-specific constants for the EEPROM driver.

2.3.4.5.2 Detailed Description

This file contains device-specific constants for the EEPROM driver.

EEPROM generated driver configuration header file.

Version: EEPROM Driver Version 1.0.0

2.3.4.5.3 Macro Definition Documentation

EEPROM_I2C_DEVICE_ADDR

#define EEPROM_I2C_DEVICE_ADDR (0x54U)

EEPROM_I2C_PAGESIZE

#define EEPROM_I2C_PAGESIZE (256U)

EEPROM_I2C_SIZE

#define EEPROM_I2C_SIZE (262144U)

EEPROM_I2C_WORD_LEN_BIT

#define EEPROM_I2C_WORD_LEN_BIT (18U)

EEPROM_I2C_WORD_LEN_BYTES

#define EEPROM_I2C_WORD_LEN_BYTES (2U)

2.3.4.6 source/source-files/eeprom_i2c_types.h File Reference

This file contains type definitions for the EEPROM driver.

#include "eeprom_i2c_config.h"
#include "stdint.h"
#include "stdbool.h"
#include "stdlib.h"

2.3.4.6.1 Data structures

2.3.4.6.4 Detailed Description

This file contains type definitions for the EEPROM driver.

EEPROM generated driver data types header file.

Version: EEPROM Driver Version 1.0.0