Loading...
Searching...
No Matches
AT24CXXX EEPROM unit

Device driver interface for the AT24CXXX EEPROM units. More...

Detailed Description

Device driver interface for the AT24CXXX EEPROM units.

Overview

Various manufacturers such as Atmel/Microchip or ST offer small I2C EEPROMs which usually come in 8-pin packages and are used for persistent data storage of settings, counters, etc. This driver adds support for these devices with direct read and write functions.

The high level wrapper for RIOTs MTD interface to utilize the I2C EEPROMs as MTD storage is described in drivers_mtd_at24cxxx.

A list of supported devices can be found in the at24cxxx_defines.h file.

Usage

The preconfigured devices in the at24cxxx_defines.h file devices are easily accessible as pseudomodules and can be added to the Makefile of your project:

 USEMODULE += at24c02

When using one of the pseudomodules, the configuration of the device is already predefined in the AT24CXXX_PARAMS macro and can be used for the initialization:

 at24cxxx_t eeprom_dev;
 at24cxxx_params_t eeprom_params = AT24CXXX_PARAMS;

 at24cxxx_init(&eeprom_dev, &eeprom_params);


For other devices that are not yet part of the library, the generic module has to be added:

 USEMODULE += at24cxxx

The predefined macro can not be used in this case, so the parameters of the device have to be added to the at24cxxx_params_t structure manually with the values from the corresponding datasheet:

 at24cxxx_t eeprom_dev;
 at24cxxx_params_t eeprom_params = {
     .i2c = I2C_DEV(0), \
     ...
 };

 at24cxxx_init(&eeprom_dev, &eeprom_params);

Files

file  at24cxxx_defines.h
 Constants for various I2C EEPROM devices.
 
file  at24cxxx_params.h
 Default configuration for the AT24CXXX driver.
 
file  at24cxxx.h
 Device driver interface for AT24CXXX EEPROM units.
 

Data Structures

struct  at24cxxx_params
 Struct that holds initialization parameters. More...
 
struct  at24cxxx_t
 Struct that represents an AT24CXXX device. More...
 

Typedefs

typedef struct at24cxxx_params at24cxxx_params_t
 Struct that holds initialization parameters.
 

Enumerations

enum  { AT24CXXX_OK , AT24CXXX_I2C_ERROR }
 Return values. More...
 

Functions

int at24cxxx_init (at24cxxx_t *dev, const at24cxxx_params_t *params)
 Initialize an AT24CXXX device handle with AT24CXXX parameters.
 
int at24cxxx_read_byte (const at24cxxx_t *dev, uint32_t pos, void *dest)
 Read a byte at a given position pos.
 
int at24cxxx_read (const at24cxxx_t *dev, uint32_t pos, void *data, size_t len)
 Sequentially read len bytes from a given position pos.
 
int at24cxxx_write_byte (const at24cxxx_t *dev, uint32_t pos, uint8_t data)
 Write a byte at a given position pos.
 
int at24cxxx_write (const at24cxxx_t *dev, uint32_t pos, const void *data, size_t len)
 Sequentially write len bytes from a given position pos.
 
int at24cxxx_set (const at24cxxx_t *dev, uint32_t pos, uint8_t val, size_t len)
 Set len bytes from a given position pos to the value val.
 
int at24cxxx_clear (const at24cxxx_t *dev, uint32_t pos, size_t len)
 Set len bytes from position pos to AT24CXXX_CLEAR_BYTE.
 
int at24cxxx_erase (const at24cxxx_t *dev)
 Set the entire EEPROM memory to AT24CXXX_CLEAR_BYTE.
 
int at24cxxx_enable_write_protect (const at24cxxx_t *dev)
 Enable write protection.
 
int at24cxxx_disable_write_protect (const at24cxxx_t *dev)
 Disable write protection.
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Return values.

Definition at line 83 of file at24cxxx.h.

Function Documentation

◆ at24cxxx_clear()

int at24cxxx_clear ( const at24cxxx_t dev,
uint32_t  pos,
size_t  len 
)

Set len bytes from position pos to AT24CXXX_CLEAR_BYTE.

