67 lines
1.2 KiB
C
67 lines
1.2 KiB
C
#include "ls1x.h"
|
|
#include "Config.h"
|
|
#include "1c102_myI2C.h"
|
|
#include "1c102_dev_SHT31.h"
|
|
|
|
/*
|
|
* CRC-8 formula from page 14 of SHT spec pdf
|
|
* Test data 0xBE, 0xEF should yield 0x92
|
|
* Initialization data 0xFF
|
|
* Polynomial 0x31 (x8 + x5 +x4 +1)
|
|
* Final XOR 0x00
|
|
*/
|
|
uint8_t CRC_8(const uint8_t *data, int len)
|
|
{
|
|
const uint8_t POLYNOMIAL = 0x31;
|
|
uint8_t crc = 0xFF;
|
|
int j;
|
|
int i;
|
|
|
|
for(j = len; j; --j)
|
|
{
|
|
crc ^= *data++;
|
|
|
|
for(i = 8; i; --i)
|
|
{
|
|
crc = (crc&0x80)? (crc << 1)^POLYNOMIAL:(crc << 1);
|
|
}
|
|
}
|
|
|
|
return crc;
|
|
}
|
|
|
|
void Get_TandRH()
|
|
{
|
|
uint8_t buf[10];
|
|
int buf_len = 0;
|
|
uint8_t cmd[2] = {0x24, 0x0B};
|
|
uint32_t temp, rh = 0;
|
|
|
|
myI2C_write_mult(SHT31_INTERFACE_ADDR, SHT31_DEFAULT_ADDR, cmd, 2);
|
|
buf_len = myI2C_read_mult(SHT31_INTERFACE_ADDR, SHT31_DEFAULT_ADDR, buf);
|
|
|
|
printf("buf_len = %d\n", buf_len);
|
|
if(buf_len >= 6)
|
|
{
|
|
temp = (buf[0]&0xFF)<<8 | buf[1];
|
|
rh = (buf[3]&0xFF)<<8 | buf[4];
|
|
|
|
printf("Temp=0x%02x, RH=0x%02x.\n", temp, rh);
|
|
|
|
temp = (175*(temp/0xFFFF))-45;
|
|
rh = 100*(rh/0xFFFF);
|
|
}
|
|
|
|
|
|
return;
|
|
}
|
|
|
|
void Get_RegValue()
|
|
{
|
|
return;
|
|
}
|
|
|
|
void Set_RegValue()
|
|
{
|
|
return;
|
|
} |