PLANET-Q EEPROM Library
Dependents: IZU2020_AVIONICS IZU2020_POST_PROCESS IZU2020_AVIONICS
PQEEPROM.h@1:fccbd0a70492, 2019-12-17 (annotated)
- Committer:
- tanahashi
- Date:
- Tue Dec 17 13:39:59 2019 +0000
- Revision:
- 1:fccbd0a70492
- Parent:
- 0:559c23c5884c
- Child:
- 2:bb2a2a6b2702
added comment
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tanahashi | 0:559c23c5884c | 1 | #ifndef PQEEPROM_H_ |
tanahashi | 0:559c23c5884c | 2 | #define PQEEPROM_H_ |
tanahashi | 0:559c23c5884c | 3 | |
tanahashi | 1:fccbd0a70492 | 4 | /** |
tanahashi | 1:fccbd0a70492 | 5 | * EEPROM 24LC1025のライブラリ |
tanahashi | 1:fccbd0a70492 | 6 | * @note 1つにつき0x000000~0x01FFFFまでのアドレスが指定できます |
tanahashi | 1:fccbd0a70492 | 7 | * @note 2つ使用する場合は0x000000~0x03FFFFまでのアドレスが指定でき、最大4つ同時に使用できます |
tanahashi | 1:fccbd0a70492 | 8 | * @note 1ページは128バイトです |
tanahashi | 1:fccbd0a70492 | 9 | * @note ページをまたぐような書き込みは危険なのでしないこと |
tanahashi | 1:fccbd0a70492 | 10 | * @note 受信バッファは128バイトです |
tanahashi | 1:fccbd0a70492 | 11 | * @code |
tanahashi | 1:fccbd0a70492 | 12 | #include "mbed.h" |
tanahashi | 1:fccbd0a70492 | 13 | #include "PQEEPROM.h" |
tanahashi | 1:fccbd0a70492 | 14 | |
tanahashi | 1:fccbd0a70492 | 15 | Serial pc(USBTX, USBRX, 115200); |
tanahashi | 1:fccbd0a70492 | 16 | |
tanahashi | 1:fccbd0a70492 | 17 | I2C i2c(p9, p10); |
tanahashi | 1:fccbd0a70492 | 18 | |
tanahashi | 1:fccbd0a70492 | 19 | EEPROM eeprom(i2c); |
tanahashi | 1:fccbd0a70492 | 20 | |
tanahashi | 1:fccbd0a70492 | 21 | int addr; |
tanahashi | 1:fccbd0a70492 | 22 | char data[128]; |
tanahashi | 1:fccbd0a70492 | 23 | char buff[128]; |
tanahashi | 1:fccbd0a70492 | 24 | |
tanahashi | 1:fccbd0a70492 | 25 | int main() |
tanahashi | 1:fccbd0a70492 | 26 | { |
tanahashi | 1:fccbd0a70492 | 27 | addr = 0x000000; |
tanahashi | 1:fccbd0a70492 | 28 | for(int i = 0; i < 128; i++) { |
tanahashi | 1:fccbd0a70492 | 29 | data[i] = 0xFF; |
tanahashi | 1:fccbd0a70492 | 30 | } |
tanahashi | 1:fccbd0a70492 | 31 | eeprom.write(addr, data, 128); |
tanahashi | 1:fccbd0a70492 | 32 | eeprom.read(addr, buff, 128); |
tanahashi | 1:fccbd0a70492 | 33 | for(int i = 0; i < 128; i++) { |
tanahashi | 1:fccbd0a70492 | 34 | pc.printf("%x ", buff[i]); |
tanahashi | 1:fccbd0a70492 | 35 | } |
tanahashi | 1:fccbd0a70492 | 36 | } |
tanahashi | 1:fccbd0a70492 | 37 | * @endcode |
tanahashi | 1:fccbd0a70492 | 38 | */ |
tanahashi | 0:559c23c5884c | 39 | class EEPROM |
tanahashi | 0:559c23c5884c | 40 | { |
tanahashi | 0:559c23c5884c | 41 | private: |
tanahashi | 0:559c23c5884c | 42 | I2C *_i2c; |
tanahashi | 0:559c23c5884c | 43 | int _addr; |
tanahashi | 0:559c23c5884c | 44 | char cmd[130]; |
tanahashi | 0:559c23c5884c | 45 | char buff[128]; |
tanahashi | 1:fccbd0a70492 | 46 | |
tanahashi | 0:559c23c5884c | 47 | public: |
tanahashi | 1:fccbd0a70492 | 48 | /** |
tanahashi | 1:fccbd0a70492 | 49 | * @param i2c I2Cのインスタンスへの参照 |
tanahashi | 1:fccbd0a70492 | 50 | */ |
tanahashi | 0:559c23c5884c | 51 | EEPROM(I2C &i2c); |
tanahashi | 1:fccbd0a70492 | 52 | |
tanahashi | 1:fccbd0a70492 | 53 | /** |
tanahashi | 1:fccbd0a70492 | 54 | * 連続書き込み |
tanahashi | 1:fccbd0a70492 | 55 | * @param addr 書き込みアドレス |
tanahashi | 1:fccbd0a70492 | 56 | * @param data 書き込むデータの配列 |
tanahashi | 1:fccbd0a70492 | 57 | * @param size 書き込むデータのサイズ |
tanahashi | 1:fccbd0a70492 | 58 | */ |
tanahashi | 0:559c23c5884c | 59 | void write(int addr, char *data, int size); |
tanahashi | 1:fccbd0a70492 | 60 | |
tanahashi | 1:fccbd0a70492 | 61 | /** |
tanahashi | 1:fccbd0a70492 | 62 | * 連続読み込み |
tanahashi | 1:fccbd0a70492 | 63 | * @param addr 読み込みアドレス |
tanahashi | 1:fccbd0a70492 | 64 | * @param data 読み込むデータの配列 |
tanahashi | 1:fccbd0a70492 | 65 | * @param size 読み込むデータのサイズ |
tanahashi | 1:fccbd0a70492 | 66 | */ |
tanahashi | 0:559c23c5884c | 67 | void read(int addr, char *data, int size); |
tanahashi | 0:559c23c5884c | 68 | }; |
tanahashi | 0:559c23c5884c | 69 | |
tanahashi | 0:559c23c5884c | 70 | #endif |