Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info
Excerpt

Sensirion I2C temperature/humidity sensors are almost trivially easy to use with the On-Chip SDK.  In this post recipe, we connect a mote to the SHT21.

...

Sensirion makes a line of very low power I2C temperature and humidity sensors that are almost trivially easy to interface to a mote using the On-chip SDK (OCSDK).  We only need to make a few changes to the 02-i2c sample to start making measurements with the SHT21. This exercise assumes you have already set up your IAR toolchain and can compile the examples found in the OCSDK.

Hardware Connection

SHT21 PinDC9003 Pin
1 (SDA)P3.9 (S_SSn/SDA)
2 (VSS)P1.24 (GND)
5 (VDD)P1.22 (VSUPPLY)
6 (SCL)P3.11 (S_SCK/SCL)

Software

The first thing we need to do is select the correct slave address I2C_SLAVE_ADDR for the SHT21.  I2C uses 7-bit addresses, which are followed by a read/write bit.   The SHT21 data sheet gives the device address as '1000’000’ - it's tempting to interpret this as 0x80, but the OCSDK driver is expecting a right-justified 7-bit value.  The driver shifts the 7-bit word left and inserts the read/write bit automatically depending on the format of the dn_ioctl call. Thus the I2_SLAVE_ADDR is:

...

The SHT21 uses 1-byte commands, so we need to change the contents of the buffer for the write.  The SHT21 datasheet defines the command set:

Command

CodeHex
Temperature Measurement

1110’0011 

0xE3
Relative Humidity Measurement

1110’0101 

0xE5
Temperature Measurement (no hold)

1111’0011 

0xF3
Relative Humidity Measurement (no hold)

1111’0101 

0xF3

Write user register

1110’0110 

0xE6

Read user register

1110’0111 

0xE7
Soft Reset

1111’1110 

0xFE

Normally the sensor holds the SCL line to force the master to pause (here during the measurement) until the slave is ready to answer. In the "no hold" versions of the command the sensor does not hold the line - this allows the master to move to another device in a multi-drop scenario.  We use the normal temperature measurement in the sample, so we set the i2cbuffer as follows:

...