Rod Montrose[AVIDwireless]
unread,May 29, 2008, 11:40:59 AM5/29/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to AVIDdirector-M2M
Look in the M2M_IO.java source code - there's an example of reading
the on board temperature I2C sensor on the device. Its in the method
readBoardTemperature(). This uses the PSoC I2C functions direction
(Function 0x21) to access the I2C bus.
The I2C commands are written using byte arrays containing the commands
to write to the bus:
/** First a write to set the address inside the temp chip that we are
interested
* in. Note that the address of the temp sensor is 0x48--funny
coincidence
* that the PSoC I2C function is 0x48 also. The actual transmission to
the I2C
* bus is shifted left one and the read/write bit appended on at bit 0
to get a
* 90 (write) or 91 (read) as shown in the temp sensor data sheet. 21
is the
* control byte, which is a write of one byte with no stop. The byte
written
* is 0, which sets up the subsequent read to access the current
temperature
* register.
*/
private static byte[] initializeTCM75 = {0x48, 0x21, 0x48, 0x0};
/**
* Now a read from the register specified in the write. The 92 means
a read of
* two characters, continuing an operation done previously without a
stop.
*/
private static byte[] readTCM75temperature = {0x48, (byte)0x92, 0x48};
The code is:
// Initialize the temperature sensor to read the temperature
Hardware_API.PSoC_WrtReadByteArray(initializeTCM75, null);
// Then start the read operation to get the temperature
Hardware_API.PSoC_WrtReadByteArray(readTCM75temperature, null);
// And Perform the read operation and end the I2C operation
byte [] temperatureData = new byte[2];
int retryCounter = 0;
int returnDataLength = 0;
short status;
do {
status = Hardware_API.PSoC_ReadI2CData(temperatureData);
returnDataLength = status & 0x0f;
if (returnDataLength == 2) {
/* The temperature value is 9 bits long.
The status is 52, which is no errors having received two bytes. The
value
returned is 26 80, which after shifting around as shown in the data
sheet is
4D or 77. Each count is worth 0.5 deg C., so this is 38.5 deg c. */
int rawTemp = AvidUtil.byteArrayToInt(temperatureData, 0,
temperatureData.length);
int temp = rawTemp >> 7;
if (temp > 255) temp = 512 - temp; // perform twos compliment
temperature = ((float)temp) / 2.0f;
if (Logger.isDebug())
Logger.debugln("M2M_IO.readBoardTemperature","Temp = "+
temperature+" C (raw = "+temp+";"+rawTemp+" "+
AvidUtil.getByteArrayAsHexString(temperatureData,
0,temperatureData.length,',')+
" status="+AvidUtil.getUnsignedByteAsHexString(status)
+":"+retryCounter+")");
} else {
AvidUtil.waitHereMs(10);
retryCounter++;
}
} while ((returnDataLength == 0) && (retryCounter < 200));
if (returnDataLength == 0) throw new RuntimeException ("No data
returned from TCN75.
Status="+AvidUtil.getUnsignedByteAsHexString(status));