/trunk/libraries/Eeprom24C01_02/Eeprom24C01_02.cpp |
---|
0,0 → 1,326 |
/**************************************************************************//** |
* \brief EEPROM 24C01 / 24C02 library for Arduino |
* \author Copyright (C) 2012 Julien Le Sech - www.idreammicro.com |
* \version 1.0 |
* \date 20120217 |
* |
* This file is part of the EEPROM 24C01 / 24C02 library for Arduino. |
* |
* This library is free software: you can redistribute it and/or modify it under |
* the terms of the GNU Lesser General Public License as published by the Free |
* Software Foundation, either version 3 of the License, or (at your option) any |
* later version. |
* |
* This library is distributed in the hope that it will be useful, but WITHOUT |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
* details. |
* |
* You should have received a copy of the GNU Lesser General Public License |
* along with this program. If not, see http://www.gnu.org/licenses/ |
******************************************************************************/ |
/**************************************************************************//** |
* \file Eeprom24C01_02.cpp |
******************************************************************************/ |
/****************************************************************************** |
* Header file inclusions. |
******************************************************************************/ |
#include <Arduino.h> |
#include <Wire.h> |
#include <Eeprom24C01_02.h> |
/****************************************************************************** |
* Private macro definitions. |
******************************************************************************/ |
/**************************************************************************//** |
* \def EEPROM__PAGE_SIZE |
* \brief Size of a page in EEPROM memory. |
* This size is given by EEPROM memory datasheet. |
******************************************************************************/ |
#define EEPROM__PAGE_SIZE 8 |
/**************************************************************************//** |
* \def EEPROM__RD_BUFFER_SIZE |
* \brief Size of input TWI buffer. |
* This size is equal to BUFFER_LENGTH defined in Wire library (32 bytes). |
******************************************************************************/ |
#define EEPROM__RD_BUFFER_SIZE BUFFER_LENGTH |
/**************************************************************************//** |
* \def EEPROM__WR_BUFFER_SIZE |
* \brief Size of output TWI buffer. |
* This size is equal to BUFFER_LENGTH - 1 byte reserved for address. |
******************************************************************************/ |
#define EEPROM__WR_BUFFER_SIZE (BUFFER_LENGTH - 1) |
/****************************************************************************** |
* Public method definitions. |
******************************************************************************/ |
/**************************************************************************//** |
* \fn Eeprom24C01_02::Eeprom24C01_02(byte deviceAddress) |
* |
* \brief Constructor. |
* |
* \param deviceAddress EEPROM address on TWI bus. |
******************************************************************************/ |
Eeprom24C01_02::Eeprom24C01_02 |
( |
byte deviceAddress |
){ |
m_deviceAddress = deviceAddress; |
} |
/**************************************************************************//** |
* \fn void Eeprom24C01_02::initialize() |
* |
* \brief Initialize library and TWI bus. |
* |
* If several devices are connected to TWI bus, this method mustn't be |
* called. TWI bus must be initialized out of this library using |
* Wire.begin() method. |
******************************************************************************/ |
void |
Eeprom24C01_02::initialize() |
{ |
Wire.begin(); |
} |
/**************************************************************************//** |
* \fn void Eeprom24C01_02::writeByte( |
* byte address, |
* byte data) |
* |
* \brief Write a byte in EEPROM memory. |
* |
* \remarks A delay of 10 ms is required after write cycle. |
* |
* \param address Address. |
* \param data Byte to write. |
******************************************************************************/ |
void |
Eeprom24C01_02::writeByte |
( |
byte address, |
byte data |
){ |
Wire.beginTransmission(m_deviceAddress); |
Wire.write(address); |
Wire.write(data); |
Wire.endTransmission(); |
} |
/**************************************************************************//** |
* \fn void Eeprom24C01_02::writeBytes( |
* byte address, |
* byte length, |
* byte* p_data) |
* |
* \brief Write bytes in EEPROM memory. |
* |
* \param address Start address. |
* \param length Number of bytes to write. |
* \param[in] p_data Bytes to write. |
******************************************************************************/ |
void |
Eeprom24C01_02::writeBytes |
( |
byte address, |
byte length, |
byte* p_data |
){ |
// Write first page if not aligned. |
byte notAlignedLength = 0; |
byte pageOffset = address % EEPROM__PAGE_SIZE; |
if (pageOffset > 0) |
{ |
notAlignedLength = EEPROM__PAGE_SIZE - pageOffset; |
writePage(address, notAlignedLength, p_data); |
length -= notAlignedLength; |
} |
if (length > 0) |
{ |
address += notAlignedLength; |
p_data += notAlignedLength; |
// Write complete and aligned pages. |
byte pageCount = length / EEPROM__PAGE_SIZE; |
for (byte i = 0; i < pageCount; i++) |
{ |
writePage(address, EEPROM__PAGE_SIZE, p_data); |
address += EEPROM__PAGE_SIZE; |
p_data += EEPROM__PAGE_SIZE; |
length -= EEPROM__PAGE_SIZE; |
} |
if (length > 0) |
{ |
// Write remaining uncomplete page. |
writePage(address, EEPROM__PAGE_SIZE, p_data); |
} |
} |
} |
/**************************************************************************//** |
* \fn byte Eeprom24C01_02::readByte(byte address) |
* |
* \brief Read a byte in EEPROM memory. |
* |
* \param address Address. |
* |
* \return Read byte. |
******************************************************************************/ |
byte |
Eeprom24C01_02::readByte |
( |
byte address |
){ |
Wire.beginTransmission(m_deviceAddress); |
Wire.write(address); |
Wire.endTransmission(); |
Wire.requestFrom(m_deviceAddress, (byte)1); |
byte data = 0; |
if (Wire.available()) |
{ |
data = Wire.read(); |
} |
return data; |
} |
/**************************************************************************//** |
* \fn void Eeprom24C01_02::readBytes( |
* byte address, |
* byte length, |
* byte* p_data) |
* |
* \brief Read bytes in EEPROM memory. |
* |
* \param address Start address. |
* \param length Number of bytes to read. |
* \patam[in] p_data Byte array to fill with read bytes. |
******************************************************************************/ |
void |
Eeprom24C01_02::readBytes |
( |
byte address, |
byte length, |
byte* p_data |
){ |
byte bufferCount = length / EEPROM__RD_BUFFER_SIZE; |
for (byte i = 0; i < bufferCount; i++) |
{ |
byte offset = i * EEPROM__RD_BUFFER_SIZE; |
readBuffer(address + offset, EEPROM__RD_BUFFER_SIZE, p_data + offset); |
} |
byte remainingBytes = length % EEPROM__RD_BUFFER_SIZE; |
byte offset = length - remainingBytes; |
readBuffer(address + offset, remainingBytes, p_data + offset); |
} |
/****************************************************************************** |
* Private method definitions. |
******************************************************************************/ |
/**************************************************************************//** |
* \fn void Eeprom24C01_02::writePage( |
* byte address, |
* byte length, |
* byte* p_data) |
* |
* \brief Write page in EEPROM memory. |
* |
* \param address Start address. |
* \param length Number of bytes (EEPROM__PAGE_SIZE bytes max). |
* \param[in] p_data Data. |
******************************************************************************/ |
void |
Eeprom24C01_02::writePage |
( |
byte address, |
byte length, |
byte* p_data |
){ |
// Write complete buffers. |
byte bufferCount = length / EEPROM__WR_BUFFER_SIZE; |
for (byte i = 0; i < bufferCount; i++) |
{ |
byte offset = i * EEPROM__WR_BUFFER_SIZE; |
writeBuffer(address + offset, EEPROM__WR_BUFFER_SIZE, p_data + offset); |
} |
// Write remaining bytes. |
byte remainingBytes = length % EEPROM__WR_BUFFER_SIZE; |
byte offset = length - remainingBytes; |
writeBuffer(address + offset, remainingBytes, p_data + offset); |
} |
/**************************************************************************//** |
* \fn void Eeprom24C01_02::writeBuffer( |
* byte address, |
* byte length, |
* byte* p_data) |
* |
* \brief Write bytes into memory. |
* |
* \param address Start address. |
* \param length Number of bytes (EEPROM__WR_BUFFER_SIZE bytes max). |
* \param[in] p_data Data. |
******************************************************************************/ |
void |
Eeprom24C01_02::writeBuffer |
( |
byte address, |
byte length, |
byte* p_data |
){ |
Wire.beginTransmission(m_deviceAddress); |
Wire.write(address); |
for (byte i = 0; i < length; i++) |
{ |
Wire.write(p_data[i]); |
} |
Wire.endTransmission(); |
// Write cycle time (tWR). See EEPROM memory datasheet for more details. |
delay(10); |
} |
/**************************************************************************//** |
* \fn void Eeprom24C01_02::readBuffer( |
* byte address, |
* byte length, |
* byte* p_data) |
* |
* \brief Read bytes in memory. |
* |
* \param address Start address. |
* \param length Number of bytes (EEPROM__RD_BUFFER_SIZE bytes max). |
* \param[in] p_data Buffer to fill with read bytes. |
******************************************************************************/ |
void |
Eeprom24C01_02::readBuffer |
( |
byte address, |
byte length, |
byte* p_data |
){ |
Wire.beginTransmission(m_deviceAddress); |
Wire.write(address); |
Wire.endTransmission(); |
Wire.requestFrom(m_deviceAddress, length); |
for (byte i = 0; i < length; i++) |
{ |
if (Wire.available()) |
{ |
p_data[i] = Wire.read(); |
} |
} |
} |
/trunk/libraries/Eeprom24C01_02/keywords.txt |
---|
0,0 → 1,30 |
################################################################################ |
# Syntax Coloring Map For Eeprom24C01_02 |
################################################################################ |
################################################################################ |
# Datatypes (KEYWORD1) |
################################################################################ |
################################################################################ |
# Methods and Functions (KEYWORD2) |
################################################################################ |
initialize KEYWORD2 |
writeByte KEYWORD2 |
writeBytes KEYWORD2 |
readByte KEYWORD2 |
readBytes KEYWORD2 |
writePage KEYWORD2 |
writeBuffer KEYWORD2 |
readBuffer KEYWORD2 |
################################################################################ |
# Instances (KEYWORD2) |
################################################################################ |
Eeprom24C01_02 KEYWORD2 |
################################################################################ |
# Constants (LITERAL1) |
################################################################################ |
/trunk/libraries/Eeprom24C01_02/Eeprom24C01_02.h |
---|
0,0 → 1,211 |
/**************************************************************************//** |
* \brief EEPROM 24C01 / 24C02 library for Arduino |
* \author Copyright (C) 2012 Julien Le Sech - www.idreammicro.com |
* \version 1.0 |
* \date 20120217 |
* |
* This file is part of the EEPROM 24C01 / 24C02 library for Arduino. |
* |
* This library is free software: you can redistribute it and/or modify it under |
* the terms of the GNU Lesser General Public License as published by the Free |
* Software Foundation, either version 3 of the License, or (at your option) any |
* later version. |
* |
* This library is distributed in the hope that it will be useful, but WITHOUT |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
* details. |
* |
* You should have received a copy of the GNU Lesser General Public License |
* along with this program. If not, see http://www.gnu.org/licenses/ |
******************************************************************************/ |
/**************************************************************************//** |
* \headerfile Eeprom24C01_02.h |
******************************************************************************/ |
#ifndef Eeprom24C01_02_h |
#define Eeprom24C01_02_h |
/****************************************************************************** |
* Header file inclusion. |
******************************************************************************/ |
#include <Arduino.h> |
/**************************************************************************//** |
* \class Eeprom24C01_02 |
* |
* \brief EEPROM 24C01 / 24C02 memory driver. |
* |
* This driver is designed for 24C01 and 24C02 EEPROM memories. |
******************************************************************************/ |
class Eeprom24C01_02 |
{ |
public: |
/******************************************************************//** |
* \fn Eeprom24C01_02(byte deviceAddress) |
* |
* \brief Constructor. |
* |
* \param deviceAddress EEPROM address on TWI bus. |
**********************************************************************/ |
Eeprom24C01_02 |
( |
byte deviceAddress |
); |
/******************************************************************//** |
* \fn void initialize() |
* |
* \brief Initialize library abnd TWI bus. |
* |
* If several devices are connected to TWI bus, this method mustn't be |
* called. TWI bus must be initialized out of this library using |
* Wire.begin() method. |
**********************************************************************/ |
void |
initialize(); |
/******************************************************************//** |
* \fn void writeByte( |
* byte address, |
* byte data) |
* |
* \brief Write a byte in EEPROM memory. |
* |
* \remarks A delay of 10 ms is required after write cycle. |
* |
* \param address Address. |
* \param data Byte to write. |
**********************************************************************/ |
void |
writeByte |
( |
byte address, |
byte data |
); |
/******************************************************************//** |
* \fn void writeBytes( |
* byte address, |
* byte length, |
* byte* p_data) |
* |
* \brief Write bytes in EEPROM memory. |
* |
* \param address Start address. |
* \param length Number of bytes to write. |
* \param[in] p_data Bytes to write. |
**********************************************************************/ |
void |
writeBytes |
( |
byte address, |
byte length, |
byte* p_data |
); |
/******************************************************************//** |
* \fn byte readByte(byte address) |
* |
* \brief Read a byte in EEPROM memory. |
* |
* \param address Address. |
* |
* \return Read byte. |
**********************************************************************/ |
byte |
readByte |
( |
byte address |
); |
/******************************************************************//** |
* \fn void readBytes( |
* byte address, |
* byte length, |
* byte* p_data) |
* |
* \brief Read bytes in EEPROM memory. |
* |
* \param address Start address. |
* \param length Number of bytes to read. |
* \patam[in] p_data Byte array to fill with read bytes. |
**********************************************************************/ |
void |
readBytes |
( |
byte address, |
byte length, |
byte* p_buffer |
); |
private: |
byte m_deviceAddress; |
/******************************************************************//** |
* \fn void writePage( |
* byte address, |
* byte length, |
* byte* p_data) |
* |
* \brief Write page in EEPROM memory. |
* |
* \param address Start address. |
* \param length Number of bytes (64 bytes max). |
* \param[in] p_data Data. |
**********************************************************************/ |
void |
writePage |
( |
byte address, |
byte length, |
byte* p_data |
); |
/******************************************************************//** |
* \fn void writeBuffer( |
* byte address, |
* byte length, |
* byte* p_data) |
* |
* \brief Write bytes into memory. |
* |
* \param address Start address. |
* \param length Number of bytes (30 bytes max). |
* \param[in] p_date Data. |
**********************************************************************/ |
void |
writeBuffer |
( |
byte address, |
byte length, |
byte* p_data |
); |
/******************************************************************//** |
* \fn void readBuffer( |
* byte address, |
* byte length, |
* byte* p_data) |
* |
* \brief Read bytes in memory. |
* |
* \param address Start address. |
* \param length Number of bytes to read (32 bytes max). |
* \param[in] p_data Buffer to fill with read bytes. |
**********************************************************************/ |
void |
readBuffer |
( |
byte address, |
byte length, |
byte* p_data |
); |
}; |
#endif // Eeprom24C01_02_h |
/trunk/libraries/Eeprom24C01_02/lgpl-3.0.txt |
---|
0,0 → 1,165 |
GNU LESSER GENERAL PUBLIC LICENSE |
Version 3, 29 June 2007 |
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> |
Everyone is permitted to copy and distribute verbatim copies |
of this license document, but changing it is not allowed. |
This version of the GNU Lesser General Public License incorporates |
the terms and conditions of version 3 of the GNU General Public |
License, supplemented by the additional permissions listed below. |
0. Additional Definitions. |
As used herein, "this License" refers to version 3 of the GNU Lesser |
General Public License, and the "GNU GPL" refers to version 3 of the GNU |
General Public License. |
"The Library" refers to a covered work governed by this License, |
other than an Application or a Combined Work as defined below. |
An "Application" is any work that makes use of an interface provided |
by the Library, but which is not otherwise based on the Library. |
Defining a subclass of a class defined by the Library is deemed a mode |
of using an interface provided by the Library. |
A "Combined Work" is a work produced by combining or linking an |
Application with the Library. The particular version of the Library |
with which the Combined Work was made is also called the "Linked |
Version". |
The "Minimal Corresponding Source" for a Combined Work means the |
Corresponding Source for the Combined Work, excluding any source code |
for portions of the Combined Work that, considered in isolation, are |
based on the Application, and not on the Linked Version. |
The "Corresponding Application Code" for a Combined Work means the |
object code and/or source code for the Application, including any data |
and utility programs needed for reproducing the Combined Work from the |
Application, but excluding the System Libraries of the Combined Work. |
1. Exception to Section 3 of the GNU GPL. |
You may convey a covered work under sections 3 and 4 of this License |
without being bound by section 3 of the GNU GPL. |
2. Conveying Modified Versions. |
If you modify a copy of the Library, and, in your modifications, a |
facility refers to a function or data to be supplied by an Application |
that uses the facility (other than as an argument passed when the |
facility is invoked), then you may convey a copy of the modified |
version: |
a) under this License, provided that you make a good faith effort to |
ensure that, in the event an Application does not supply the |
function or data, the facility still operates, and performs |
whatever part of its purpose remains meaningful, or |
b) under the GNU GPL, with none of the additional permissions of |
this License applicable to that copy. |
3. Object Code Incorporating Material from Library Header Files. |
The object code form of an Application may incorporate material from |
a header file that is part of the Library. You may convey such object |
code under terms of your choice, provided that, if the incorporated |
material is not limited to numerical parameters, data structure |
layouts and accessors, or small macros, inline functions and templates |
(ten or fewer lines in length), you do both of the following: |
a) Give prominent notice with each copy of the object code that the |
Library is used in it and that the Library and its use are |
covered by this License. |
b) Accompany the object code with a copy of the GNU GPL and this license |
document. |
4. Combined Works. |
You may convey a Combined Work under terms of your choice that, |
taken together, effectively do not restrict modification of the |
portions of the Library contained in the Combined Work and reverse |
engineering for debugging such modifications, if you also do each of |
the following: |
a) Give prominent notice with each copy of the Combined Work that |
the Library is used in it and that the Library and its use are |
covered by this License. |
b) Accompany the Combined Work with a copy of the GNU GPL and this license |
document. |
c) For a Combined Work that displays copyright notices during |
execution, include the copyright notice for the Library among |
these notices, as well as a reference directing the user to the |
copies of the GNU GPL and this license document. |
d) Do one of the following: |
0) Convey the Minimal Corresponding Source under the terms of this |
License, and the Corresponding Application Code in a form |
suitable for, and under terms that permit, the user to |
recombine or relink the Application with a modified version of |
the Linked Version to produce a modified Combined Work, in the |
manner specified by section 6 of the GNU GPL for conveying |
Corresponding Source. |
1) Use a suitable shared library mechanism for linking with the |
Library. A suitable mechanism is one that (a) uses at run time |
a copy of the Library already present on the user's computer |
system, and (b) will operate properly with a modified version |
of the Library that is interface-compatible with the Linked |
Version. |
e) Provide Installation Information, but only if you would otherwise |
be required to provide such information under section 6 of the |
GNU GPL, and only to the extent that such information is |
necessary to install and execute a modified version of the |
Combined Work produced by recombining or relinking the |
Application with a modified version of the Linked Version. (If |
you use option 4d0, the Installation Information must accompany |
the Minimal Corresponding Source and Corresponding Application |
Code. If you use option 4d1, you must provide the Installation |
Information in the manner specified by section 6 of the GNU GPL |
for conveying Corresponding Source.) |
5. Combined Libraries. |
You may place library facilities that are a work based on the |
Library side by side in a single library together with other library |
facilities that are not Applications and are not covered by this |
License, and convey such a combined library under terms of your |
choice, if you do both of the following: |
a) Accompany the combined library with a copy of the same work based |
on the Library, uncombined with any other library facilities, |
conveyed under the terms of this License. |
b) Give prominent notice with the combined library that part of it |
is a work based on the Library, and explaining where to find the |
accompanying uncombined form of the same work. |
6. Revised Versions of the GNU Lesser General Public License. |
The Free Software Foundation may publish revised and/or new versions |
of the GNU Lesser General Public License from time to time. Such new |
versions will be similar in spirit to the present version, but may |
differ in detail to address new problems or concerns. |
Each version is given a distinguishing version number. If the |
Library as you received it specifies that a certain numbered version |
of the GNU Lesser General Public License "or any later version" |
applies to it, you have the option of following the terms and |
conditions either of that published version or of any later version |
published by the Free Software Foundation. If the Library as you |
received it does not specify a version number of the GNU Lesser |
General Public License, you may choose any version of the GNU Lesser |
General Public License ever published by the Free Software Foundation. |
If the Library as you received it specifies that a proxy can decide |
whether future versions of the GNU Lesser General Public License shall |
apply, that proxy's public statement of acceptance of any version is |
permanent authorization for you to choose that version for the |
Library. |
/trunk/libraries/Eeprom24C01_02/examples/WriteReadByte/WriteReadByte.ino |
---|
0,0 → 1,93 |
/**************************************************************************//** |
* \brief EEPROM 24C01 / 24C02 library for Arduino - Demonstration program |
* \author Copyright (C) 2012 Julien Le Sech - www.idreammicro.com |
* \version 1.0 |
* \date 20120217 |
* |
* This file is part of the EEPROM 24C01 / 24C02 library for Arduino. |
* |
* This library is free software: you can redistribute it and/or modify it under |
* the terms of the GNU Lesser General Public License as published by the Free |
* Software Foundation, either version 3 of the License, or (at your option) any |
* later version. |
* |
* This library is distributed in the hope that it will be useful, but WITHOUT |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
* details. |
* |
* You should have received a copy of the GNU Lesser General Public License |
* along with this program. If not, see http://www.gnu.org/licenses/ |
******************************************************************************/ |
/**************************************************************************//** |
* \file WriteReadByte.ino |
******************************************************************************/ |
/****************************************************************************** |
* Header file inclusions. |
******************************************************************************/ |
#include <Wire.h> |
#include <Eeprom24C01_02.h> |
/****************************************************************************** |
* Private macro definitions. |
******************************************************************************/ |
/**************************************************************************//** |
* \def EEPROM_ADDRESS |
* \brief Address of EEPROM memory on TWI bus. |
******************************************************************************/ |
#define EEPROM_ADDRESS 0x50 |
/****************************************************************************** |
* Private variable definitions. |
******************************************************************************/ |
static Eeprom24C01_02 eeprom(EEPROM_ADDRESS); |
/****************************************************************************** |
* Public function definitions. |
******************************************************************************/ |
/**************************************************************************//** |
* \fn void setup() |
* |
* \brief |
******************************************************************************/ |
void setup() |
{ |
// Initialize serial communication. |
Serial.begin(9600); |
// Initialize EEPROM library. |
eeprom.initialize(); |
// Write a byte at address 0 in EEPROM memory. |
Serial.println("Write byte to EEPROM memory..."); |
eeprom.writeByte(0, 0xAA); |
// Write cycle time (tWR). See EEPROM memory datasheet for more details. |
delay(10); |
// Read a byte at address 0 in EEPROM memory. |
Serial.println("Read byte from EEPROM memory..."); |
byte data = eeprom.readByte(0); |
// Print read byte. |
Serial.print("Read byte = 0x"); |
Serial.print(data, HEX); |
Serial.println(""); |
} |
/**************************************************************************//** |
* \fn void loop() |
* |
* \brief |
******************************************************************************/ |
void loop() |
{ |
} |
/trunk/libraries/Eeprom24C01_02/examples/WriteReadBytes/WriteReadBytes.ino |
---|
0,0 → 1,105 |
/**************************************************************************//** |
* \brief EEPROM 24C01 / 24C02 library for Arduino - Demonstration program |
* \author Copyright (C) 2012 Julien Le Sech - www.idreammicro.com |
* \version 1.0 |
* \date 20120217 |
* |
* This file is part of the EEPROM 24C01 / 24C02 library for Arduino. |
* |
* This library is free software: you can redistribute it and/or modify it under |
* the terms of the GNU Lesser General Public License as published by the Free |
* Software Foundation, either version 3 of the License, or (at your option) any |
* later version. |
* |
* This library is distributed in the hope that it will be useful, but WITHOUT |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
* details. |
* |
* You should have received a copy of the GNU Lesser General Public License |
* along with this program. If not, see http://www.gnu.org/licenses/ |
******************************************************************************/ |
/**************************************************************************//** |
* \file WriteReadBytes.ino |
******************************************************************************/ |
/****************************************************************************** |
* Header file inclusions. |
******************************************************************************/ |
#include <Wire.h> |
#include <Eeprom24C01_02.h> |
/****************************************************************************** |
* Private macro definitions. |
******************************************************************************/ |
/**************************************************************************//** |
* \def EEPROM_ADDRESS |
* \brief Address of EEPROM memory on TWI bus. |
******************************************************************************/ |
#define EEPROM_ADDRESS 0x50 |
/****************************************************************************** |
* Private variable definitions. |
******************************************************************************/ |
static Eeprom24C01_02 eeprom(EEPROM_ADDRESS); |
/****************************************************************************** |
* Public function definitions. |
******************************************************************************/ |
/**************************************************************************//** |
* \fn void setup() |
* |
* \brief |
******************************************************************************/ |
void setup() |
{ |
// Initialize serial communication. |
Serial.begin(9600); |
// Initiliaze EEPROM library. |
eeprom.initialize(); |
// Declare byte arrays. |
byte inputBytes[94] = { 0 }; |
byte outputBytes[94] = { 0 }; |
// Fill input array with printable characters. See ASCII table for more |
// details. |
for (byte i = 0; i < 94; i++) |
{ |
inputBytes[i] = i + 33; |
} |
// Write input array to EEPROM memory. |
Serial.println("Write bytes to EEPROM memory..."); |
eeprom.writeBytes(0, 94, inputBytes); |
// Read array with bytes read from EEPROM memory. |
Serial.println("Read bytes from EEPROM memory..."); |
eeprom.readBytes(0, 94, outputBytes); |
// Print read bytes. |
Serial.println("Read bytes:"); |
for (byte i = 0; i < 94; i++) |
{ |
Serial.write(outputBytes[i]); |
Serial.print(" "); |
} |
Serial.println(""); |
} |
/**************************************************************************//** |
* \fn void loop() |
* |
* \brief |
******************************************************************************/ |
void loop() |
{ |
} |