a simple wrapper above I2C to provider EEPROM access API
Dependents: ou_mbed_oled ou_mbed_eeprom ou_mbed_tmp102
Revision 3:8ddab67b62c3, committed 2018-06-19
- Comitter:
- poushen
- Date:
- Tue Jun 19 01:26:31 2018 +0000
- Parent:
- 2:ce12a405cd3a
- Commit message:
- make sample more complete.
Changed in this revision
eeprom.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r ce12a405cd3a -r 8ddab67b62c3 eeprom.h --- a/eeprom.h Mon Jun 18 22:53:01 2018 +0000 +++ b/eeprom.h Tue Jun 19 01:26:31 2018 +0000 @@ -24,20 +24,64 @@ * #include "mbed.h" * #include "eeprom.h" * + * #define BUFFER_SIZE 64 + * * // make eeprom instance using I2C object. * // with default slave address 0xA0 (0x50 in 7bit format) * // test ok with 24FC256 EEPROM * I2C i2c(dp5,dp27); * eeprom epm(i2c); * + * // import!!! must prefix 3 bytes for memory address + * uint8_t buffer[BUFFER_SIZE + 3]; + * * int main() * { + * printf("LPC1114 demo.\n\r"); + * + * // -------- page write -------------------- + * for (int i=0; i<BUFFER_SIZE; i++) + * buffer[i+3] = i; // for prefix 3 memory address + * + * epm.page_write(12288, TWO_BYTES_ADDRESS, buffer, BUFFER_SIZE); + * //wait(0.008); + * epm.ack_polling(); + * + * // -------- current read ------------------ + * printf("below shold be 00 01 ... 3f\n\r"); * epm.write_address(12288, TWO_BYTES_ADDRESS); * - * for (int i=0; i< 64; i++) { + * for (int i=0; i<BUFFER_SIZE; i++) { * printf("%.2x ", epm.current_read()); * } * printf("\n\r"); + * + * // -------- byte write -------------------- + * epm.byte_write(12288, TWO_BYTES_ADDRESS, 0xAA); + * epm.ack_polling(); + * + * // -------- sequential read --------------- + * printf("below shold be aa 01 02 ... 3f\n\r"); + * epm.write_address(12288, TWO_BYTES_ADDRESS); + * + * uint8_t data[BUFFER_SIZE]; + * epm.sequential_read(data, BUFFER_SIZE); + * for (int i=0; i<BUFFER_SIZE; i++) { + * printf("%.2x ", data[i]); + * } + * printf("\n\r"); + * + * // -------- byte write -------------------- + * epm.byte_write(12289, TWO_BYTES_ADDRESS, 0xBB); + * epm.ack_polling(); + * + * // -------- random read ------------------- + * printf("below shold be aa bb 02 03 ... 3f\n\r"); + * epm.random_read(12288, TWO_BYTES_ADDRESS, buffer, 64); + * for (int i=0; i<64; i++) { + * printf("%.2x ", buffer[i]); + * } + * printf("\n\r"); * * while(1); * }