Fumiya Fujisawa
/
CatPotI2CSlavetest
SlaveTest
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "Ping.h" 00003 00004 #define SYSAHBCLKDIV_Val 0x00000001 // Reset: 0x001 00005 #define CLOCK_SETUP 1 // デフォルト=1 00006 #define SYSPLLCTRL_Val 0x00000023 // デフォルト=23 Reset: 0x000 00007 #define SYSPLLCLKSEL_Val 0x00000001 // デフォルト=0 Reset: 0x000 00008 #define MAINCLKSEL_Val 0x00000003 // デフォルト=3 Reset: 0x000 00009 00010 00011 #define ADDRESS 0xA0 00012 #define DATA_NUM 5 00013 00014 DigitalOut myled(LED1); 00015 I2CSlave Tiny(dp5, dp27); 00016 Ping Sensor(dp1,dp2); 00017 Serial pc(USBTX, USBRX); 00018 00019 int main() { 00020 00021 char Export[DATA_NUM]={0}; 00022 uint8_t cycle=0; 00023 00024 Tiny.address(ADDRESS); 00025 //Tiny.frequency(9600); 00026 00027 while(1) { 00028 00029 00030 Sensor.Send(); 00031 wait_ms(30); 00032 Export[cycle%DATA_NUM] = 0xAA;//Sensor.Read_cm(); 00033 00034 cycle++; 00035 00036 switch(Tiny.receive()){ 00037 00038 case I2CSlave::ReadAddressed: 00039 Tiny.write(Export, DATA_NUM); // Includes null char 00040 break; 00041 case I2CSlave::WriteGeneral: 00042 break; 00043 case I2CSlave::WriteAddressed: 00044 break; 00045 } 00046 00047 } 00048 }
Generated on Tue Aug 9 2022 10:08:36 by 1.7.2