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.
Diff: YKNCT_I2C.cpp
- Revision:
- 8:f7779710d64a
- Parent:
- 7:5b22492a5a13
- Child:
- 9:f892d57a6714
--- a/YKNCT_I2C.cpp Mon Apr 15 10:42:16 2019 +0000 +++ b/YKNCT_I2C.cpp Tue Apr 16 10:54:57 2019 +0000 @@ -15,33 +15,25 @@ void Y_I2C::Out(OUT_I2C_Data_TypeDef *OUT_I2C_Data, uint8_t num) { - i2c.write((OUT_I2C_Data+num) -> DevAddress<<1, &(OUT_I2C_Data+num)->out_data,1); + i2c.write((OUT_I2C_Data+num) -> DevAddress<<1, &(OUT_I2C_Data+num)->out_data, 1, false); + wait_us(1000); +} + +void Y_I2C::In(IN_I2C_Data_TypeDef *IN_I2C_Data, uint8_t num) +{ + i2c.read((IN_I2C_Data+num) -> DevAddress<<1, &(IN_I2C_Data+num)->in_data, 1, false); wait_us(1000); - } -int Y_I2C::In(int address, int num) -{ - static char data=0; - - i2c.read(address<<1, &data, 1, false); - - wait_us(1000); - return data>>num&1; -} - -int Y_I2C::Adc(int address, int num) +void Y_I2C::Adc(ADC_I2C_Data_TypeDef *ADC_I2C_Data, uint8_t num) { static char data[8]= {0}; - static int ad_data[4]= {0}; - i2c.read(address<<1, data, 8, false); + i2c.read((ADC_I2C_Data+num) -> DevAddress<<1, data, 8, false); for(int i=0; i<4; i++) - ad_data[i]=(int16_t)data[i*2+1]<<8|data[i*2]; - + (ADC_I2C_Data+num)->adc_data[i]=(int16_t)data[i*2+1]<<8|data[i*2]; wait_us(1000); - return ad_data[num]; } double Y_I2C::Enc(int address)