source: rtos_arduino/trunk/arduino_lib/libraries/Robot_Control/src/EEPROM_I2C.cpp@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 1.4 KB
Line 
1#include "EEPROM_I2C.h"
2#include <Wire.h>
3
4#if ARDUINO >= 100
5#include "Arduino.h"
6#else
7#include "WProgram.h"
8#endif
9
10void EEPROM_I2C::begin(){
11 Wire.begin();
12}
13
14void EEPROM_I2C::writeByte(unsigned int eeaddress, byte data){
15 int rdata = data;
16 this->_beginTransmission(eeaddress);
17 Wire.write(rdata);
18 this->_endTransmission();
19}
20
21byte EEPROM_I2C::readByte(unsigned int eeaddress){
22 int rdata;
23 this->_beginTransmission(eeaddress);
24 this->_endTransmission();
25
26 Wire.requestFrom(DEVICEADDRESS,1);
27 if (Wire.available()) rdata = Wire.read();
28 return rdata;
29}
30
31void EEPROM_I2C::writePage(unsigned int eeaddress, byte* data, byte length ){
32 this->_beginTransmission(eeaddress);
33
34 byte c;
35
36 for ( c = 0; c < length; c++)
37 Wire.write(data[c]);
38
39 this->_endTransmission();
40
41 delay(10); // need some delay
42}
43
44void EEPROM_I2C::readBuffer(unsigned int eeaddress, byte *buffer, int length ){
45 this->_beginTransmission(eeaddress);
46 this->_endTransmission();
47 Wire.requestFrom(DEVICEADDRESS,length);
48
49 for ( int c = 0; c < length; c++ )
50 if (Wire.available()) buffer[c] = Wire.read();
51}
52
53
54
55void EEPROM_I2C::_beginTransmission(unsigned int eeaddress){
56 Wire.beginTransmission(DEVICEADDRESS);
57 Wire.write((eeaddress >> 8)); // Address High Byte
58 Wire.write((eeaddress & 0xFF)); // Address Low Byte
59}
60void EEPROM_I2C::_endTransmission(){
61 Wire.endTransmission();
62}
Note: See TracBrowser for help on using the repository browser.