---
name: "avr_eeprom"
section: "3avr"
platform: "linux"
package: "avr-libc"
version: "1:2.2.1-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/avr_eeprom"
---

# avr\_eeprom(3avr)

\<avr/eeprom.h\>: EEPROM handling

## NAME

avr\_eeprom - \<avr/eeprom.h\>: EEPROM handling

## SYNOPSIS

### Macros

\#define **EEMEM**   \_\_attribute\_\_((\_\_section\_\_('.eeprom')))\
 \#define **eeprom\_is\_ready**()\
 \#define **eeprom\_busy\_wait**()   do {} while (!**eeprom\_is\_ready**())\

### Functions

**uint8\_t** **eeprom\_read\_byte** (const **uint8\_t** \*\_\_p)\
 **uint16\_t** **eeprom\_read\_word** (const **uint16\_t** \*\_\_p)\
 **uint32\_t** **eeprom\_read\_dword** (const **uint32\_t** \*\_\_p)\
 **uint64\_t** **eeprom\_read\_qword** (const **uint64\_t** \*\_\_p)\
 float **eeprom\_read\_float** (const float \*\_\_p)\
 double **eeprom\_read\_double** (const double \*\_\_p)\
 long double **eeprom\_read\_long\_double** (const long double \*\_\_p)\
 void **eeprom\_read\_block** (void \*\_\_dst, const void \*\_\_src, size\_t \_\_n)\
 void **eeprom\_write\_byte** (**uint8\_t** \*\_\_p, **uint8\_t** \_\_value)\
 void **eeprom\_write\_word** (**uint16\_t** \*\_\_p, **uint16\_t** \_\_value)\
 void **eeprom\_write\_dword** (**uint32\_t** \*\_\_p, **uint32\_t** \_\_value)\
 void **eeprom\_write\_qword** (**uint64\_t** \*\_\_p, **uint64\_t** \_\_value)\
 void **eeprom\_write\_float** (float \*\_\_p, float \_\_value)\
 void **eeprom\_write\_double** (double \*\_\_p, double \_\_value)\
 void **eeprom\_write\_long\_double** (long double \*\_\_p, long double \_\_value)\
 void **eeprom\_write\_block** (const void \*\_\_src, void \*\_\_dst, size\_t \_\_n)\
 void **eeprom\_update\_byte** (**uint8\_t** \*\_\_p, **uint8\_t** \_\_value)\
 void **eeprom\_update\_word** (**uint16\_t** \*\_\_p, **uint16\_t** \_\_value)\
 void **eeprom\_update\_dword** (**uint32\_t** \*\_\_p, **uint32\_t** \_\_value)\
 void **eeprom\_update\_qword** (**uint64\_t** \*\_\_p, **uint64\_t** \_\_value)\
 void **eeprom\_update\_float** (float \*\_\_p, float \_\_value)\
 void **eeprom\_update\_double** (double \*\_\_p, double \_\_value)\
 void **eeprom\_update\_long\_double** (long double \*\_\_p, long double \_\_value)\
 void **eeprom\_update\_block** (const void \*\_\_src, void \*\_\_dst, size\_t \_\_n)\

### IAR C compatibility defines

\#define **\_EEPUT**(addr,  val)   **eeprom\_write\_byte** ((**uint8\_t** \*)(addr), (**uint8\_t**)(val))\
 \#define **\_\_EEPUT**(addr,  val)   **eeprom\_write\_byte** ((**uint8\_t** \*)(addr), (**uint8\_t**)(val))\
 \#define **\_EEGET**(var,  addr)   (var) = **eeprom\_read\_byte** ((const **uint8\_t** \*)(addr))\
 \#define **\_\_EEGET**(var,  addr)   (var) = **eeprom\_read\_byte** ((const **uint8\_t** \*)(addr))\

## Detailed Description

```
#include <avr/eeprom.h>
```

This header file declares the interface to some simple library routines suitable for handling the data EEPROM contained in the AVR microcontrollers. The implementation uses a simple polled mode interface. Applications that require interrupt-controlled EEPROM access to ensure that no time will be wasted in spinloops will have to deploy their own implementation.

**Notes:**

- •

  In addition to the write functions there is a set of update ones. This functions read each byte first and skip the burning if the old value is the same with new. The scaning direction is from high address to low, to obtain quick return in common cases.

- •

  All of the read/write functions first make sure the EEPROM is ready to be accessed. Since this may cause long delays if a write operation is still pending, time-critical applications should first poll the EEPROM e. g. using **eeprom\_is\_ready()** before attempting any actual I/O. But this functions does not wait until SELFPRGEN in SPMCSR becomes zero. Do this manually, if your softwate contains the Flash burning.

- •

  As these functions modify IO registers, they are known to be non-reentrant. If any of these functions are used from both, standard and interrupt context, the applications must ensure proper protection (e.g. by disabling interrupts before accessing them).

- •

  All write functions force erase\_and\_write programming mode.

- •

  For Xmega the EEPROM start address is 0, like other architectures. The reading functions add the 0x2000 value to use EEPROM mapping into data space.

## Macro Definition Documentation

### #define \_\_EEGET(var, addr) (var) = eeprom\_read\_byte ((const uint8\_t \*)(addr))

Read a byte from EEPROM. Compatibility define for IAR C.

