The following example shows you how to use Z-Wave Multilevel sensor example running on BRD2603A/ZGM230S to read temperature from Texas Instrument TMP116 temperature sensor.
1. Connect Texas Instrument BOOSTXL-BASSENSORS TMP116 TMP V+, GND, and SCL/SDA to pin 20, 1, and 15(PB05)/16(PB05) on EXP-header of BRD2603A.
2. Install Z-Wave Debug and Z-Wave Debug Print in project software component to use DEBUGPRINT to output data to SSv5 console 1.
3.Add the following code into MultilevelSensor_interface_sensor.c
#define TMP116_I2C_DEVICE (sl_i2cspm_sensor) /**< I2C device used to control the Si7021 */
#define TMP116_I2C_BUS_ADDRESS 0x48//TMP116 0x40 /**< I2C bus address */
static I2C_TransferReturn_TypeDef TMP116_transaction(uint16_t flag,
uint8_t *writeCmd,
size_t writeLen,
uint8_t *readCmd,
size_t readLen)
{
I2C_TransferSeq_TypeDef seq;
I2C_TransferReturn_TypeDef ret;
seq.addr = TMP116_I2C_BUS_ADDRESS << 1;
seq.flags = flag;
switch (flag) {
// Send the write command from writeCmd
case I2C_FLAG_WRITE:
seq.buf[0].data = writeCmd;
seq.buf[0].len = writeLen;
break;
// Receive data into readCmd of readLen
case I2C_FLAG_READ:
seq.buf[0].data = readCmd;
seq.buf[0].len = readLen;
break;
// Send the write command from writeCmd
// and receive data into readCmd of readLen
case I2C_FLAG_WRITE_READ:
seq.buf[0].data = writeCmd;
seq.buf[0].len = writeLen;
seq.buf[1].data = readCmd;
seq.buf[1].len = readLen;
break;
default:
return i2cTransferUsageFault;
}
// Perform the transfer and return status from the transfer
ret = I2CSPM_Transfer(TMP116_I2C_DEVICE, &seq);
return ret;
}
uint32_t TMP116_read()
{
I2C_TransferReturn_TypeDef ret;
uint8_t temp[2];
uint8_t cmdReadTemp[1]={0x00};
int32_t temperature;
// Wait for sensor to become ready
//sl_sleeptimer_delay_millisecond(1000);
// Check for device presence and compare device ID
ret = TMP116_transaction(I2C_FLAG_WRITE_READ, cmdReadTemp, 1, temp, 2);
temperature=temp[0];
temperature=(temperature<<8)|temp[1];
//DPRINTF("Temperature = %d\r\n", (int)temperature);
return temperature*10;
}
4. Replace "MultilevelSensor_temperature_humidity_sensor_read(&rh_data, &temp_data);" with "temp_data=(int32_t)TMP116_read();" in cc_multilevel_sensor_air_temperature_interface_read_value.
5. Build and run the firmware on BRD2603A to see the following temperature reading fromTMP116
P.S. If you use Texas Instrument instead of TMP117, it should work similarly.
No comments:
Post a Comment