LibDriver HDC1080
Loading...
Searching...
No Matches
driver_hdc1080_read_test.c
Go to the documentation of this file.
1
36
38
39static hdc1080_handle_t gs_handle;
40
49uint8_t hdc1080_read_test(uint32_t times)
50{
51 uint8_t res;
52 uint32_t i;
53 hdc1080_info_t info;
54
55 /* link interface function */
64
65 /* get hdc1080 information */
66 res = hdc1080_info(&info);
67 if (res != 0)
68 {
69 hdc1080_interface_debug_print("hdc1080: get info failed.\n");
70
71 return 1;
72 }
73 else
74 {
75 /* print hdc1080 information */
76 hdc1080_interface_debug_print("hdc1080: chip is %s.\n", info.chip_name);
77 hdc1080_interface_debug_print("hdc1080: manufacturer is %s.\n", info.manufacturer_name);
78 hdc1080_interface_debug_print("hdc1080: interface is %s.\n", info.interface);
79 hdc1080_interface_debug_print("hdc1080: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
80 hdc1080_interface_debug_print("hdc1080: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
81 hdc1080_interface_debug_print("hdc1080: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
82 hdc1080_interface_debug_print("hdc1080: max current is %0.2fmA.\n", info.max_current_ma);
83 hdc1080_interface_debug_print("hdc1080: max temperature is %0.1fC.\n", info.temperature_max);
84 hdc1080_interface_debug_print("hdc1080: min temperature is %0.1fC.\n", info.temperature_min);
85 }
86
87 /* start basic read test */
88 hdc1080_interface_debug_print("hdc1080: start read test.\n");
89
90 /* hdc1080 init */
91 res = hdc1080_init(&gs_handle);
92 if (res != 0)
93 {
94 hdc1080_interface_debug_print("hdc1080: init failed.\n");
95
96 return 1;
97 }
98
99 /* enable heater */
100 res = hdc1080_set_heater(&gs_handle, HDC1080_BOOL_TRUE);
101 if (res != 0)
102 {
103 hdc1080_interface_debug_print("hdc1080: set heater failed.\n");
104 (void)hdc1080_deinit(&gs_handle);
105
106 return 1;
107 }
108
109 /* temperature and humidity are acquired in sequence */
110 res = hdc1080_set_mode(&gs_handle, HDC1080_MODE_SEQUENCE);
111 if (res != 0)
112 {
113 hdc1080_interface_debug_print("hdc1080: set mode failed.\n");
114 (void)hdc1080_deinit(&gs_handle);
115
116 return 1;
117 }
118
119 /* 11 bit */
121 if (res != 0)
122 {
123 hdc1080_interface_debug_print("hdc1080: set temperature resolution failed.\n");
124 (void)hdc1080_deinit(&gs_handle);
125
126 return 1;
127 }
128
129 /* output */
130 hdc1080_interface_debug_print("hdc1080: set temperature resolution 11 bit.\n");
131
132 /* loop */
133 for (i = 0; i < times; i++)
134 {
135 uint16_t temperature_raw;
136 float temperature_s;
137 uint16_t humidity_raw;
138 float humidity_s;
139
140 /* delay 1000ms */
142
143 /* read temperature humidity */
144 res = hdc1080_read_temperature_humidity(&gs_handle, &temperature_raw, &temperature_s,
145 &humidity_raw, &humidity_s);
146 if (res != 0)
147 {
148 hdc1080_interface_debug_print("hdc1080: read temperature humidity failed.\n");
149 (void)hdc1080_deinit(&gs_handle);
150
151 return 1;
152 }
153
154 /* output */
155 hdc1080_interface_debug_print("hdc1080: temperature is %0.2fC, humidity is %0.2f%%.\n", temperature_s, humidity_s);
156 }
157
158 /* 14 bit */
160 if (res != 0)
161 {
162 hdc1080_interface_debug_print("hdc1080: set temperature resolution failed.\n");
163 (void)hdc1080_deinit(&gs_handle);
164
165 return 1;
166 }
167
168 /* output */
169 hdc1080_interface_debug_print("hdc1080: set temperature resolution 14 bit.\n");
170
171 /* loop */
172 for (i = 0; i < times; i++)
173 {
174 uint16_t temperature_raw;
175 float temperature_s;
176 uint16_t humidity_raw;
177 float humidity_s;
178
179 /* delay 1000ms */
181
182 /* read temperature humidity */
183 res = hdc1080_read_temperature_humidity(&gs_handle, &temperature_raw, &temperature_s,
184 &humidity_raw, &humidity_s);
185 if (res != 0)
186 {
187 hdc1080_interface_debug_print("hdc1080: read temperature humidity failed.\n");
188 (void)hdc1080_deinit(&gs_handle);
189
190 return 1;
191 }
192
193 /* output */
194 hdc1080_interface_debug_print("hdc1080: temperature is %0.2fC, humidity is %0.2f%%.\n", temperature_s, humidity_s);
195 }
196
197 /* 8 bit */
199 if (res != 0)
200 {
201 hdc1080_interface_debug_print("hdc1080: set humidity resolution failed.\n");
202 (void)hdc1080_deinit(&gs_handle);
203
204 return 1;
205 }
206
207 /* output */
208 hdc1080_interface_debug_print("hdc1080: set humidity resolution 8 bit.\n");
209
210 /* loop */
211 for (i = 0; i < times; i++)
212 {
213 uint16_t temperature_raw;
214 float temperature_s;
215 uint16_t humidity_raw;
216 float humidity_s;
217
218 /* delay 1000ms */
220
221 /* read temperature humidity */
222 res = hdc1080_read_temperature_humidity(&gs_handle, &temperature_raw, &temperature_s,
223 &humidity_raw, &humidity_s);
224 if (res != 0)
225 {
226 hdc1080_interface_debug_print("hdc1080: read temperature humidity failed.\n");
227 (void)hdc1080_deinit(&gs_handle);
228
229 return 1;
230 }
231
232 /* output */
233 hdc1080_interface_debug_print("hdc1080: temperature is %0.2fC, humidity is %0.2f%%.\n", temperature_s, humidity_s);
234 }
235
236 /* 11 bit */
238 if (res != 0)
239 {
240 hdc1080_interface_debug_print("hdc1080: set humidity resolution failed.\n");
241 (void)hdc1080_deinit(&gs_handle);
242
243 return 1;
244 }
245
246 /* output */
247 hdc1080_interface_debug_print("hdc1080: set humidity resolution 11 bit.\n");
248
249 /* loop */
250 for (i = 0; i < times; i++)
251 {
252 uint16_t temperature_raw;
253 float temperature_s;
254 uint16_t humidity_raw;
255 float humidity_s;
256
257 /* delay 1000ms */
259
260 /* read temperature humidity */
261 res = hdc1080_read_temperature_humidity(&gs_handle, &temperature_raw, &temperature_s,
262 &humidity_raw, &humidity_s);
263 if (res != 0)
264 {
265 hdc1080_interface_debug_print("hdc1080: read temperature humidity failed.\n");
266 (void)hdc1080_deinit(&gs_handle);
267
268 return 1;
269 }
270
271 /* output */
272 hdc1080_interface_debug_print("hdc1080: temperature is %0.2fC, humidity is %0.2f%%.\n", temperature_s, humidity_s);
273 }
274
275 /* 14 bit */
277 if (res != 0)
278 {
279 hdc1080_interface_debug_print("hdc1080: set humidity resolution failed.\n");
280 (void)hdc1080_deinit(&gs_handle);
281
282 return 1;
283 }
284
285 /* output */
286 hdc1080_interface_debug_print("hdc1080: set humidity resolution 14 bit.\n");
287
288 /* loop */
289 for (i = 0; i < times; i++)
290 {
291 uint16_t temperature_raw;
292 float temperature_s;
293 uint16_t humidity_raw;
294 float humidity_s;
295
296 /* delay 1000ms */
298
299 /* read temperature humidity */
300 res = hdc1080_read_temperature_humidity(&gs_handle, &temperature_raw, &temperature_s,
301 &humidity_raw, &humidity_s);
302 if (res != 0)
303 {
304 hdc1080_interface_debug_print("hdc1080: read temperature humidity failed.\n");
305 (void)hdc1080_deinit(&gs_handle);
306
307 return 1;
308 }
309
310 /* output */
311 hdc1080_interface_debug_print("hdc1080: temperature is %0.2fC, humidity is %0.2f%%.\n", temperature_s, humidity_s);
312 }
313
314 /* output */
315 hdc1080_interface_debug_print("hdc1080: hdc1080_read_temperature test.\n");
316
317 /* loop */
318 for (i = 0; i < times; i++)
319 {
320 uint16_t temperature_raw;
321 float temperature_s;
322
323 /* delay 1000ms */
325
326 /* read temperature humidity */
327 res = hdc1080_read_temperature(&gs_handle, &temperature_raw, &temperature_s);
328 if (res != 0)
329 {
330 hdc1080_interface_debug_print("hdc1080: read temperature failed.\n");
331 (void)hdc1080_deinit(&gs_handle);
332
333 return 1;
334 }
335
336 /* output */
337 hdc1080_interface_debug_print("hdc1080: temperature is %0.2fC.\n", temperature_s);
338 }
339
340 /* output */
341 hdc1080_interface_debug_print("hdc1080: hdc1080_read_humidity test.\n");
342
343 /* loop */
344 for (i = 0; i < times; i++)
345 {
346 uint16_t humidity_raw;
347 float humidity_s;
348
349 /* delay 1000ms */
351
352 /* read humidity */
353 res = hdc1080_read_humidity(&gs_handle, &humidity_raw, &humidity_s);
354 if (res != 0)
355 {
356 hdc1080_interface_debug_print("hdc1080: read humidity failed.\n");
357 (void)hdc1080_deinit(&gs_handle);
358
359 return 1;
360 }
361
362 /* output */
363 hdc1080_interface_debug_print("hdc1080: humidity is %0.2f%%.\n", humidity_s);
364 }
365
366 /* finish basic read test and exit */
367 hdc1080_interface_debug_print("hdc1080: finish read test.\n");
368 (void)hdc1080_deinit(&gs_handle);
369
370 return 0;
371}
driver hdc1080 read test header file
uint8_t hdc1080_info(hdc1080_info_t *info)
get chip's information
struct hdc1080_info_s hdc1080_info_t
hdc1080 information structure definition
uint8_t hdc1080_read_humidity(hdc1080_handle_t *handle, uint16_t *humidity_raw, float *humidity_s)
read the humidity data
struct hdc1080_handle_s hdc1080_handle_t
hdc1080 handle structure definition
uint8_t hdc1080_read_temperature_humidity(hdc1080_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read the temperature and humidity data
uint8_t hdc1080_deinit(hdc1080_handle_t *handle)
close the chip
uint8_t hdc1080_set_heater(hdc1080_handle_t *handle, hdc1080_bool_t enable)
enable or disable heater
uint8_t hdc1080_set_mode(hdc1080_handle_t *handle, hdc1080_mode_t mode)
set the chip mode
uint8_t hdc1080_set_humidity_resolution(hdc1080_handle_t *handle, hdc1080_humidity_resolution_t resolution)
set humidity resolution
uint8_t hdc1080_init(hdc1080_handle_t *handle)
initialize the chip
uint8_t hdc1080_read_temperature(hdc1080_handle_t *handle, uint16_t *temperature_raw, float *temperature_s)
read the temperature
uint8_t hdc1080_set_temperature_resolution(hdc1080_handle_t *handle, hdc1080_temperature_resolution_t resolution)
set temperature resolution
@ HDC1080_HUMIDITY_RESOLUTION_8_BIT
@ HDC1080_HUMIDITY_RESOLUTION_11_BIT
@ HDC1080_HUMIDITY_RESOLUTION_14_BIT
@ HDC1080_MODE_SEQUENCE
@ HDC1080_TEMPERATURE_RESOLUTION_14_BIT
@ HDC1080_TEMPERATURE_RESOLUTION_11_BIT
@ HDC1080_BOOL_TRUE
uint8_t hdc1080_interface_iic_read_with_wait(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read with wait
void hdc1080_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t hdc1080_interface_iic_deinit(void)
interface iic bus deinit
void hdc1080_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t hdc1080_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t hdc1080_interface_iic_init(void)
interface iic bus init
uint8_t hdc1080_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t hdc1080_read_test(uint32_t times)
read test
uint32_t driver_version
char manufacturer_name[32]