a simple test program against eeprom class

Dependencies:   eeprom mbed

Fork of ou_mbed_eeprom by Poushen Ou

Files at this revision

API Documentation at this revision

Comitter:
poushen
Date:
Tue Jun 19 05:41:52 2018 +0000
Parent:
1:2e18ad95d4ed
Commit message:
add code to demo eeprom access function

Changed in this revision

eeprom.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 2e18ad95d4ed -r 47ee605d0830 eeprom.lib
--- a/eeprom.lib	Sun Jun 17 06:52:12 2018 +0000
+++ b/eeprom.lib	Tue Jun 19 05:41:52 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/poushen/code/eeprom/#0c876c06b026
+https://os.mbed.com/users/poushen/code/eeprom/#8ddab67b62c3
diff -r 2e18ad95d4ed -r 47ee605d0830 main.cpp
--- a/main.cpp	Sun Jun 17 06:52:12 2018 +0000
+++ b/main.cpp	Tue Jun 19 05:41:52 2018 +0000
@@ -1,6 +1,8 @@
 #include "mbed.h"
 #include "eeprom.h"
 
+#define BUFFER_SIZE  64
+
 DigitalOut myled(LED2);
 
 // for LPCXpresso LPC1114 board
@@ -10,55 +12,61 @@
 // ** serial port: 9600, 8, N, 1, N
 // *************************************
 //Serial pc(xp9, xp10);
-I2C i2c(dp5, dp27);
+I2C i2c(dp5, dp27);     // for NXP LPC111x
 eeprom epm(i2c);
 
-int main() {
+// import!!! must prefix 3 bytes for memory address
+uint8_t buffer[BUFFER_SIZE + 3]; 
+
+int main()
+{
     myled = 1;
-    printf("LPC1114 demo \r\n");
-    i2c.frequency(1000 * 1000);
-    
-    uint8_t data[13] = { 0, 0, 0, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5};
-    
-    epm.page_write(12288, TWO_BYTES_ADDRESS, data, 10);
+    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++) {
-        printf("%.2x ", epm.current_read());
+
+    for (int i=0; i<BUFFER_SIZE; i++) {
+      printf("%.2x ", epm.current_read());
     }
     printf("\n\r");
     
-    epm.write_address(13312, TWO_BYTES_ADDRESS);
+    // -------- byte write --------------------
+    epm.byte_write(12288, TWO_BYTES_ADDRESS, 0xAA);
+    epm.ack_polling();
     
-    uint8_t buffer[64];
-    epm.sequential_read(buffer, 64);
-    for (int i=0; i<64; i++) {
-        printf("%.2x ", buffer[i]);
+    // -------- 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");
-    
+
     myled = 0;
-    
-    while (1);
-/*
-    while(1) {
-        myled = 1;
-        printf("led on\n");
-        for (int i=0; i<10000; i++);
-        //wait(1);
-        myled = 0;
-        printf("led off\n");
-        for (int i=0; i<10000; i++);
-        //wait(1);
-    }
-    */
+    while(1);
 }