Fork of 24LCxx_I2C. Works for Renesas EEPROMs. Fixes problems with PageWrites over page boundaries.
Fork of 24LCxx_I2C by
C24LCXX_I2C Class Reference
This class provides simplified I2C access to a Microchip 24LCxx Serial EEPROM device. More...
#include <24LCxx_I2C.h>
Public Types | |
| enum | Mode |
Memory storage mode. More... | |
Public Member Functions | |
| C24LCXX_I2C (const PinName p_sda, const PinName p_scl, const unsigned char p_address, const PinName p_wp=NC, const unsigned int p_frequency=400000, const uint32_t deviceSize=256, const uint8_t pageSize=64) | |
| Constructor with Write Protect command pin wired. | |
| virtual | ~C24LCXX_I2C () |
| Destructor. | |
| const I2C * | operator* () |
| Used to return the unique instance of I2C instance. | |
| bool | EraseMemoryArea (const short p_startAddress, const int p_count, const unsigned char p_pattern=0x00) |
| Erase of memory area starting at the specified address, using the specified pattern to fill the memory area. | |
| bool | Write (const short p_address, const unsigned char p_byte) |
| Write a byte at the specified memory address. | |
| bool | Write (const short p_address, const short p_short, const C24LCXX_I2C::Mode p_mode=BigEndian) |
| Write a short at the specified memory address according to the specified mode. | |
| bool | Write (const short p_address, const int p_int, const C24LCXX_I2C::Mode p_mode=BigEndian) |
| Write an integer at the specified memory address according to the specified mode. | |
| bool | Write (const short p_address, const std::vector< unsigned char > &p_datas, bool p_storeLength=true, const int p_length2write=-1) |
| Write a buffer of bytes at the specified memory address. | |
| bool | Write (const short p_address, const unsigned char *p_datas, bool p_storeLength=true, const int p_length2write=-1) |
| Write a buffer of bytes at the specified memory address. | |
| bool | Write (const short p_address, const std::string &p_string, const bool p_storeLength=true, const int p_length2write=-1) |
| Write a string at the specified memory address. | |
| bool | Write (const short p_address, const char *p_datas, const bool p_storeLength=true, const int p_length2write=-1) |
| Write a buffer of characters at the specified memory address (from 0 to N - 1, N is the number of cells of the memory) | |
| bool | Read (const short p_address, unsigned char *p_value) |
| Read a byte from the specified memory address. | |
| bool | Read (const short p_address, short *p_short, C24LCXX_I2C::Mode p_mode=BigEndian) |
| Read a short from the specified memory address. | |
| bool | Read (const short p_address, int *p_int, C24LCXX_I2C::Mode p_mode=BigEndian) |
| Read an integer from the specified memory address. | |
| bool | Read (const short p_address, std::vector< unsigned char > &p_datas, bool p_readLengthFirst=true, int p_length2read=-1) |
| Read a buffer of bytes from the specified memory address and store it into a std::vector<unsigned char> object. | |
| bool | Read (const short p_address, std::string &p_string, bool p_readLengthFirst=true, int p_length2write=-1) |
| Read a buffer of characters from the specified memory address and store it into a string object. | |
| bool | Read (const short p_address, unsigned char *p_datas, bool p_readLengthFirst=true, int p_length2write=-1) |
| Read a buffer of characters from the specified memory address and store it into char array. | |
| bool | WriteProtect (const bool p_writeProtect) |
| Activate or deactivate write protect (pin 7) | |
| bool | IsWriteProtected () |
| Indicate the current WP state indicator (pin 7) | |
| void | DumpMemoryArea (const int p_address, const int p_count) |
| Dump a memory area. | |
| std::string & | ToString () |
| For debug purpose only. | |
Detailed Description
This class provides simplified I2C access to a Microchip 24LCxx Serial EEPROM device.
V0.0.0.3
Note that if the LPC1768 is powered in 3.3V and Microchip 24LCxx Serial EEPROM device could be powered at 3.3V or 5V. In this case, you shall use a bi-directional level shifter for I2C-bus. Please refer to AN97055 (http://ics.nxp.com/support/documents/interface/pdf/an97055.pdf) Microchip 24LCxx Serial EEPROM device reference:
- 24LC256: DS21203K
- 24LC64 : DS21189D
Note that for I2C details, please visit http://www.datelec.fr/fiches/I2C.htm
Note that this header file include following headers:
- <string>
- <vector>
- <mbed.h>
- Remarks:
- This class was validated with Tektronix TDS2014 oscilloscope in 3.3V and in mixte power mode 3.3V for mbed and 5V for the Microchip 24LCxx Serial EEPROM device
Definition at line 46 of file 24LCxx_I2C.h.
Member Enumeration Documentation
| enum Mode |
Memory storage mode.
Definition at line 63 of file 24LCxx_I2C.h.
Constructor & Destructor Documentation
| C24LCXX_I2C | ( | const PinName | p_sda, |
| const PinName | p_scl, | ||
| const unsigned char | p_address, | ||
| const PinName | p_wp = NC, |
||
| const unsigned int | p_frequency = 400000, |
||
| const uint32_t | deviceSize = 256, |
||
| const uint8_t | pageSize = 64 |
||
| ) |
Constructor with Write Protect command pin wired.
Use it to manage the first I2C module on 3.3V or 5V network
- Parameters:
-
p_sda,: MBed pin for SDA p_scl,: MBed pin for SCL p_address,: Device address input: A0, A1, A2 (Pins <1,3>) p_wp,: MBed pin to manage Write Protect input. If NC, WP is not managed, default value is NC, not connected p_frequency,: Frequency of the I2C interface (SCL), default value is 400KHz Example: - If A1 and A2 pins are tired to Vdd and A0 is tired to Vss, address shall '00000110'B
- If A0 and A1 pins are tired to Vss and A2 is tired to Vdd, address shall '00000100'B
Definition at line 29 of file 24LCxx_I2C.cpp.
| ~C24LCXX_I2C | ( | ) | [virtual] |
Destructor.
Definition at line 69 of file 24LCxx_I2C.cpp.
Member Function Documentation
| void DumpMemoryArea | ( | const int | p_address, |
| const int | p_count | ||
| ) |
Dump a memory area.
Note that this method is available only on debug mode
- Parameters:
-
p_address The memory address (from 0 to N - 1, N is the number of cells of the memory) p_count The number of bytes toi dump
- Returns:
- true on success, false otherwise
Definition at line 594 of file 24LCxx_I2C.cpp.
| bool EraseMemoryArea | ( | const short | p_startAddress, |
| const int | p_count, | ||
| const unsigned char | p_pattern = 0x00 |
||
| ) |
Erase of memory area starting at the specified address, using the specified pattern to fill the memory area.
- Parameters:
-
p_startAddress The address of the memory area (from 0 to N - 1, N is the number of cells of the memory) p_count The size of the memory area to erase p_pattern The pattern value to use to fill the memory area. Default vqlue: 0x00
- Returns:
- true on success, false otherwise Exemple:
... myEEPROM.EraseMemoryArea(0, 1024); // Set to 0x00 the first 1Kb memory ...
Definition at line 100 of file 24LCxx_I2C.cpp.
| bool IsWriteProtected | ( | ) |
Indicate the current WP state indicator (pin 7)
- Returns:
- true is write protected, false otherwise
Definition at line 311 of file 24LCxx_I2C.h.
| const I2C* operator* | ( | ) |
Used to return the unique instance of I2C instance.
Definition at line 91 of file 24LCxx_I2C.h.
| bool Read | ( | const short | p_address, |
| unsigned char * | p_value | ||
| ) |
Read a byte from the specified memory address.
- Parameters:
-
p_address The memory address (from 0 to N - 1, N is the number of cells of the memory) p_byte The byte value to read
- Returns:
- true on success, false otherwise Exemple:
unsigned char value; ... myEEPROM.Read(memoryAddress, (unsigned char *)&value); ...
Definition at line 315 of file 24LCxx_I2C.cpp.
| bool Read | ( | const short | p_address, |
| unsigned char * | p_datas, | ||
| bool | p_readLengthFirst = true, |
||
| int | p_length2write = -1 |
||
| ) |
Read a buffer of characters from the specified memory address and store it into char array.
- Parameters:
-
p_address The memory address (from 0 to N - 1, N is the number of cells of the memory) p_datas The string buffer to fill p_readLengthFirst If true, read the length first and p_length2write parameter is ignored, otherwise the length is provided by p_length2write parameter. Default value: true p_length2write The number of character to write, -1 to use the size of the string buffer
- Returns:
- true on success, false otherwise Exemple:
char[255] readtext; ... myEEPROM.Read(memoryAddress, readtext); ...
Definition at line 537 of file 24LCxx_I2C.cpp.
| bool Read | ( | const short | p_address, |
| short * | p_short, | ||
| C24LCXX_I2C::Mode | p_mode = BigEndian |
||
| ) |
Read a short from the specified memory address.
- Parameters:
-
p_address The memory address (from 0 to N - 1, N is the number of cells of the memory) p_short The short value to read
- Returns:
- true on success, false otherwise Exemple:
short value; ... myEEPROM.Read(memoryAddress, (short *)&value); ...
Definition at line 343 of file 24LCxx_I2C.cpp.
| bool Read | ( | const short | p_address, |
| int * | p_int, | ||
| C24LCXX_I2C::Mode | p_mode = BigEndian |
||
| ) |
Read an integer from the specified memory address.
- Parameters:
-
p_address The memory address (from 0 to N - 1, N is the number of cells of the memory) p_int The integer value to read
- Returns:
- true on success, false otherwise Exemple:
int value; ... myEEPROM.Read(memoryAddress, (int *)&value); ...
Definition at line 378 of file 24LCxx_I2C.cpp.
| bool Read | ( | const short | p_address, |
| std::vector< unsigned char > & | p_datas, | ||
| bool | p_readLengthFirst = true, |
||
| int | p_length2read = -1 |
||
| ) |
Read a buffer of bytes from the specified memory address and store it into a std::vector<unsigned char> object.
Note that the size of the buffer object is used for the number of bytes to read
- Parameters:
-
p_address The memory address (from 0 to N - 1, N is the number of cells of the memory) p_datas The buffer to fill p_readLengthFirst If true, read the length first and p_length2write parameter is ignored, otherwise the length is provided by p_length2write parameter. Default value: true p_length2read The number of character to write, -1 to use the size of the string buffer
- Returns:
- true on success, false otherwise Exemple:
std::vector<unsigned char> datas(bufferLength); ... myEEPROM.Read(memoryAddress, datas); ...
Definition at line 417 of file 24LCxx_I2C.cpp.
| bool Read | ( | const short | p_address, |
| std::string & | p_string, | ||
| bool | p_readLengthFirst = true, |
||
| int | p_length2write = -1 |
||
| ) |
Read a buffer of characters from the specified memory address and store it into a string object.
Note that the size of the string object is used for the number of characters to read
- Parameters:
-
p_address The memory address (from 0 to N - 1, N is the number of cells of the memory) p_string The string buffer to fill p_readLengthFirst If true, read the length first and p_length2write parameter is ignored, otherwise the length is provided by p_length2write parameter. Default value: true p_length2write The number of character to write, -1 to use the size of the string buffer
- Returns:
- true on success, false otherwise Exemple:
std::string readtext; ... myEEPROM.Read(memoryAddress, readtext); ...
Definition at line 471 of file 24LCxx_I2C.cpp.
| std::string& ToString | ( | ) |
For debug purpose only.
Definition at line 326 of file 24LCxx_I2C.h.
| bool Write | ( | const short | p_address, |
| const char * | p_datas, | ||
| const bool | p_storeLength = true, |
||
| const int | p_length2write = -1 |
||
| ) |
Write a buffer of characters at the specified memory address (from 0 to N - 1, N is the number of cells of the memory)
- Parameters:
-
p_address The memory address (from 0 to N - 1, N is the number of cells of the memory) p_datas The string to save p_storeLength If true, store also the length of the string in Big Endian mode, otherwise the length will be provided by p_length2write parameter. Default value: true. length2write The number of character to write, -1 for all characters
- Returns:
- true on success, false otherwise
Definition at line 219 of file 24LCxx_I2C.cpp.
| bool Write | ( | const short | p_address, |
| const unsigned char * | p_datas, | ||
| bool | p_storeLength = true, |
||
| const int | p_length2write = -1 |
||
| ) |
Write a buffer of bytes at the specified memory address.
- Parameters:
-
p_address The memory address (from 0 to N - 1, N is the number of cells of the memory) p_datas The buffer of bytes to save p_storeLength If true, store also the length of the buffer in Big Endian mode, otherwise the length will be provided by p_length2write parameter. Default value: true. p_length2write The number of bytes to write, -1 for all bytes. Default value: -1
- Returns:
- true on success, false otherwise
Definition at line 273 of file 24LCxx_I2C.cpp.
| bool Write | ( | const short | p_address, |
| const std::vector< unsigned char > & | p_datas, | ||
| bool | p_storeLength = true, |
||
| const int | p_length2write = -1 |
||
| ) |
Write a buffer of bytes at the specified memory address.
- Parameters:
-
p_address The memory address (from 0 to N - 1, N is the number of cells of the memory) p_datas The string to save p_storeLength If true, store also the length of the buffer in Big Endian mode, otherwise the length will be provided by p_length2write parameter. Default value: true. p_length2write The number of bytes to write, -1 for all characters. Default value: -1
- Returns:
- true on success, false otherwise
Definition at line 205 of file 24LCxx_I2C.cpp.
| bool Write | ( | const short | p_address, |
| const unsigned char | p_byte | ||
| ) |
Write a byte at the specified memory address.
- Parameters:
-
p_address The memory address (from 0 to N - 1, N is the number of cells of the memory) p_byte The byte value to save
- Returns:
- true on success, false otherwise Exemple:
unsigned char value = 0xaa; ... myEEPROM.Write(memoryAddress, value); ...
Definition at line 108 of file 24LCxx_I2C.cpp.
| bool Write | ( | const short | p_address, |
| const int | p_int, | ||
| const C24LCXX_I2C::Mode | p_mode = BigEndian |
||
| ) |
Write an integer at the specified memory address according to the specified mode.
- Parameters:
-
p_address The memory address (from 0 to N - 1, N is the number of cells of the memory) p_int The integer value to save p_mode The storage mode. Default value: BigEndian
- Returns:
- true on success, false otherwise Exemple:
int value = 0xcafedeca; ... myEEPROM.Write(memoryAddress, value, LittleEndian); ...
Definition at line 164 of file 24LCxx_I2C.cpp.
| bool Write | ( | const short | p_address, |
| const short | p_short, | ||
| const C24LCXX_I2C::Mode | p_mode = BigEndian |
||
| ) |
Write a short at the specified memory address according to the specified mode.
- Parameters:
-
p_address The memory address (from 0 to N - 1, N is the number of cells of the memory) p_short The short value to save p_mode The storage mode. Default value: BigEndian
- Returns:
- true on success, false otherwise Exemple:
short value = 0xcafe; ... myEEPROM.Write(memoryAddress, value, LittleEndian); ...
Definition at line 133 of file 24LCxx_I2C.cpp.
| bool Write | ( | const short | p_address, |
| const std::string & | p_string, | ||
| const bool | p_storeLength = true, |
||
| const int | p_length2write = -1 |
||
| ) |
Write a string at the specified memory address.
- Parameters:
-
p_address The memory address (from 0 to N - 1, N is the number of cells of the memory) p_string The string to save p_storeLength If true, store also the length of the string in Big Endian mode, otherwise the length will be provided by p_length2write parameter. Default value: true. p_length2write The number of character to write, -1 for all characters
- Returns:
- true on success, false otherwise Exemple:
std::string text2save("CafeDeca"); ... myEEPROM.Write(memoryAddress, text2save); ...
Definition at line 199 of file 24LCxx_I2C.cpp.
| bool WriteProtect | ( | const bool | p_writeProtect ) |
Activate or deactivate write protect (pin 7)
Note that a voltage of 3.3V apply to WP input of 24LCxx device is enough to enable write protect
- Parameters:
-
p_writeProtect,: Set to true to activate write protection, false otherwise
- Returns:
- true on success, false otherwise
Definition at line 89 of file 24LCxx_I2C.cpp.
Generated on Sat Jul 30 2022 16:18:10 by
1.7.2
