Created
September 20, 2020 04:02
-
-
Save sepfy/56d8d5929e1ebdad7c7835cd70dc230e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int val = 0; | |
int temp, humi; | |
u8 bytes[6] = {0}; | |
const u8 cmd[6] = {0}; | |
u32 s; | |
printk("[%s][%d]\n", __func__, __LINE__); | |
s = i2c_smbus_write_i2c_block_data(i2c_client, 0x24, 1, cmd); | |
if(s < 0) { | |
printk("[%s][%d]: i2c write block data failed\n", __func__, __LINE__); | |
return -1; | |
} | |
mdelay(16); | |
s = i2c_smbus_read_i2c_block_data(i2c_client, 0x00, 6, bytes); | |
if(s < 0) { | |
printk("[%s][%d]: i2c read block data failed\n", __func__, __LINE__); | |
return -1; | |
} | |
temp = (bytes[0] << 8) + bytes[1]; | |
humi = (bytes[3] << 8) + bytes[4]; | |
if(bytes[2] != crc(&bytes[0], 2)) { | |
temp = 0; | |
printk("[%s][%d] Temperature CRC error\n", __func__, __LINE__); | |
} | |
if(bytes[5] != crc(&bytes[3], 2)) { | |
humi = 0; | |
printk("[%s][%d] Humidity CRC error\n", __func__, __LINE__); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment