Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1253 | linlun | 1 | /*! \file i2ceeprom.c \brief Interface for standard I2C EEPROM memories. */ |
| 2 | //***************************************************************************** |
||
| 3 | // |
||
| 4 | // File Name : 'i2ceeprom.c' |
||
| 5 | // Title : Interface for standard I2C EEPROM memories |
||
| 6 | // Author : Pascal Stang - Copyright (C) 2003 |
||
| 7 | // Created : 2003.04.23 |
||
| 8 | // Revised : 2003.04.23 |
||
| 9 | // Version : 0.1 |
||
| 10 | // Target MCU : Atmel AVR series |
||
| 11 | // Editor Tabs : 4 |
||
| 12 | // |
||
| 13 | // This code is distributed under the GNU Public License |
||
| 14 | // which can be found at http://www.gnu.org/licenses/gpl.txt |
||
| 15 | // |
||
| 16 | //***************************************************************************** |
||
| 17 | |||
| 18 | #include <avr/io.h> |
||
| 19 | #include <avr/interrupt.h> |
||
| 20 | |||
| 21 | #include <drivers/mcu/i2c.h> |
||
| 22 | #include <drivers/misc/i2ceeprom.h> |
||
| 23 | |||
| 24 | // Standard I2C bit rates are: |
||
| 25 | // 100KHz for slow speed |
||
| 26 | // 400KHz for high speed |
||
| 27 | |||
| 28 | // functions |
||
| 29 | void i2ceepromInit(void) |
||
| 30 | { |
||
| 31 | i2cInit(); |
||
| 32 | // although there is no code here |
||
| 33 | // don't forget to initialize the I2C interface itself |
||
| 34 | } |
||
| 35 | |||
| 36 | uint8_t i2ceepromReadByte(uint8_t i2cAddr, uint16_t memAddr) |
||
| 37 | { |
||
| 38 | uint8_t packet[2]; |
||
| 39 | // prepare address |
||
| 40 | packet[0] = (memAddr>>8); |
||
| 41 | packet[1] = (memAddr&0x00FF); |
||
| 42 | // send memory address we wish to access to the memory chip |
||
| 43 | i2cMasterSend(i2cAddr, 2, packet); |
||
| 44 | // retrieve the data at this memory address |
||
| 45 | i2cMasterReceive(i2cAddr, 1, packet); |
||
| 46 | // return data |
||
| 47 | return packet[0]; |
||
| 48 | } |
||
| 49 | |||
| 50 | void i2ceepromWriteByte(uint8_t i2cAddr, uint16_t memAddr, uint8_t data) |
||
| 51 | { |
||
| 52 | uint8_t packet[3]; |
||
| 53 | // prepare address + data |
||
| 54 | packet[0] = (memAddr>>8); |
||
| 55 | packet[1] = (memAddr&0x00FF); |
||
| 56 | packet[2] = data; |
||
| 57 | // send memory address we wish to access to the memory chip |
||
| 58 | // along with the data we wish to write |
||
| 59 | i2cMasterSend(i2cAddr, 3, packet); |
||
| 60 | } |