MCP3204をSTM303K8T6で同時に6個使ってみた
Dependencies: mbed 24LC1025 MCP3204
Diff: main.cpp
- Revision:
- 4:56d1f3a81b30
- Parent:
- 3:99c659d89698
- Child:
- 5:7d768f3acdd8
--- a/main.cpp Wed Sep 09 08:07:13 2020 +0000 +++ b/main.cpp Thu Sep 17 02:18:16 2020 +0000 @@ -117,37 +117,66 @@ pc.printf(",%.2f\r\n", cal_z); if(page_frg == 0){ + pc.printf("s:%d,0x%x\r\n",page_frg,eeprom_cnt); *(float*)serialData=0.0f; eeprom.PageWrite(ADDRESS_24LC1025_BLOCK0,eeprom_cnt,serialData,4); + eeprom_cnt = 0x04 + eeprom_cnt; + wait(0.01); + pc.printf("s:%d,0x%x\r\n",page_frg,eeprom_cnt); *(float*)serialData=cal_x; eeprom.PageWrite(ADDRESS_24LC1025_BLOCK0,eeprom_cnt,serialData,4); + wait(0.01); + eeprom_cnt = 0x04 + eeprom_cnt; + pc.printf("s:%d,0x%x\r\n",page_frg,eeprom_cnt); *(float*)serialData=cal_y; eeprom.PageWrite(ADDRESS_24LC1025_BLOCK0,eeprom_cnt,serialData,4); + wait(0.01); + eeprom_cnt = 0x04 + eeprom_cnt; + pc.printf("s:%d,0x%x\r\n",page_frg,eeprom_cnt); *(float*)serialData=cal_z; eeprom.PageWrite(ADDRESS_24LC1025_BLOCK0,eeprom_cnt,serialData,4); + wait(0.01); + eeprom_cnt = 0x04 + eeprom_cnt; + pc.printf("s:%d,0x%x\r\n",page_frg,eeprom_cnt); *(float*)serialData=world_time; eeprom.PageWrite(ADDRESS_24LC1025_BLOCK0,eeprom_cnt,serialData,4); + wait(0.01); + eeprom_cnt = 0x04 + eeprom_cnt; + pc.printf("s:%d,0x%x\r\n",page_frg,eeprom_cnt); *(float*)serialData=0.0f; eeprom.PageWrite(ADDRESS_24LC1025_BLOCK0,eeprom_cnt,serialData,4); - //pc.printf("%d,0x%x\r\n",page_frg,eeprom_cnt); + wait(0.01); + eeprom_cnt = 0x04 + eeprom_cnt; + pc.printf("e:%d,0x%x\r\n",page_frg,eeprom_cnt); }else if(page_frg == 1){ *(float*)serialData=0.0f; + pc.printf("%d,0x%x\r\n",page_frg,eeprom_cnt); + eeprom.PageWrite(ADDRESS_24LC1025_BLOCK1,eeprom_cnt,serialData,4); + wait(0.01); + eeprom_cnt = 0x04 + eeprom_cnt; + *(float*)serialData=cal_x; + eeprom.PageWrite(ADDRESS_24LC1025_BLOCK1,eeprom_cnt,serialData,4); + wait(0.01); + eeprom_cnt = 0x04 + eeprom_cnt; + *(float*)serialData=cal_y; + eeprom.PageWrite(ADDRESS_24LC1025_BLOCK1,eeprom_cnt,serialData,4); + wait(0.01); + eeprom_cnt = 0x04 + eeprom_cnt; + *(float*)serialData=cal_z; + eeprom.PageWrite(ADDRESS_24LC1025_BLOCK1,eeprom_cnt,serialData,4); + wait(0.01); + eeprom_cnt = 0x04 + eeprom_cnt; + *(float*)serialData=world_time; + eeprom.PageWrite(ADDRESS_24LC1025_BLOCK1,eeprom_cnt,serialData,4); + wait(0.01); + eeprom_cnt = 0x04 + eeprom_cnt; + *(float*)serialData=0.0f; eeprom.PageWrite(ADDRESS_24LC1025_BLOCK1,eeprom_cnt,serialData,4); - *(float*)serialData=cal_x; - eeprom.PageWrite(ADDRESS_24LC1025_BLOCK1,eeprom_cnt,serialData,4); - *(float*)serialData=cal_y; - eeprom.PageWrite(ADDRESS_24LC1025_BLOCK1,eeprom_cnt,serialData,4); - *(float*)serialData=cal_z; - eeprom.PageWrite(ADDRESS_24LC1025_BLOCK1,eeprom_cnt,serialData,4); - *(float*)serialData=world_time; - eeprom.PageWrite(ADDRESS_24LC1025_BLOCK1,eeprom_cnt,serialData,4); - *(float*)serialData=0.0f; - eeprom.PageWrite(ADDRESS_24LC1025_BLOCK1,eeprom_cnt,serialData,4); - //pc.printf("%d,0x%x\r\n",page_frg,eeprom_cnt); + eeprom_cnt = 0x04 + eeprom_cnt; + wait(0.01); }else{ - //pc.printf("EEPROM_ERROR!! You should erase memory\r\n"); + pc.printf("EEPROM_ERROR!! You should erase memory\r\n"); } - eeprom_cnt = 0x18 + eeprom_cnt; } @@ -182,6 +211,12 @@ pc.printf("Hello world%d\r\n",sizeof(i)); led = 1; wait(1.0); + *(float*)serialData=0.0f; + for(i=0;i<6;i++){ + eeprom.PageWrite(ADDRESS_24LC1025_BLOCK0,eeprom_cnt,serialData,4); + eeprom_cnt = 0x04 + eeprom_cnt; + wait(0.1); + } while(1){ adc1[0] = mcp1.sgl( CH0 ); @@ -347,7 +382,7 @@ }else{ pc.printf("none\r\n"); } - pc.printf("%d,%x,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f\r\n",page_frg,eeprom_cnt,ave[1],ave[2],ave[3],ave[5],ave[4],ave[0]); + //pc.printf("%d,%x,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f\r\n",page_frg,eeprom_cnt,ave[1],ave[2],ave[3],ave[5],ave[4],ave[0]); for(i=0; i<6; i++){ *(float*)serialData = ave[i]; @@ -359,7 +394,7 @@ if(page_frg == 0){ eeprom.PageWrite(ADDRESS_24LC1025_BLOCK0,eeprom_cnt,serialData,4); - //pc.printf("%d,0x%x\r\n",page_frg,eeprom_cnt); + pc.printf("%d,0x%x,%.1f\r\n",page_frg,eeprom_cnt,ave[i]); }else if(page_frg == 1){ eeprom.PageWrite(ADDRESS_24LC1025_BLOCK1,eeprom_cnt,serialData,4); //pc.printf("%d,0x%x\r\n",page_frg,eeprom_cnt);