This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

i2c例程有不懂的部份

Other Parts Discussed in Thread: TMP102, CC1310

下面红色区是里面我比较不懂得地方,不知道为啥要这么写,有人可以指导一下吗

1.为啥rxBuffer[0] 要左移6,rxBuffer[1]要右移2,而且rxBuffer[0] 和rxBuffer[1]是代表啥

2.  不清楚这一段代表意思

3.为啥需要除32,数据有经过什么处理吗


for (i = 0; i < 20; i++) {
if (I2C_transfer(i2c, &i2cTransaction)) {
/* Extract degrees C from the received data; see TMP102 datasheet */
temperature = (rxBuffer[0] << 6) | (rxBuffer[1] >> 2);

/*
* If the MSB is set '1', then we have a 2's complement
* negative value which needs to be sign extended
*/
if (rxBuffer[0] & 0x80) {
temperature |= 0xF000;
}
/*
* For simplicity, divide the temperature value by 32 to get rid of
* the decimal precision; see TI's TMP007 datasheet
*/
temperature /= 32;