![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
EEPROM test
Dependencies: mbed EEPROM_lib
main.cpp@7:f89925dac6ca, 2021-05-22 (annotated)
- Committer:
- Sigma884
- Date:
- Sat May 22 16:11:31 2021 +0000
- Revision:
- 7:f89925dac6ca
- Parent:
- 5:8b4c33da0c71
- Child:
- 8:f024aab29f82
add comment (Hayashi)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
imadaemi | 0:7b9806067298 | 1 | #include "mbed.h" |
imadaemi | 0:7b9806067298 | 2 | #include "EEPROM_lib.h" |
imadaemi | 0:7b9806067298 | 3 | |
imadaemi | 0:7b9806067298 | 4 | Serial pc(USBTX, USBRX, 115200); |
imadaemi | 0:7b9806067298 | 5 | I2C i2c_bus(p28, p27); |
imadaemi | 0:7b9806067298 | 6 | |
imadaemi | 0:7b9806067298 | 7 | EEPROM_lib EEPROM(i2c_bus, 1); |
imadaemi | 0:7b9806067298 | 8 | |
imadaemi | 3:ce61a30944b3 | 9 | // hoge test |
Sigma884 | 1:dddddafe7cde | 10 | // ビッグエンディアン/リトルエンディアンに注意! |
Sigma884 | 7:f89925dac6ca | 11 | // OB ROCKET 2021 |
Sigma884 | 1:dddddafe7cde | 12 | |
imadaemi | 0:7b9806067298 | 13 | int main(){ |
imadaemi | 0:7b9806067298 | 14 | //////////////////////////////////////////write |
imadaemi | 0:7b9806067298 | 15 | /* |
imadaemi | 0:7b9806067298 | 16 | EEPROM.setWriteAddr(1, 0, 0x00, 0x00); |
imadaemi | 0:7b9806067298 | 17 | int ptr, n = 0; |
imadaemi | 0:7b9806067298 | 18 | while(1){ |
imadaemi | 0:7b9806067298 | 19 | while(1){ |
imadaemi | 0:7b9806067298 | 20 | ptr = EEPROM.chargeBuff((int)n++); |
imadaemi | 0:7b9806067298 | 21 | if(ptr == 128){ |
imadaemi | 0:7b9806067298 | 22 | EEPROM.writeBuff(); |
imadaemi | 0:7b9806067298 | 23 | ptr = EEPROM.setNextPage(); |
imadaemi | 0:7b9806067298 | 24 | break; |
imadaemi | 0:7b9806067298 | 25 | } |
imadaemi | 0:7b9806067298 | 26 | } |
imadaemi | 0:7b9806067298 | 27 | if(ptr == 0x01000000){ |
imadaemi | 0:7b9806067298 | 28 | break; |
imadaemi | 0:7b9806067298 | 29 | } |
imadaemi | 0:7b9806067298 | 30 | } |
imadaemi | 0:7b9806067298 | 31 | |
imadaemi | 0:7b9806067298 | 32 | //////////////////////////////////////////read |
imadaemi | 0:7b9806067298 | 33 | |
imadaemi | 0:7b9806067298 | 34 | char data[128]; |
imadaemi | 0:7b9806067298 | 35 | int num, block; |
imadaemi | 0:7b9806067298 | 36 | char ADDR_H, ADDR_L; |
imadaemi | 0:7b9806067298 | 37 | |
imadaemi | 0:7b9806067298 | 38 | num = 1; |
imadaemi | 0:7b9806067298 | 39 | block = 0; |
imadaemi | 0:7b9806067298 | 40 | ADDR_H = ADDR_L = 0x00; |
imadaemi | 0:7b9806067298 | 41 | |
imadaemi | 0:7b9806067298 | 42 | for(int i = 0; i < 1024; i ++){ |
imadaemi | 0:7b9806067298 | 43 | switch(i){ |
imadaemi | 0:7b9806067298 | 44 | case 512: |
imadaemi | 0:7b9806067298 | 45 | num = 1; |
imadaemi | 0:7b9806067298 | 46 | block = 1; |
imadaemi | 0:7b9806067298 | 47 | break; |
imadaemi | 0:7b9806067298 | 48 | |
imadaemi | 0:7b9806067298 | 49 | case 1024: |
imadaemi | 0:7b9806067298 | 50 | num = 2; |
imadaemi | 0:7b9806067298 | 51 | block = 0; |
imadaemi | 0:7b9806067298 | 52 | break; |
imadaemi | 0:7b9806067298 | 53 | |
imadaemi | 0:7b9806067298 | 54 | case 1536: |
imadaemi | 0:7b9806067298 | 55 | num = 2; |
imadaemi | 0:7b9806067298 | 56 | block = 1; |
imadaemi | 0:7b9806067298 | 57 | break; |
imadaemi | 0:7b9806067298 | 58 | |
imadaemi | 0:7b9806067298 | 59 | case 2048: |
imadaemi | 0:7b9806067298 | 60 | num = 3; |
imadaemi | 0:7b9806067298 | 61 | block = 0; |
imadaemi | 0:7b9806067298 | 62 | break; |
imadaemi | 0:7b9806067298 | 63 | |
imadaemi | 0:7b9806067298 | 64 | case 2560: |
imadaemi | 0:7b9806067298 | 65 | num = 3; |
imadaemi | 0:7b9806067298 | 66 | block = 1; |
imadaemi | 0:7b9806067298 | 67 | break; |
imadaemi | 0:7b9806067298 | 68 | |
imadaemi | 0:7b9806067298 | 69 | case 3072: |
imadaemi | 0:7b9806067298 | 70 | num = 4; |
imadaemi | 0:7b9806067298 | 71 | block = 0; |
imadaemi | 0:7b9806067298 | 72 | break; |
imadaemi | 0:7b9806067298 | 73 | |
imadaemi | 0:7b9806067298 | 74 | case 3584: |
imadaemi | 0:7b9806067298 | 75 | num = 4; |
imadaemi | 0:7b9806067298 | 76 | block = 1; |
imadaemi | 0:7b9806067298 | 77 | break; |
imadaemi | 0:7b9806067298 | 78 | } |
imadaemi | 0:7b9806067298 | 79 | |
imadaemi | 0:7b9806067298 | 80 | EEPROM.readMultiByte(num, block, ADDR_H, ADDR_L, data, 128); |
imadaemi | 0:7b9806067298 | 81 | for(int x = 0; x < 128; x ++){ |
imadaemi | 0:7b9806067298 | 82 | pc.printf("%02x ", data[x]); |
imadaemi | 0:7b9806067298 | 83 | } |
imadaemi | 0:7b9806067298 | 84 | pc.printf("\r\n"); |
imadaemi | 0:7b9806067298 | 85 | |
imadaemi | 0:7b9806067298 | 86 | if(ADDR_L == 0x00){ |
imadaemi | 0:7b9806067298 | 87 | ADDR_L = 0x80; |
imadaemi | 0:7b9806067298 | 88 | } |
imadaemi | 0:7b9806067298 | 89 | else{ |
imadaemi | 0:7b9806067298 | 90 | ADDR_L = 0x00; |
imadaemi | 0:7b9806067298 | 91 | ADDR_H ++; |
imadaemi | 0:7b9806067298 | 92 | } |
imadaemi | 0:7b9806067298 | 93 | } |
imadaemi | 0:7b9806067298 | 94 | */ |
imadaemi | 0:7b9806067298 | 95 | /* |
imadaemi | 0:7b9806067298 | 96 | char data[128]; |
imadaemi | 0:7b9806067298 | 97 | int num, block; |
imadaemi | 0:7b9806067298 | 98 | char ADDR_H, ADDR_L; |
imadaemi | 0:7b9806067298 | 99 | |
imadaemi | 0:7b9806067298 | 100 | num = 1; |
imadaemi | 0:7b9806067298 | 101 | block = 0; |
imadaemi | 0:7b9806067298 | 102 | ADDR_H = ADDR_L = 0x00; |
imadaemi | 0:7b9806067298 | 103 | |
imadaemi | 0:7b9806067298 | 104 | char a; |
imadaemi | 0:7b9806067298 | 105 | |
imadaemi | 0:7b9806067298 | 106 | for(int i = 0; i < 9; i ++){ |
imadaemi | 0:7b9806067298 | 107 | a = EEPROM.readByte(num, block, ADDR_H, ADDR_L); |
imadaemi | 0:7b9806067298 | 108 | pc.printf("%02x ", a); |
imadaemi | 0:7b9806067298 | 109 | ADDR_L ++; |
imadaemi | 0:7b9806067298 | 110 | } |
imadaemi | 0:7b9806067298 | 111 | */ |
imadaemi | 0:7b9806067298 | 112 | |
imadaemi | 0:7b9806067298 | 113 | EEPROM.setWriteAddr(1, 0, 0x00, 0x00); |
imadaemi | 0:7b9806067298 | 114 | int ptr, n = 0; |
imadaemi | 0:7b9806067298 | 115 | |
imadaemi | 0:7b9806067298 | 116 | for(int j = 0; j < 2; j ++){ |
imadaemi | 0:7b9806067298 | 117 | for(int k = 0; k < 128; k ++){ |
imadaemi | 0:7b9806067298 | 118 | ptr = EEPROM.chargeBuff((int)k); |
imadaemi | 0:7b9806067298 | 119 | if(ptr == 128){ |
imadaemi | 0:7b9806067298 | 120 | EEPROM.writeBuff(); |
imadaemi | 0:7b9806067298 | 121 | ptr = EEPROM.setNextPage(); |
imadaemi | 0:7b9806067298 | 122 | } |
imadaemi | 0:7b9806067298 | 123 | } |
imadaemi | 0:7b9806067298 | 124 | } |
imadaemi | 0:7b9806067298 | 125 | |
imadaemi | 0:7b9806067298 | 126 | char data[128]; |
imadaemi | 0:7b9806067298 | 127 | int num, block; |
imadaemi | 0:7b9806067298 | 128 | char ADDR_H, ADDR_L; |
imadaemi | 0:7b9806067298 | 129 | |
imadaemi | 0:7b9806067298 | 130 | num = 1; |
imadaemi | 0:7b9806067298 | 131 | block = 0; |
imadaemi | 0:7b9806067298 | 132 | ADDR_H = ADDR_L = 0x00; |
imadaemi | 0:7b9806067298 | 133 | |
imadaemi | 0:7b9806067298 | 134 | for(int l = 0; l < 2; l ++){ |
imadaemi | 0:7b9806067298 | 135 | EEPROM.readMultiByte(num, block, ADDR_H, ADDR_L, data, 128); |
imadaemi | 0:7b9806067298 | 136 | for(int x = 0; x < 128; x ++){ |
imadaemi | 0:7b9806067298 | 137 | pc.printf("%02x ", data[x]); |
imadaemi | 0:7b9806067298 | 138 | } |
imadaemi | 0:7b9806067298 | 139 | pc.printf("\r\n"); |
imadaemi | 0:7b9806067298 | 140 | |
imadaemi | 0:7b9806067298 | 141 | if(ADDR_L == 0x00){ |
imadaemi | 0:7b9806067298 | 142 | ADDR_L = 0x80; |
imadaemi | 0:7b9806067298 | 143 | } |
imadaemi | 0:7b9806067298 | 144 | else{ |
imadaemi | 0:7b9806067298 | 145 | ADDR_L = 0x00; |
imadaemi | 0:7b9806067298 | 146 | ADDR_H ++; |
imadaemi | 0:7b9806067298 | 147 | } |
imadaemi | 0:7b9806067298 | 148 | } |
imadaemi | 0:7b9806067298 | 149 | } |