This is a wrapper around

See also
at24cxxx_set.
Parameters
[in]devAT24CXXX device handle
[in]posPosition in EEPROM memory
[in]lenRequested length to be written
Returns
See also
at24cxxx_set

◆ at24cxxx_disable_write_protect()

int at24cxxx_disable_write_protect ( const at24cxxx_t dev)

Disable write protection.

Parameters
[in]devAT24CXXX device handle
Returns
AT24CXXX_OK on success
-ENOTSUP if pin_wp was initialized with GPIO_UNDEF

◆ at24cxxx_enable_write_protect()

int at24cxxx_enable_write_protect ( const at24cxxx_t dev)

Enable write protection.

Parameters
[in]devAT24CXXX device handle
Returns
AT24CXXX_OK on success
-ENOTSUP if pin_wp was initialized with GPIO_UNDEF

◆ at24cxxx_erase()

int at24cxxx_erase ( const at24cxxx_t dev)

Set the entire EEPROM memory to AT24CXXX_CLEAR_BYTE.

This is a wrapper around

See also
at24cxxx_clear.
Parameters
[in]devAT24CXXX device handle
Returns
See also
at24cxxx_set

◆ at24cxxx_init()

int at24cxxx_init ( at24cxxx_t dev,
const at24cxxx_params_t params 
)

Initialize an AT24CXXX device handle with AT24CXXX parameters.

Parameters
[in,out]devAT24CXXX device handle
[in]paramsAT24CXXX parameters
Returns
AT24CXXX_OK on success
-AT24CXXX_I2C_ERROR if i2c could not be acquired
-EINVAL if input parameters are NULL

◆ at24cxxx_read()

int at24cxxx_read ( const at24cxxx_t dev,
uint32_t  pos,
void *  data,
size_t  len 
)

Sequentially read len bytes from a given position pos.

Parameters
[in]devAT24CXXX device handle
[in]posPosition in EEPROM memory
[out]dataRead buffer
[in]lenRequested length to be read
Returns
AT24CXXX_OK on success
-ERANGE if pos + len is out of bounds
See also
i2c_read_regs

◆ at24cxxx_read_byte()

int at24cxxx_read_byte ( const at24cxxx_t dev,
uint32_t  pos,
void *  dest 
)

Read a byte at a given position pos.

Parameters
[in]devAT24CXXX device handle
[in]posPosition in EEPROM memory
[out]destRead byte
Returns
AT24CXXX_OK on success
-ERANGE if pos is out of bounds
See also
i2c_read_regs

◆ at24cxxx_set()

int at24cxxx_set ( const at24cxxx_t dev,
uint32_t  pos,
uint8_t  val,
size_t  len 
)

Set len bytes from a given position pos to the value val.

Writing is performed in chunks of size AT24CXXX_SET_BUFFER_SIZE.

Parameters
[in]devAT24CXXX device handle
[in]posPosition in EEPROM memory
[in]valValue to be set
[in]lenRequested length to be written
Returns
AT24CXXX_OK on success
-ERANGE if pos + len is out of bounds
See also
i2c_write_byte

◆ at24cxxx_write()

int at24cxxx_write ( const at24cxxx_t dev,
uint32_t  pos,
const void *  data,
size_t  len 
)

Sequentially write len bytes from a given position pos.

Writing is performed in chunks of size AT24CXXX_PAGE_SIZE.

Parameters
[in]devAT24CXXX device handle
[in]posPosition in EEPROM memory
[in]dataWrite buffer
[in]lenRequested length to be written
Returns
AT24CXXX_OK on success
-ERANGE if pos + len is out of bounds
See also
i2c_write_regs

◆ at24cxxx_write_byte()

int at24cxxx_write_byte ( const at24cxxx_t dev,
uint32_t  pos,
uint8_t  data 
)

Write a byte at a given position pos.

Parameters
[in]devAT24CXXX device handle
[in]posPosition in EEPROM memory
[in]dataValue to be written
Returns
AT24CXXX_OK on success
-ERANGE if pos is out of bounds
See also
i2c_write_regs