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/signal.h> 00020 #include <avr/interrupt.h> 00021 00022 #include "i2c.h" 00023 #include "i2ceeprom.h" 00024 00025 // Standard I2C bit rates are: 00026 // 100KHz for slow speed 00027 // 400KHz for high speed 00028 00029 // functions 00030 void i2ceepromInit(void) 00031 { 00032 // although there is no code here 00033 // don't forget to initialize the I2C interface itself 00034 } 00035 00036 u08 i2ceepromReadByte(u08 i2cAddr, u32 memAddr) 00037 { 00038 u08 packet[2]; 00039 // prepare address 00040 packet[0] = (memAddr>>8); 00041 packet[1] = (memAddr&0x00FF); 00042 // send memory address we wish to access to the memory chip 00043 i2cMasterSendNI(i2cAddr, 2, packet); 00044 // retrieve the data at this memory address 00045 i2cMasterReceiveNI(i2cAddr, 1, packet); 00046 // return data 00047 return packet[0]; 00048 } 00049 00050 void i2ceepromWriteByte(u08 i2cAddr, u32 memAddr, u08 data) 00051 { 00052 u08 packet[3]; 00053 // prepare address + data 00054 packet[0] = (memAddr>>8); 00055 packet[1] = (memAddr&0x00FF); 00056 packet[2] = data; 00057 // send memory address we wish to access to the memory chip 00058 // along with the data we wish to write 00059 i2cMasterSendNI(i2cAddr, 3, packet); 00060 }