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.
Dependencies: mbed
Diff: I2CSlaveComm.cpp
- Revision:
- 2:d0308b3aaf69
- Parent:
- 1:85afd4bd4651
- Child:
- 3:29925a0f88da
--- a/I2CSlaveComm.cpp Wed Oct 31 14:52:28 2018 +0000 +++ b/I2CSlaveComm.cpp Wed Oct 31 16:08:34 2018 +0000 @@ -1,11 +1,12 @@ #include "mbed.h" #include "I2CSlaveComm.h" -I2CSlaveCustom slave(D14, D15); -I2CSlaveCustom slave2(D2, D8); //use another I2C to emulate the adc +I2CSlaveCustom slave(D4, D7); +I2CSlaveCustom slave2(D14, D15); //use another I2C to emulate the adc unsigned char PointOnAddress = 0; -unsigned short ReadADCValue = 0; + +unsigned char ADCValue[2]; #pragma pack(push,1) struct SmartSensorStruct { char crc; ///< Checksum CRC8 @@ -39,9 +40,14 @@ } } -void setADC(unsigned short value) +void setTension(double value) { - ReadADCValue = value; + int tension = (int)(value*100); + + int adc = ((1000 * (tension - stSensor.c3)) / stSensor.c2) - stSensor.c1; + adc = adc / 4; //into low read of the ST + ADCValue[0] = (adc >> 8)&0xFF; + ADCValue[1] = (adc)&0xFF; } char ComputeCRC8(char *buff, char len, char start_data) @@ -94,11 +100,8 @@ ret = slave.read(buf, nbRx); SaveRamBuffer(PointOnAddress, buf, nbRx); } - printf("nb rx %d %d\r\n", nbRx, PointOnAddress); - break; } - wait_ms(1); } void I2C_2Process() @@ -109,8 +112,7 @@ switch (rx) { case I2CSlave::ReadAddressed: - slave2.write((char*)&ReadADCValue, 2); - printf("ReadAddressed 2 end\n"); + slave2.write((char*)&ADCValue, 2); break; /*case I2CSlave::WriteGeneral: @@ -119,12 +121,11 @@ case I2CSlave::WriteAddressed: //to empty read buffer we do nothing with the data int ret = slave2.read(buf, 1); - nbRx = slave.getCount(); + nbRx = slave2.getCount(); if (nbRx > 0) //to simulate write on EEPROM need to test { ret = slave2.read(buf, nbRx); } - printf("nb rx2 %d %d\r\n", nbRx, PointOnAddress); break; } }