EEPROM-24xx01x - 1K I2C Serial EEPROM

Description

Library for interfacing NXP 24xx01x 1K I2C Serial EEPROM

This library supports up to four 24xx01x, each having to be connected to its own I2C interface.

The Microchip Technology Inc. 24xx01x is a 1 Kbit Electrically Erasable PROM. The device is organized as one block of 128 x 8-bit memory with a 2-wire serial interface. -) I2C interface with communication speed up to 1 MHz -) Page write time: maximum 5 ms -) 8-Byte internal page write buffer

OVERVIEW

EEPR24xx01x_Abstract:
This library can be used to handle the Microchip Technology Inc. 24xx01x 1 Kbit Electrically Erasable PROM. The library supports up to four 24xx01x, each having to be connected to its own I2C interface. The combination of a 24xx01x and the associated I2C interface is referred to as "Write Slot". If the rapidM2M hardware used does not have enough I2C interfaces, an NXP PCA9646 Buffered 4-channel 2-wire bus switch can be used.

Interfaces: 1x I2C (per 24xx01x)

The EEPR24xx01x is a 1 Kbit Electrically Erasable PROM.
  • I2C interface with communication speed up to 1 MHz
  • Page write time: maximum 5 ms
  • 8-Byte internal page write buffer
  • EEPR24xx01x_How_to_use:
    To use the EEPROM-24xx01x-mt library the following functions must be defined:
    EEPR24xx01x_GetHandle()
    EEPR24xx01x_SetHandle()
    /* Hardware setup */ const { PORT_I2C = 0, // The first I2C interface should be used. } /* Example Setup */ const { TEST_ADDR = 0x10, // Write start address } /* Handles for available chips */ new h24LC01_Cfg[TEEPR24xx01x_Handle]; // Handle to manage the EEPR24xx01x /* Callback to handle the EEPR24xx01x readout */ #callback Readout() { // Temporary memory for the read value new iReadValue; // Check if the EEPR24xx01x write has finished and a readout is possible if(EEPR24xx01x_GetState(h24LC01_Cfg) == EEPR24xx01x_STATE_READY) { // Readout from the selected address catch(EEPR24xx01x_Read(h24LC01_Cfg, TEST_ADDR, iReadValue)); // Print the received data #log("Read Data: %02X", iReadValue); } else { #log("Write still in process!") // Restart the readout callback since the write process is still in progress setTimeout(Readout, EEPR24xx01x_Write_CYCLE_TIME); } } /** * Function that is called up when the device has been prepared for the start of the application by the * "salve" function. I.e. the device is ready for proceeding with the application. */ #callback Test24LC01B() { new iByteWriteValue; // Inits the I2C interface catch(rM2M_I2cInit(PORT_I2C, EEPR24xx01x_CLOCK, 0)); // Init EEPROM library catch(EEPR24xx01x_Init(h24LC01_Cfg, PORT_I2C)); // Set the data to write iByteWriteValue = 0xAB; // Write chosen byte to EEPROM and trigger readout catch(EEPR24xx01x_Write(h24LC01_Cfg, TEST_ADDR, iByteWriteValue)); // Directly call the callback ___Readout(); } /* Application entry point */ main(){ salve(Test24LC01B); } /* Library function that has to be defined, which returns the correct handle for a specific write slot */ EEPR24xx01x_GetHandle(handle[TEEPR24xx01x_Handle], iWriteSlot) { //If only a single EEPR24xx01x is used, the "iWriteSlot" parameter can be ignored handle = h24LC01_Cfg; } /* Library function that has to be defined, which updates the correct handle for a specific write slot */ EEPR24xx01x_SetHandle(handle[TEEPR24xx01x_Handle], iWriteSlot) { //If only a single EEPR24xx01x is used, the "iWriteSlot" parameter can be ignored h24LC01_Cfg = handle; }
    EEPR24xx01x_Config:
    To use the EEPROM-24xx01x-mt library the following functions must be defined:
    EEPR24xx01x_GetHandle()
    EEPR24xx01x_SetHandle()
    Each device handle for an EEPR24xx01x contains a buffer to write a data block into the EEPR24xx01x using the EEPR24xx01x_SequentialWrite() function. To select the buffer size (i.e. the number of bytes that can be written at once), add the following macro to the main.dde file.
    If the macro is not defined a buffer size of 128 bytes is used.
    /** * Use this macro the select a specific buffer size for the EEPR24xx01x handles. */ #define EEPR24xx01x_BUFFER_SIZE 128

    REQUIRED

    EEPR24xx01x_GetHandle(handle[TEEPR24xx01x_Handle], iWriteSlot)

    Function for transferring a device handle of an specific EEPR24xx01x from the application to the library


    The function has to be defined by the user of the library to ensure correct library operation. Up to four write slots are supported by the library.
    handle : TEEPR24xx01x_Handle - Variable for receiving the device handle of a specific EEPR24xx01x (application to library)
    iWriteSlot : s32 - The write slot number that is used for the handle of a specific EEPR24xx01x

    If only a single EEPR24xx01x is used, the "iWriteSlot" parameter can be ignored
    EEPR24xx01x_GetHandle(handle[TEEPR24xx01x_Handle], iWriteSlot) { handle = h24LC01_Cfg; }

    If multiple EEPR24xx01x are used, the parameter "iWriteSlot" must be taken into account
    EEPR24xx01x_GetHandle(handle[TEEPR24xx01x_Handle], iWriteSlot) { switch(iWriteSlot) { case(EEPR24xx01x_WRITE_SLOT1): handle = h24LC01_Cfg_1; case(EEPR24xx01x_WRITE_SLOT2): handle = h24LC01_Cfg_2; case(EEPR24xx01x_WRITE_SLOT3): handle = h24LC01_Cfg_3; case(EEPR24xx01x_WRITE_SLOT4): handle = h24LC01_Cfg_4; } }
    EEPR24xx01x_SetHandle(handle[TEEPR24xx01x_Handle], iWriteSlot)

    Function for transferring a device handle of an specific EEPR24xx01x from the library to the application


    The function has to be defined by the user of the library to ensure correct library operation. Up to four write slots are supported by the library.
    handle : TEEPR24xx01x_Handle - Variable for transfering the device handle of a specific EEPR24xx01x (library to application)
    iWriteSlot : s32 - The write slot number that is used for the handle of a specific EEPR24xx01x

    If only a single EEPR24xx01x is used, the "iWriteSlot" parameter can be ignored
    EEPR24xx01x_SetHandle(handle[TEEPR24xx01x_Handle], iWriteSlot) { h24LC01_Cfg = handle; }

    If multiple EEPR24xx01x are used, the parameter "iWriteSlot" must be taken into account
    EEPR24xx01x_SetHandle(handle[TEEPR24xx01x_Handle], iWriteSlot) { switch(iWriteSlot) { case(EEPR24xx01x_WRITE_SLOT1): h24LC01_Cfg_1 = handle; case(EEPR24xx01x_WRITE_SLOT2): h24LC01_Cfg_2 = handle; case(EEPR24xx01x_WRITE_SLOT3): h24LC01_Cfg_3 = handle; case(EEPR24xx01x_WRITE_SLOT4): h24LC01_Cfg_4 = handle; } }

    BASIC

    EEPR24xx01x_CLOCK -

    typical I2C clock speed to be used

    EEPR24xx01x_I2C_ADR0:

    Available I2C address

    EEPR24xx01x_Write_CYCLE_TIME -

    The maximum page write cycle time of the EEPR24xx01x

    EEPR24xx01x_STATE_x:

    The possible EEPR24xx01x handle states

    EEPR24xx01x_STATE_READY - The EEPR24xx01x is ready for new commands.
    EEPR24xx01x_STATE_BUSY - A sequential write is in progress
    EEPR24xx01x_STATE_ERROR - The last operation failed
    EEPR24xx01x_STATE_FINISHED - Waiting until the last write operation is completed
    EEPR24xx01x_Init(handle[TEEPR24xx01x_Handle], i2c, addr=EEPR24xx01x_I2C_ADR0, writeSlot=EEPR24xx01x_WRITE_SLOT1)

    Initializes communication with the EEPR24xx01x and prepares the EEPR24xx01x for use


    First copies the I2C port, I2C address and the write slot number to the transferred empty device handle. Afterwards the EEPR24xx01x word address is set to zero.

    handle : TEEPR24xx01x_Handle - Empty device handle for a EEPR24xx01x
    i2c : s32 - I2C interface where EEPR24xx01x is connected to
    The I2C interface must be initialized before using rM2M_I2cInit().
    addr : s32 - I2C Address of the chip
    Use only EEPR24xx01x_I2C_ADR0
    writeSlot - Write slot that is to be used for the EEPR24xx01x
    Use only the Write slot numbers specified under EEPR24xx01x_WRITE_SLOTx
    returns : s32
    OK - If successful
    ERROR - The used write slot number is invalid
    < OK - If another error occurs
    EEPR24xx01x_Read(handle[TEEPR24xx01x_Handle], iAddr, &iValue)

    Read a single byte from the EEPR24xx01x


    First perfoms several checks to ensure that the provided address and state of the library are valid. Afterwards reads a single byte from the provided address and returns the read data.

    handle : TEEPR24xx01x_Handle - Device handle of a specific EEPR24xx01x (Initialized by EEPR24xx01x_Init() )
    iAddr : s32 - Address from which the data is read
    iValue : s32 - Variable for storing the read data
    The data will be returned as u8 (0-0xFF)
    returns : s32
    OK - If successful
    ERROR - if one of the following errors occurs
  • Address invalid
  • A sequential write is in progress
  • Waiting until the last write operation is completed
  • < OK - If another error occurs
    EEPR24xx01x_SequentialRead(handle[TEEPR24xx01x_Handle], iAddr, aBuffer{}, iLen)

    Read a specific number of bytes from the EEPR24xx01x


    First perfoms several checks to ensure that the provided address, length and state of the library are valid. Afterwards reads out the number of bytes specified into the user provided buffer, starting at the specified address.

    handle : TEEPR24xx01x_Handle - Device handle of a specific EEPR24xx01x (Initialized by EEPR24xx01x_Init() )
    iAddr : s32 - Start address from which the data is read
    aBuffer{} : u8 - Buffer to store the read data
    iLen : s32 - Number of bytes to read
    returns : s32
    OK - If successful
    ERROR - if one of the following errors occurs
  • Address invalid
  • Address + length is outside the valid address range
  • A sequential write is in progress
  • Waiting until the last write operation is completed
  • < OK - If another error occurs
    EEPR24xx01x_Write(handle[TEEPR24xx01x_Handle], iAddr, iValue)

    Write a single byte to the EEPR24xx01x


    First perfoms several checks to ensure that the provided address, value and state of the library are valid. Afterwards writes a single byte to the provided address.

    handle : TEEPR24xx01x_Handle - Device handle of a specific EEPR24xx01x (Initialized by EEPR24xx01x_Init() )
    iAddr : s32 - Address where to write the data
    iValue : s32 - Value to write
    The data must be transferred as u8 (0-0xFF)
    returns : s32
    OK - If successful
    ERROR - if one of the following errors occurs
  • Address invalid
  • The transferred value is not a u8
  • A sequential write is in progress
  • Waiting until the last write operation is completed
  • < OK - If another error occurs
    EEPR24xx01x_SequentialWrite(handle[TEEPR24xx01x_Handle], iAddr, aBuffer{}, iLen)

    Write a specific number of bytes to the EEPR24xx01x


    First perfoms several checks to ensure that the provided address, length and state of the library are valid. Afterwards updates the state of the handle to EEPR24xx01x_STATE_BUSY, copies the provided data into an handle specific buffer and sets the necessary variables in the handle for the write process and initiates this process.

    The sequential write process uses the application defined functions (EEPR24xx01x_GetHandle() and EEPR24xx01x_SetHandle()) to read and update the specific handles of the EEPR24xx01x.
    handle : TEEPR24xx01x_Handle - Device handle of a specific EEPR24xx01x (Initialized by EEPR24xx01x_Init() )
    iAddr : s32 - Start address of the write process
    aBuffer{} : u8 - Data to write
    iLen : s32 - Number of bytes to write
    returns : s32
    OK - If successful
    ERROR - if one of the following errors occurs
  • Address invalid
  • Address + length is outside the valid address range
  • Number of bytes to write exceeds the size of the handle specific buffer
  • A sequential write is in progress
  • Waiting until the last write operation is completed
  • < OK - If another error occurs
    EEPR24xx01x_GetState(handle[TEEPR24xx01x_Handle])

    Returns the current state of a specific EEPR24xx01x


    handle : TEEPR24xx01x_Handle - Device handle of a specific EEPR24xx01x (Initialized by EEPR24xx01x_Init() )
    returns : s32 - Current state of the EEPR24xx01x (see EEPR24xx01x_STATE_x)

    EXPERT

    EEPR24FC01_CLOCK_MAX -

    absolute maximum I2C clock speed for a specific EEPR24FC01

    EEPR24AA01_LOW_VOLTAGE_CLOCK -

    I2C clock speed for the EEPR24AA01 below 2.5V

    EEPR24xx01x_WRITE_SLOTx:

    Available "Write Slots". The combination of a 24xx01x and the associated I2C interface is referred to as "Write Slot". Each "Write Slot" requires its own EEPR24xx01x device handle.

    EEPR24xx01x_WRITE_SLOT1
    EEPR24xx01x_WRITE_SLOT2
    EEPR24xx01x_WRITE_SLOT3
    EEPR24xx01x_WRITE_SLOT4
    EEPR24xx01x_Com(handle[TEEPR24xx01x_Handle], aData{}, writelen, readlen)

    Performs raw I2C read/write communication with a specific EEPR24xx01x.


    handle : TEEPR24xx01x_Handle - Device handle of a specific EEPR24xx01x (Initialized by EEPR24xx01x_Init() )
    aData{} : u8 - Array in which the data to be sent must initially be saved. Once the data has been sent, the array is used as a memory for the data to be received.
    writelen : s32 - Number of bytes to be sent
    readlen : s32 - Number of bytes to be received
    returns : s32
    OK - if successful
    ERROR - if one of the following errors occurs
  • Number of bytes to be sent >255
  • Number of bytes to be received >255
  • < OK - if an error occurs
    EEPR24xx01x_ResetWriteState(handle[TEEPR24xx01x_Handle])

    Resets the state of a specific handle to EEPR24xx01x_STATE_READY. The internal write offsets, address and data length are also reset to zero.


    handle : TEEPR24xx01x_Handle - Device handle of a specific EEPR24xx01x (Initialized by EEPR24xx01x_Init() )

    DEBUG

    EEPR24xx01x_Debug_Config:
    To configure debug mode add the following macro to the main.dde file.
    /** * Use this macro to configure the debug mode: * * 0: No debugging * 1: In the event of an error, the return values of the functions for accessing * the EEPR24xx01x are issued via the console. */ #define EEPR24xx01x_DEBUG 0

    On this page

    EEPROM-24xx01x - 1K I2C Serial EEPROM