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