![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
EEPROM test
Dependencies: mbed EEPROM_lib
main.cpp
- Committer:
- Sigma884
- Date:
- 2021-05-22
- Revision:
- 5:8b4c33da0c71
- Parent:
- 4:b886fe26f396
- Child:
- 6:13bebe6d434a
- Child:
- 7:f89925dac6ca
File content as of revision 5:8b4c33da0c71:
#include "mbed.h" #include "EEPROM_lib.h" Serial pc(USBTX, USBRX, 115200); I2C i2c_bus(p28, p27); EEPROM_lib EEPROM(i2c_bus, 1); // hoge test // ビッグエンディアン/リトルエンディアンに注意! int main(){ //////////////////////////////////////////write /* EEPROM.setWriteAddr(1, 0, 0x00, 0x00); int ptr, n = 0; while(1){ while(1){ ptr = EEPROM.chargeBuff((int)n++); if(ptr == 128){ EEPROM.writeBuff(); ptr = EEPROM.setNextPage(); break; } } if(ptr == 0x01000000){ break; } } //////////////////////////////////////////read char data[128]; int num, block; char ADDR_H, ADDR_L; num = 1; block = 0; ADDR_H = ADDR_L = 0x00; for(int i = 0; i < 1024; i ++){ switch(i){ case 512: num = 1; block = 1; break; case 1024: num = 2; block = 0; break; case 1536: num = 2; block = 1; break; case 2048: num = 3; block = 0; break; case 2560: num = 3; block = 1; break; case 3072: num = 4; block = 0; break; case 3584: num = 4; block = 1; break; } EEPROM.readMultiByte(num, block, ADDR_H, ADDR_L, data, 128); for(int x = 0; x < 128; x ++){ pc.printf("%02x ", data[x]); } pc.printf("\r\n"); if(ADDR_L == 0x00){ ADDR_L = 0x80; } else{ ADDR_L = 0x00; ADDR_H ++; } } */ /* char data[128]; int num, block; char ADDR_H, ADDR_L; num = 1; block = 0; ADDR_H = ADDR_L = 0x00; char a; for(int i = 0; i < 9; i ++){ a = EEPROM.readByte(num, block, ADDR_H, ADDR_L); pc.printf("%02x ", a); ADDR_L ++; } */ EEPROM.setWriteAddr(1, 0, 0x00, 0x00); int ptr, n = 0; for(int j = 0; j < 2; j ++){ for(int k = 0; k < 128; k ++){ ptr = EEPROM.chargeBuff((int)k); if(ptr == 128){ EEPROM.writeBuff(); ptr = EEPROM.setNextPage(); } } } char data[128]; int num, block; char ADDR_H, ADDR_L; num = 1; block = 0; ADDR_H = ADDR_L = 0x00; for(int l = 0; l < 2; l ++){ EEPROM.readMultiByte(num, block, ADDR_H, ADDR_L, data, 128); for(int x = 0; x < 128; x ++){ pc.printf("%02x ", data[x]); } pc.printf("\r\n"); if(ADDR_L == 0x00){ ADDR_L = 0x80; } else{ ADDR_L = 0x00; ADDR_H ++; } } }