gnea\grbl-Mega  1.0f
Source Code Documentation ( Internal Workings )
eeprom.c File Reference
#include <avr/io.h>
#include <avr/interrupt.h>

Go to the source code of this file.

Macros

#define EEPE   EEWE
 These EEPROM bits have different names on different devices. More...
 
#define EEMPE   EEMWE
 EEPROM master program/write enable. More...
 
#define EEPM1   5
 These two are unfortunately not defined in the device include files. More...
 
#define EEPM0   4
 EEPROM Programming Mode Bit 0. More...
 
#define EEPROM_IGNORE_SELFPROG
 Define to reduce code size. More...
 

Functions

unsigned char eeprom_get_char (unsigned int addr)
 Read byte from EEPROM. More...
 
void eeprom_put_char (unsigned int addr, unsigned char new_value)
 Write byte to EEPROM. More...
 
void memcpy_to_eeprom_with_checksum (unsigned int destination, char *source, unsigned int size)
 Extensions added as part of Grbl. More...
 
int memcpy_from_eeprom_with_checksum (char *destination, unsigned int source, unsigned int size)
 

Detailed Description

Atmel Corporation

  • Supported devices: All devices with split EEPROM erase/write capabilities can be used. The example is written for ATmega48.
  • AppNote: AVR103 - Using the EEPROM Programming Modes.
  • Description: Example on how to use the split EEPROM erase/write capabilities in e.g. ATmega48. All EEPROM programming modes are tested, i.e. Erase+Write, Erase-only and Write-only.
Revision
1.6
Date
Friday, February 11, 2005 07:16:44 UTC

Definition in file eeprom.c.

Macro Definition Documentation

#define EEMPE   EEMWE

EEPROM master program/write enable.

Definition at line 30 of file eeprom.c.

#define EEPE   EEWE

These EEPROM bits have different names on different devices.

EEPROM program/write enable.

Definition at line 29 of file eeprom.c.

#define EEPM0   4

EEPROM Programming Mode Bit 0.

Definition at line 35 of file eeprom.c.

#define EEPM1   5

These two are unfortunately not defined in the device include files.

EEPROM Programming Mode Bit 1.

Definition at line 34 of file eeprom.c.

#define EEPROM_IGNORE_SELFPROG

Define to reduce code size.

Remove SPM flag polling.

Definition at line 38 of file eeprom.c.

Function Documentation

unsigned char eeprom_get_char ( unsigned int  addr)

Read byte from EEPROM.

This function reads one byte from a given EEPROM address.

Note
The CPU is halted for 4 clock cycles during EEPROM read.
Parameters
addrEEPROM address to read from.
Returns
The byte read from the EEPROM address.

< Wait for completion of previous write.

< Set EEPROM address register.

< Start EEPROM read operation.

< Return the byte read from EEPROM.

Definition at line 49 of file eeprom.c.

void eeprom_put_char ( unsigned int  addr,
unsigned char  new_value 
)

Write byte to EEPROM.

This function writes one byte to a given EEPROM address. The differences between the existing byte and the new value is used to select the most efficient EEPROM programming mode.

Note
The CPU is halted for 2 clock cycles during EEPROM programming.
When this function returns, the new EEPROM value is not available until the EEPROM programming time has passed. The EEPE bit in EECR should be polled to check whether the programming is finished.
The EEPROM_GetChar() function checks the EEPE bit automatically.
Parameters
addrEEPROM address to write to.
new_valueNew EEPROM value.

< Old EEPROM value.

< Difference mask, i.e. old value XOR new value.

< Ensure atomic operation for the write operation.

< Wait for completion of previous write.

< Set EEPROM address register.

< Start EEPROM read operation.

< Get old EEPROM value.

< Get bit differences.

< Set EEPROM data register.

< Set Master Write Enable bit...

< ...and Erase+Write mode.

< Start Erase+Write operation.

< Set Master Write Enable bit...

< ...and Erase-only mode.

< Start Erase-only operation.

< Set EEPROM data register.

< Set Master Write Enable bit...

< ...and Write-only mode.

< Start Write-only operation.

< Restore interrupt flag state.

Definition at line 74 of file eeprom.c.

int memcpy_from_eeprom_with_checksum ( char *  destination,
unsigned int  source,
unsigned int  size 
)

Definition at line 139 of file eeprom.c.

void memcpy_to_eeprom_with_checksum ( unsigned int  destination,
char *  source,
unsigned int  size 
)

Extensions added as part of Grbl.

Definition at line 129 of file eeprom.c.