-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSi7021_I2C.c
86 lines (67 loc) · 1.36 KB
/
Si7021_I2C.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Si7021_I2C.c
*
* Created on: Feb 3, 2019
* Author: aakash
*/
#include "Si7021_I2C.h"
static int32_t temp_data;
void temp_sensor_init()
{
//Initialize I2C peripheral
I2C_SWSTK_Init();
/*
* init_App() turns on sensor, turn off
* till measurement is to be taken
*/
temp_sensor_lpm_off();
}
void measure_temp_non_blocking(void)
{
I2C_Command_Read_NonBlocking(I2CPORT_USED, SI7021_ADDR, SI7013_TEMP);
}
int32_t get_temp_val()
{
get_I2C_read_data(&temp_data);
return (((temp_data) * 21965L) >> 13) - 46850;;
}
void get_transfer_error(void)
{
}
int32_t get_humidity(uint32_t *data)
{
int ret = I2C_Command_Read(I2CPORT_USED, SI7021_ADDR, data,SI7013_RH);
if (ret == 2)
{
/* convert to milli-percent */
*data = (((*data) * 15625L) >> 13) - 6000;
}
else
return -1;
return 0;
}
int32_t get_temp(int32_t *data)
{
int ret = I2C_Command_Read(I2CPORT_USED, SI7021_ADDR, (uint32_t *)data,SI7013_TEMP);
if (ret == 2)
{
/* convert to milli-percent */
*data = (((*data) * 21965L) >> 13) - 46850;
}
else
return -1;
return 0;
}
int32_t get_temp_humidity(int32_t *tdata, uint32_t *rhData)
{
/*
* Run humidity measurement first as
* temp measurement used gets the temp
* measured during last humidity measure
*/
if(get_humidity(rhData) != 0)
return -1;
if(get_temp(tdata) !=0)
return -1;
return 0;
}