- 1 -
Doc#
40AN
0002
.
00
©
Silicon Microstructures, Inc. 2001
2015. All rights reserved
+1(408) 577
-
0100 |
sales@si
-
micro.com
|
www.si
-
micro.com
I
2
C Communication with SMI Protocol-A
1. Description
This document is a reference for a possible coding method to achieve pressure, temperature,
and status for SMI part readings using I
2
C. This SMI Protocol-A is used on but not limited to SMI
parts SM9541, SM9543, SM3041, etc. Please check part data sheet for the correct SMI I
2
C
protocol used. For more general information on how to interface using the I
2
C protocol please
refer to http://en.wikipedia.org/wiki/I%C2%B2C. Note that the current example serves as only a
“pseudo-codemeaning that it will not work by itself, needs additional work, and is only meant
for guidance purposes. Therefore this example may look different depending on which coding
language is used.
2. Retrieving data
1: If applicable, include any necessary libraries for I
2
C communication or other
needed protocol with your microcontroller/device.
2: Assign variables and create any setup features.
i2cv.pressure (14 bit Pressure in counts)
i2cv.temperature (11 bit Temperature in counts)
i2cv.status (2 bit Status)
i2c_byte1
i2c_byte2
i2c_byte3
i2c_byte4
(*ETC*)
3: Send I
2
C initialize command (Initialize I
2
C bus to set up communication with
device)
i2c_init();
- 2 -
Doc#
40AN
0002
.
00
©
Silicon Microstructures, Inc. 2001
2015. All rights reserved
+1(408) 577
-
0100 |
sales@si
-
micro.com
|
www.si
-
micro.com
4: Send I
2
C start command (Send start I
2
C condition to begin communication
with device)
i2c_start_bus();
5: To address and read the SMI sensor, the master must write 8 bits total
through I
2
C. The 8 bits consist of the device address and a read command. Send
the 7 bit I
2
C device address command and a least significant bit (LSB) of 1 to tell
the master what address to read from. This will give you an 8 bit address with 7
bit part address shifted left and a LSB of 1 added to end of byte. (Please check
part data sheet for correct device address.)
Device_Read_Byte = (Device Address << 1) + 1;
i2c_write(Device_Read_Byte);
6: Read the SMI part at the device address to gather measurements. This can be
done by setting the master into a receiving state. 4 bytes will have to be read to
gather all measurement information. An acknowledge will have to be sent after
each of the first 3 bytes and not acknowledge on the fourth byte to stop
transmission.
i2c_byte1 = i2c_read_ack();
i2c_byte2 = i2c_read_ack();
i2c_byte3 = i2c_read_ack();
i2c_byte4 = i2c_read_nack();
7: Stop bus, this ends communication with bus, this can be a reset if trying to
receive multiple readings.
stop_i2c_bus();
3. Converting Bytes
To collect pressure, temperature, and status, 4 bytes of data have to be read. These bytes will
be converted and rearranged to be able to read temperature, pressure, and status of the
device. If only 1 or 2 of the 3 device output values are needed, reading less bytes may be
sufficient. For example If only pressure is needed, only 2 bytes can be read to obtain the full 14
bit pressure reading. See diagram below in section 3 for more details.
1: Converting Temperature Reading.
Temperature conversion consists of a right-shift of the fourth byte by 5 bits (last
5 bits will not contain any data). Then taking the third byte and shifting it left by
3 bits. This is done by multiplying by 8 (8 = 2
3
). Adding both these values
together achieves an 11 bit temperature reading.