CatPot 2015-2016
/
CatPotI2CSlavetest
test program of I2CSlave
Fork of CatPotI2CSlavetest by
main.cpp@0:dcc9cf1071f1, 2014-12-15 (annotated)
- Committer:
- ryuna
- Date:
- Mon Dec 15 07:37:14 2014 +0000
- Revision:
- 0:dcc9cf1071f1
- Child:
- 1:178963fb9f75
ver.1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ryuna | 0:dcc9cf1071f1 | 1 | #include "mbed.h" |
ryuna | 0:dcc9cf1071f1 | 2 | #include "Ping.h" |
ryuna | 0:dcc9cf1071f1 | 3 | |
ryuna | 0:dcc9cf1071f1 | 4 | #define SYSAHBCLKDIV_Val 0x00000001 // Reset: 0x001 |
ryuna | 0:dcc9cf1071f1 | 5 | #define CLOCK_SETUP 1 // デフォルト=1 |
ryuna | 0:dcc9cf1071f1 | 6 | #define SYSPLLCTRL_Val 0x00000023 // デフォルト=23 Reset: 0x000 |
ryuna | 0:dcc9cf1071f1 | 7 | #define SYSPLLCLKSEL_Val 0x00000001 // デフォルト=0 Reset: 0x000 |
ryuna | 0:dcc9cf1071f1 | 8 | #define MAINCLKSEL_Val 0x00000003 // デフォルト=3 Reset: 0x000 |
ryuna | 0:dcc9cf1071f1 | 9 | |
ryuna | 0:dcc9cf1071f1 | 10 | |
ryuna | 0:dcc9cf1071f1 | 11 | #define ADDRESS 0xA0 |
ryuna | 0:dcc9cf1071f1 | 12 | #define DATA_NUM 5 |
ryuna | 0:dcc9cf1071f1 | 13 | |
ryuna | 0:dcc9cf1071f1 | 14 | DigitalOut myled(LED1); |
ryuna | 0:dcc9cf1071f1 | 15 | I2CSlave Tiny(dp5, dp27); |
ryuna | 0:dcc9cf1071f1 | 16 | Ping Sensor(dp1,dp2); |
ryuna | 0:dcc9cf1071f1 | 17 | Serial pc(USBTX, USBRX); |
ryuna | 0:dcc9cf1071f1 | 18 | |
ryuna | 0:dcc9cf1071f1 | 19 | int main() { |
ryuna | 0:dcc9cf1071f1 | 20 | |
ryuna | 0:dcc9cf1071f1 | 21 | char Export[DATA_NUM]={0}; |
ryuna | 0:dcc9cf1071f1 | 22 | uint8_t cycle=0; |
ryuna | 0:dcc9cf1071f1 | 23 | |
ryuna | 0:dcc9cf1071f1 | 24 | Tiny.address(ADDRESS); |
ryuna | 0:dcc9cf1071f1 | 25 | //Tiny.frequency(9600); |
ryuna | 0:dcc9cf1071f1 | 26 | |
ryuna | 0:dcc9cf1071f1 | 27 | while(1) { |
ryuna | 0:dcc9cf1071f1 | 28 | |
ryuna | 0:dcc9cf1071f1 | 29 | |
ryuna | 0:dcc9cf1071f1 | 30 | Sensor.Send(); |
ryuna | 0:dcc9cf1071f1 | 31 | wait_ms(30); |
ryuna | 0:dcc9cf1071f1 | 32 | Export[cycle%DATA_NUM] = 0xAA;//Sensor.Read_cm(); |
ryuna | 0:dcc9cf1071f1 | 33 | |
ryuna | 0:dcc9cf1071f1 | 34 | cycle++; |
ryuna | 0:dcc9cf1071f1 | 35 | |
ryuna | 0:dcc9cf1071f1 | 36 | switch(Tiny.receive()){ |
ryuna | 0:dcc9cf1071f1 | 37 | |
ryuna | 0:dcc9cf1071f1 | 38 | case I2CSlave::ReadAddressed: |
ryuna | 0:dcc9cf1071f1 | 39 | Tiny.write(Export, DATA_NUM); // Includes null char |
ryuna | 0:dcc9cf1071f1 | 40 | break; |
ryuna | 0:dcc9cf1071f1 | 41 | case I2CSlave::WriteGeneral: |
ryuna | 0:dcc9cf1071f1 | 42 | break; |
ryuna | 0:dcc9cf1071f1 | 43 | case I2CSlave::WriteAddressed: |
ryuna | 0:dcc9cf1071f1 | 44 | break; |
ryuna | 0:dcc9cf1071f1 | 45 | } |
ryuna | 0:dcc9cf1071f1 | 46 | |
ryuna | 0:dcc9cf1071f1 | 47 | } |
ryuna | 0:dcc9cf1071f1 | 48 | } |