at24cm0x 1.0
at24cm0x driver library
Loading...
Searching...
No Matches
at24cm0x

Version: 1.0 Release Build License GPLv3

AT24CM0X EEPROM Driver

Ask DeepWiki

This hardware abstracted driver can be used to interact with an AT24CM0X over TWI/I2C. The hardware layer is fully abstract an can be switched between different plattforms. The TWI/I2C library has to impelement the twi.h-header used in this repository.

File Structure

File Structure

drivers/
└── prom/
└── at24cm0x/
├── at24cm0x.c
└── at24cm0x.h
hal/
├── common/
| ├── defines/
| | └── TWI_defines.h
| └── enums/
| └── TWI_enums.h
└── avr0/
└── twi/
├── twi.c
└── twi.h
utils/
├── macros/
| └── stringify.h
└── systick/
├── systick.c
└── systick.h

The plattform avr0 can completely be exchanged with any other hardware abstraction library.

Downloads

The library can be downloaded (zip or tar), cloned or used as submodule in a project.

Type File Description
Library zip / tar AT24CM0X eeprom library including all required libraries (including hal-avr0-twi).

Using with git clone

mkdir -p ./drivers/prom/
git clone https://github.com/0x007E/drivers-prom-at24cm0x.git ./drivers/prom
mv ./drivers/prom/drivers-prom-at24cm0x ./drivers/prom/at24cm0x
mkdir -p ./hal/
git clone https://github.com/0x007E/hal-common.git ./hal
mv ./hal/hal-common ./hal/common
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Hardware abstraction layer of TWI (Must fit the used plattform)
mkdir -p ./hal/avr0/
git clone https://github.com/0x007E/hal-avr0-twi.git ./hal/avr0
mv ./hal/avr0/hal-avr0-twi ./hal/avr0/twi
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
mkdir -p ./utils/
git clone https://github.com/0x007E/utils-macros.git ./utils
git clone https://github.com/0x007E/utils-systick.git ./utils
mv ./utils/utils-macros ./utils/macros
mv ./utils/utils-systick ./utils/systick

Using as git submodule

git submodule add https://github.com/0x007E/drivers-prom-at24cm0x.git drivers/prom/at24cm0x
git submodule add https://github.com/0x007E/hal-common.git hal/common
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Hardware abstraction layer of TWI (Must fit the used plattform)
git submodule add https://github.com/0x007E/hal-avr0-twi.git hal/avr0/twi
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
git submodule add https://github.com/0x007E/utils-macros.git utils/macros
git submodule add https://github.com/0x007E/utils-systick.git utils/systick

Programming

#include "../hal/PLATFORM/twi/twi.h"
#include "../lib/drivers/prom/at24cm0x/at24cm0x.h"
#include "../lib/utils/systick/systick.h"
// Called every ~ milli-/microsecond!
ISR(...)
{
}
void systick_timer_wait_ms(unsigned int ms)
{
}
// Only necessary if AT24CM0X_WP_CONTROL_EN define is set!
// If the EEPROM WP Pin is connectet to the microcontroller the
// EEPROM library can enable/disable the WP pin when necessary.
// This prevents the EEPROM to be written accidentally through
// the twi bus.
{
if(mode)
{
// Set WP_PIN low (write protect disabled)
return;
}
// Set WP_PIN high (write protect enabled)
}
int main(void)
{
// If more AT24CM0X devices share the same bus the AT24CM0X_MULTI_DEVICES
// define can be enabled. This enables the possibility to select different
// AT24CM0X devices on the bus!
if(at24cm0x_write_byte(0x00000000, 0x01) == AT24CM0X_Status_Done)
{
// Byte written!
}
char buffer[] = "Sample text into buffer";
if(at24cm0x_write_page(0x00000000UL, (unsigned char *)buffer, sizeof(buffer)/sizeof(buffer[0]) == AT24CM0X_Status_Done))
{
// Buffer written!
}
if(at24cm0x_read_sequential(0x00000000UL, (unsigned char*)buffer, sizeof(buffer)/sizeof(buffer[0])) == AT24CM0X_Status_Done)
{
// Output -> buffer data
}
unsigned char temp = '\0';
if(at24cm0x_read_byte(0x00000000UL, &temp) == AT24CM0X_Status_Done)
{
// Output -> single byte
}
{
// Output -> current address
}
}
AT24CM0X_Status at24cm0x_read_sequential(unsigned long address, unsigned char *data, unsigned int size)
Reads a sequence of bytes from the AT24CM0X EEPROM.
Definition at24cm0x.c:322
AT24CM0X_Status at24cm0x_write_page(unsigned int page, unsigned char *data, unsigned int size)
Writes a sequence of bytes to a single EEPROM page.
Definition at24cm0x.c:172
void at24cm0x_init(void)
Initializes the AT24CM0X EEPROM driver.
Definition at24cm0x.c:32
AT24CM0X_Status at24cm0x_write_byte(unsigned long address, unsigned char data)
Writes a single byte to the AT24CM0X EEPROM.
Definition at24cm0x.c:104
AT24CM0X_Status at24cm0x_read_current_byte(unsigned char *data)
Reads the current byte from the AT24CM0X EEPROM.
Definition at24cm0x.c:248
AT24CM0X_Status at24cm0x_read_byte(unsigned long address, unsigned char *data)
Reads a single byte from the AT24CM0X EEPROM.
Definition at24cm0x.c:280
void at24cm0x_device(unsigned char identifier)
Selects the active AT24CM0X device.
Definition at24cm0x.c:54
enum AT24CM0X_WP_Mode_t AT24CM0X_WP_Mode
Alias for enum AT24CM0X_WP_Mode_t representing WP control modes.
Definition at24cm0x.h:266
@ AT24CM0X_Status_Done
Definition at24cm0x.h:278
#define AT24CM0X_BASE_ADDRESS
Base I2C address of the AT24CM0X EEPROM device.
Definition at24cm0x.h:112
void at24cm0x_wp(AT24CM0X_WP_Mode mode)
void systick_init(void)
Initializes the SysTick timer module.
Definition systick.c:35
void systick_tick(void)
Increments the SysTick timer tick counter.
Definition systick.c:61
void systick_timer_wait(unsigned int ticks)
Blocks execution for a specified number of SysTick ticks.
Definition systick.c:168
void systick_timer_wait_ms(unsigned int ms)
unsigned char twi_init(void)
Initialize the TWI (I2C) hardware interface in master mode.
Definition twi.c:36

Additional Information

Type Link Description
AT24CM01 pdf AT24CM01 TWI/I2C EEPROM
AT24CM02 pdf AT24CM02 TWI/I2C EEPROM

R. GAECHTER