Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@1:17efbc35c3ba, 2020-07-20 (annotated)
- Committer:
- rary
- Date:
- Mon Jul 20 13:20:43 2020 +0000
- Revision:
- 1:17efbc35c3ba
- Parent:
- 0:637769b3a60b
mulch EEPROM
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rary | 0:637769b3a60b | 1 | #include "mbed.h" |
| rary | 0:637769b3a60b | 2 | #include "EEPROM.h" |
| rary | 0:637769b3a60b | 3 | #include "LPS33HW.h" |
| rary | 0:637769b3a60b | 4 | |
| rary | 0:637769b3a60b | 5 | Timer t; //時間計測 |
| rary | 0:637769b3a60b | 6 | Serial pc(USBTX, USBRX); |
| rary | 0:637769b3a60b | 7 | LPS33HW lps(p9, p10); |
| rary | 0:637769b3a60b | 8 | EEPROM e2prom(p9, p10); |
| rary | 0:637769b3a60b | 9 | |
| rary | 0:637769b3a60b | 10 | |
| rary | 1:17efbc35c3ba | 11 | #define ADDR 0xA6 //コントロールアドレス |
| rary | 0:637769b3a60b | 12 | |
| rary | 0:637769b3a60b | 13 | int pointerAddress = 0; |
| rary | 0:637769b3a60b | 14 | |
| rary | 0:637769b3a60b | 15 | //main |
| rary | 0:637769b3a60b | 16 | int main() |
| rary | 0:637769b3a60b | 17 | { |
| rary | 1:17efbc35c3ba | 18 | int n; |
| rary | 1:17efbc35c3ba | 19 | char data_read[128]; |
| rary | 1:17efbc35c3ba | 20 | char s[128]; //データ格納配列 |
| rary | 1:17efbc35c3ba | 21 | |
| rary | 1:17efbc35c3ba | 22 | pc.baud(460800); |
| rary | 0:637769b3a60b | 23 | |
| rary | 0:637769b3a60b | 24 | //readEEPROM(ADDR, pointerAddress, data_read, h); |
| rary | 0:637769b3a60b | 25 | //pc.printf("Previous data stored:%s\r\n", data_read); |
| rary | 0:637769b3a60b | 26 | |
| rary | 0:637769b3a60b | 27 | t.start(); //timer Start |
| rary | 0:637769b3a60b | 28 | |
| rary | 1:17efbc35c3ba | 29 | for(n = 0; n < 500; n++) { |
| rary | 0:637769b3a60b | 30 | lps.start(1); //気圧センサスタート |
| rary | 0:637769b3a60b | 31 | double P = lps.data_read(); //気圧データ取得 |
| rary | 0:637769b3a60b | 32 | double T = t.read(); //時刻データ取得 |
| rary | 0:637769b3a60b | 33 | |
| rary | 1:17efbc35c3ba | 34 | sprintf(s, "%d, %.3f, %.3f\r\n", n, T, P); //floatからchar*へ変換 |
| rary | 0:637769b3a60b | 35 | |
| rary | 0:637769b3a60b | 36 | // write tha data |
| rary | 1:17efbc35c3ba | 37 | e2prom.write(ADDR, pointerAddress, s, 128); |
| rary | 1:17efbc35c3ba | 38 | pc.printf("%d, Data written: %s\r\n", n, s); |
| rary | 0:637769b3a60b | 39 | |
| rary | 1:17efbc35c3ba | 40 | pointerAddress = pointerAddress + 128; //アドレスずらし |
| rary | 1:17efbc35c3ba | 41 | memset(s, '\0' , 128 ); //初期化 |
| rary | 1:17efbc35c3ba | 42 | wait(0.01); |
| rary | 0:637769b3a60b | 43 | } |
| rary | 0:637769b3a60b | 44 | |
| rary | 0:637769b3a60b | 45 | //read the data |
| rary | 0:637769b3a60b | 46 | pointerAddress = 0; |
| rary | 0:637769b3a60b | 47 | pc.printf("Data read\r\n"); |
| rary | 0:637769b3a60b | 48 | |
| rary | 1:17efbc35c3ba | 49 | for(n = 0; n < 500; n++) { |
| rary | 1:17efbc35c3ba | 50 | e2prom.read(ADDR, pointerAddress, data_read, 128); |
| rary | 0:637769b3a60b | 51 | pc.printf("%s", data_read); |
| rary | 0:637769b3a60b | 52 | |
| rary | 1:17efbc35c3ba | 53 | pointerAddress = pointerAddress + 128; |
| rary | 1:17efbc35c3ba | 54 | memset(data_read, '\0' , 128 ); //初期化 |
| rary | 0:637769b3a60b | 55 | } |
| rary | 0:637769b3a60b | 56 | |
| rary | 0:637769b3a60b | 57 | pc.printf("Finish"); |
| rary | 0:637769b3a60b | 58 | } |