### #define \_\_EEPUT(addr, val) eeprom\_write\_byte ((uint8\_t \*)(addr), (uint8\_t)(val))

Write a byte to EEPROM. Compatibility define for IAR C.

### #define \_EEGET(var, addr) (var) = eeprom\_read\_byte ((const uint8\_t \*)(addr))

Read a byte from EEPROM. Compatibility define for IAR C.

### #define \_EEPUT(addr, val) eeprom\_write\_byte ((uint8\_t \*)(addr), (uint8\_t)(val))

Write a byte to EEPROM. Compatibility define for IAR C.

### #define EEMEM \_\_attribute\_\_((\_\_section\_\_('.eeprom')))

Attribute expression causing a variable to be allocated within the .eeprom section.

### #define eeprom\_busy\_wait() do {} while (!eeprom\_is\_ready())

Loops until the eeprom is no longer busy.

**Returns**

Nothing.

### #define eeprom\_is\_ready()

**Returns**

1 if EEPROM is ready for a new read/write operation, 0 if not.

## Function Documentation

### void eeprom\_read\_block (void \* \_\_dst, const void \* \_\_src, size\_t \_\_n)

Read a block of *\_\_n* bytes from EEPROM address *\_\_src* to SRAM *\_\_dst*.

### uint8\_t eeprom\_read\_byte (const uint8\_t \* \_\_p)

Read one byte from EEPROM address *\_\_p*.

### double eeprom\_read\_double (const double \* \_\_p)

Read one double value (little endian) from EEPROM address *\_\_p*.

### uint32\_t eeprom\_read\_dword (const uint32\_t \* \_\_p)

Read one 32-bit double word (little endian) from EEPROM address *\_\_p*.

### float eeprom\_read\_float (const float \* \_\_p)

Read one float value (little endian) from EEPROM address *\_\_p*.

### long double eeprom\_read\_long\_double (const long double \* \_\_p)

Read one long double value (little endian) from EEPROM address *\_\_p*.

### uint64\_t eeprom\_read\_qword (const uint64\_t \* \_\_p)

Read one 64-bit quad word (little endian) from EEPROM address *\_\_p*.

### uint16\_t eeprom\_read\_word (const uint16\_t \* \_\_p)

Read one 16-bit word (little endian) from EEPROM address *\_\_p*.

### void eeprom\_update\_block (const void \* \_\_src, void \* \_\_dst, size\_t \_\_n)

Update a block of *\_\_n* bytes at EEPROM address *\_\_dst* from *\_\_src*.

**Note**

The argument order is mismatch with common functions like strcpy().

### void eeprom\_update\_byte (uint8\_t \* \_\_p, uint8\_t \_\_value)

Update a byte *\_\_value* at EEPROM address *\_\_p*.

### void eeprom\_update\_double (double \* \_\_p, double \_\_value)

Update a double *\_\_value* at EEPROM address *\_\_p*.

### void eeprom\_update\_dword (uint32\_t \* \_\_p, uint32\_t \_\_value)

Update a 32-bit double word *\_\_value* at EEPROM address *\_\_p*.

### void eeprom\_update\_float (float \* \_\_p, float \_\_value)

Update a float *\_\_value* at EEPROM address *\_\_p*.

### void eeprom\_update\_long\_double (long double \* \_\_p, long double \_\_value)

Update a long double *\_\_value* at EEPROM address *\_\_p*.

### void eeprom\_update\_qword (uint64\_t \* \_\_p, uint64\_t \_\_value)

Update a 64-bit quad word *\_\_value* at EEPROM address *\_\_p*.

### void eeprom\_update\_word (uint16\_t \* \_\_p, uint16\_t \_\_value)

Update a word *\_\_value* at EEPROM address *\_\_p*.

### void eeprom\_write\_block (const void \* \_\_src, void \* \_\_dst, size\_t \_\_n)

Write a block of *\_\_n* bytes to EEPROM address *\_\_dst* from *\_\_src*.

**Note**

The argument order is mismatch with common functions like strcpy().

### void eeprom\_write\_byte (uint8\_t \* \_\_p, uint8\_t \_\_value)

Write a byte *\_\_value* to EEPROM address *\_\_p*.

### void eeprom\_write\_double (double \* \_\_p, double \_\_value)

Write a double *\_\_value* to EEPROM address *\_\_p*.

### void eeprom\_write\_dword (uint32\_t \* \_\_p, uint32\_t \_\_value)

Write a 32-bit double word *\_\_value* to EEPROM address *\_\_p*.

### void eeprom\_write\_float (float \* \_\_p, float \_\_value)

Write a float *\_\_value* to EEPROM address *\_\_p*.

### void eeprom\_write\_long\_double (long double \* \_\_p, long double \_\_value)

Write a long double *\_\_value* to EEPROM address *\_\_p*.

### void eeprom\_write\_qword (uint64\_t \* \_\_p, uint64\_t \_\_value)

Write a 64-bit quad word *\_\_value* to EEPROM address *\_\_p*.

### void eeprom\_write\_word (uint16\_t \* \_\_p, uint16\_t \_\_value)

Write a word *\_\_value* to EEPROM address *\_\_p*.

## Author

Generated automatically by Doxygen for AVR-LibC from the source code.
