Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# i2ceeprom.c

Go to the documentation of this file.

    00001 /*! \file i2ceeprom.c \brief Interface for standard I2C EEPROM memories. */
    00002 //*****************************************************************************
    00003 //
    00004 // File Name    : 'i2ceeprom.c'
    00005 // Title        : Interface for standard I2C EEPROM memories
    00006 // Author       : Pascal Stang - Copyright (C) 2003
    00007 // Created      : 2003.04.23
    00008 // Revised      : 2003.04.23
    00009 // Version      : 0.1
    00010 // Target MCU   : Atmel AVR series
    00011 // Editor Tabs  : 4
    00012 //
    00013 // This code is distributed under the GNU Public License
    00014 //      which can be found at http://www.gnu.org/licenses/gpl.txt
    00015 //
    00016 //*****************************************************************************
    00017
    00018 #include <avr/io.h>
    00019 #include <avr/interrupt.h>
    00020
    00021 #include "i2c.h"
    00022 #include "i2ceeprom.h"
    00023
    00024 // Standard I2C bit rates are:
    00025 // 100KHz for slow speed
    00026 // 400KHz for high speed
    00027
    00028 // functions
    00029 void i2ceepromInit(void)
    00030 {
    00031     // although there is no code here
    00032     // don't forget to initialize the I2C interface itself
    00033 }
    00034
    00035 u08 i2ceepromReadByte(u08 i2cAddr, u32 memAddr)
    00036 {
    00037     u08 packet[2];
    00038     // prepare address
    00039     packet[0] = (memAddr>>8);
    00040     packet[1] = (memAddr&0x00FF);
    00041     // send memory address we wish to access to the memory chip
    00042     i2cMasterSendNI(i2cAddr, 2, packet);
    00043     // retrieve the data at this memory address
    00044     i2cMasterReceiveNI(i2cAddr, 1, packet);
    00045     // return data
    00046     return packet[0];
    00047 }
    00048
    00049 void i2ceepromWriteByte(u08 i2cAddr, u32 memAddr, u08 data)
    00050 {
    00051     u08 packet[3];
    00052     // prepare address + data
    00053     packet[0] = (memAddr>>8);
    00054     packet[1] = (memAddr&0x00FF);
    00055     packet[2] = data;
    00056     // send memory address we wish to access to the memory chip
    00057     // along with the data we wish to write
    00058     i2cMasterSendNI(i2cAddr, 3, packet);
    00059 }