i2cslave class without interrupt process
Embed:
(wiki syntax)
Show/hide line numbers
i2cslave.h
00001 #ifndef MBED_I2CSLAVE_H 00002 #define MBED_I2CSLAVE_H 00003 00004 #include "mbed.h" 00005 00006 #define SendData 0 00007 #define RequestData 1 00008 00009 class i2cslave : public I2CSlave 00010 { 00011 public: 00012 char *_Registar; 00013 i2cslave(PinName sda, PinName scl, char *Registar); 00014 /*{ 00015 _Registar = Registar; 00016 frequency(400000); 00017 }*/ 00018 00019 void communication(); 00020 /*{ 00021 switch(receive()) 00022 { 00023 case I2CSlave::NoData: //データなし 00024 break; 00025 case I2CSlave::ReadAddressed: //マスターからのデータ送信要求 00026 break; 00027 case I2CSlave::WriteAddressed: //マスターからデータを受信 00028 geti2c(); 00029 break; 00030 case I2CSlave::WriteGeneral: //マスターからデータを受信(全スレーブ宛) 00031 break; 00032 } 00033 }*/ 00034 void geti2c(); 00035 /*{ 00036 char i2cData[3] = {}; 00037 read(i2cData, 3); 00038 wait_us(30); 00039 switch(i2cData[2]) 00040 { 00041 case SendData: 00042 read(_Registar + i2cData[1], i2cData[0]); 00043 break; 00044 case RequestData: 00045 write(_Registar + i2cData[1], i2cData[0]); 00046 break; 00047 } 00048 }*/ 00049 }; 00050 00051 #endif
Generated on Sat Jul 23 2022 22:24:51 by 1.7.2