LibDriver INA219
Loading...
Searching...
No Matches
driver_ina219_register_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static ina219_handle_t gs_handle;
41
51{
52 uint8_t res;
53 double r, r_check;
54 uint16_t data, data_check;
55 ina219_info_t info;
58 ina219_pga_t pga;
60 ina219_mode_t chip_mode;
61
62 /* link interface function */
70
71 /* get information */
72 res = ina219_info(&info);
73 if (res != 0)
74 {
75 ina219_interface_debug_print("ina219: get info failed.\n");
76
77 return 1;
78 }
79 else
80 {
81 /* print chip info */
82 ina219_interface_debug_print("ina219: chip is %s.\n", info.chip_name);
83 ina219_interface_debug_print("ina219: manufacturer is %s.\n", info.manufacturer_name);
84 ina219_interface_debug_print("ina219: interface is %s.\n", info.interface);
85 ina219_interface_debug_print("ina219: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
86 ina219_interface_debug_print("ina219: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
87 ina219_interface_debug_print("ina219: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
88 ina219_interface_debug_print("ina219: max current is %0.2fmA.\n", info.max_current_ma);
89 ina219_interface_debug_print("ina219: max temperature is %0.1fC.\n", info.temperature_max);
90 ina219_interface_debug_print("ina219: min temperature is %0.1fC.\n", info.temperature_min);
91 }
92
93 /* start register test */
94 ina219_interface_debug_print("ina219: start register test.\n");
95
96 /* ina219_set_addr_pin/ina219_get_addr_pin test */
97 ina219_interface_debug_print("ina219: ina219_set_addr_pin/ina219_get_addr_pin test.\n");
98
99 /* set address 0 */
100 res = ina219_set_addr_pin(&gs_handle, INA219_ADDRESS_0);
101 if (res != 0)
102 {
103 ina219_interface_debug_print("ina219: set addr pin failed.\n");
104
105 return 1;
106 }
107 ina219_interface_debug_print("ina219: set addr pin 0.\n");
108 res = ina219_get_addr_pin(&gs_handle, &addr);
109 if (res != 0)
110 {
111 ina219_interface_debug_print("ina219: get addr pin failed.\n");
112
113 return 1;
114 }
115 ina219_interface_debug_print("ina219: check addr pin %s.\n", addr == INA219_ADDRESS_0 ? "ok" : "error");
116
117 /* set address 1 */
118 res = ina219_set_addr_pin(&gs_handle, INA219_ADDRESS_1);
119 if (res != 0)
120 {
121 ina219_interface_debug_print("ina219: set addr pin failed.\n");
122
123 return 1;
124 }
125 ina219_interface_debug_print("ina219: set addr pin 1.\n");
126 res = ina219_get_addr_pin(&gs_handle, &addr);
127 if (res != 0)
128 {
129 ina219_interface_debug_print("ina219: get addr pin failed.\n");
130
131 return 1;
132 }
133 ina219_interface_debug_print("ina219: check addr pin %s.\n", addr == INA219_ADDRESS_1 ? "ok" : "error");
134
135 /* set address 2 */
136 res = ina219_set_addr_pin(&gs_handle, INA219_ADDRESS_2);
137 if (res != 0)
138 {
139 ina219_interface_debug_print("ina219: set addr pin failed.\n");
140
141 return 1;
142 }
143 ina219_interface_debug_print("ina219: set addr pin 2.\n");
144 res = ina219_get_addr_pin(&gs_handle, &addr);
145 if (res != 0)
146 {
147 ina219_interface_debug_print("ina219: get addr pin failed.\n");
148
149 return 1;
150 }
151 ina219_interface_debug_print("ina219: check addr pin %s.\n", addr == INA219_ADDRESS_2 ? "ok" : "error");
152
153 /* set address 3 */
154 res = ina219_set_addr_pin(&gs_handle, INA219_ADDRESS_3);
155 if (res != 0)
156 {
157 ina219_interface_debug_print("ina219: set addr pin failed.\n");
158
159 return 1;
160 }
161 ina219_interface_debug_print("ina219: set addr pin 3.\n");
162 res = ina219_get_addr_pin(&gs_handle, &addr);
163 if (res != 0)
164 {
165 ina219_interface_debug_print("ina219: get addr pin failed.\n");
166
167 return 1;
168 }
169 ina219_interface_debug_print("ina219: check addr pin %s.\n", addr == INA219_ADDRESS_3 ? "ok" : "error");
170
171 /* set address 4 */
172 res = ina219_set_addr_pin(&gs_handle, INA219_ADDRESS_4);
173 if (res != 0)
174 {
175 ina219_interface_debug_print("ina219: set addr pin failed.\n");
176
177 return 1;
178 }
179 ina219_interface_debug_print("ina219: set addr pin 4.\n");
180 res = ina219_get_addr_pin(&gs_handle, &addr);
181 if (res != 0)
182 {
183 ina219_interface_debug_print("ina219: get addr pin failed.\n");
184
185 return 1;
186 }
187 ina219_interface_debug_print("ina219: check addr pin %s.\n", addr == INA219_ADDRESS_4 ? "ok" : "error");
188
189 /* set address 5 */
190 res = ina219_set_addr_pin(&gs_handle, INA219_ADDRESS_5);
191 if (res != 0)
192 {
193 ina219_interface_debug_print("ina219: set addr pin failed.\n");
194
195 return 1;
196 }
197 ina219_interface_debug_print("ina219: set addr pin 5.\n");
198 res = ina219_get_addr_pin(&gs_handle, &addr);
199 if (res != 0)
200 {
201 ina219_interface_debug_print("ina219: get addr pin failed.\n");
202
203 return 1;
204 }
205 ina219_interface_debug_print("ina219: check addr pin %s.\n", addr == INA219_ADDRESS_5 ? "ok" : "error");
206
207 /* set address 6 */
208 res = ina219_set_addr_pin(&gs_handle, INA219_ADDRESS_6);
209 if (res != 0)
210 {
211 ina219_interface_debug_print("ina219: set addr pin failed.\n");
212
213 return 1;
214 }
215 ina219_interface_debug_print("ina219: set addr pin 6.\n");
216 res = ina219_get_addr_pin(&gs_handle, &addr);
217 if (res != 0)
218 {
219 ina219_interface_debug_print("ina219: get addr pin failed.\n");
220
221 return 1;
222 }
223 ina219_interface_debug_print("ina219: check addr pin %s.\n", addr == INA219_ADDRESS_6 ? "ok" : "error");
224
225 /* set address 7 */
226 res = ina219_set_addr_pin(&gs_handle, INA219_ADDRESS_7);
227 if (res != 0)
228 {
229 ina219_interface_debug_print("ina219: set addr pin failed.\n");
230
231 return 1;
232 }
233 ina219_interface_debug_print("ina219: set addr pin 7.\n");
234 res = ina219_get_addr_pin(&gs_handle, &addr);
235 if (res != 0)
236 {
237 ina219_interface_debug_print("ina219: get addr pin failed.\n");
238
239 return 1;
240 }
241 ina219_interface_debug_print("ina219: check addr pin %s.\n", addr == INA219_ADDRESS_7 ? "ok" : "error");
242
243 /* set address 8 */
244 res = ina219_set_addr_pin(&gs_handle, INA219_ADDRESS_8);
245 if (res != 0)
246 {
247 ina219_interface_debug_print("ina219: set addr pin failed.\n");
248
249 return 1;
250 }
251 ina219_interface_debug_print("ina219: set addr pin 8.\n");
252 res = ina219_get_addr_pin(&gs_handle, &addr);
253 if (res != 0)
254 {
255 ina219_interface_debug_print("ina219: get addr pin failed.\n");
256
257 return 1;
258 }
259 ina219_interface_debug_print("ina219: check addr pin %s.\n", addr == INA219_ADDRESS_8 ? "ok" : "error");
260
261 /* set address 9 */
262 res = ina219_set_addr_pin(&gs_handle, INA219_ADDRESS_9);
263 if (res != 0)
264 {
265 ina219_interface_debug_print("ina219: set addr pin failed.\n");
266
267 return 1;
268 }
269 ina219_interface_debug_print("ina219: set addr pin 9.\n");
270 res = ina219_get_addr_pin(&gs_handle, &addr);
271 if (res != 0)
272 {
273 ina219_interface_debug_print("ina219: get addr pin failed.\n");
274
275 return 1;
276 }
277 ina219_interface_debug_print("ina219: check addr pin %s.\n", addr == INA219_ADDRESS_9 ? "ok" : "error");
278
279 /* set address 10 */
280 res = ina219_set_addr_pin(&gs_handle, INA219_ADDRESS_A);
281 if (res != 0)
282 {
283 ina219_interface_debug_print("ina219: set addr pin failed.\n");
284
285 return 1;
286 }
287 ina219_interface_debug_print("ina219: set addr pin 10.\n");
288 res = ina219_get_addr_pin(&gs_handle, &addr);
289 if (res != 0)
290 {
291 ina219_interface_debug_print("ina219: get addr pin failed.\n");
292
293 return 1;
294 }
295 ina219_interface_debug_print("ina219: check addr pin %s.\n", addr == INA219_ADDRESS_A ? "ok" : "error");
296
297 /* set address 11 */
298 res = ina219_set_addr_pin(&gs_handle, INA219_ADDRESS_B);
299 if (res != 0)
300 {
301 ina219_interface_debug_print("ina219: set addr pin failed.\n");
302
303 return 1;
304 }
305 ina219_interface_debug_print("ina219: set addr pin 11.\n");
306 res = ina219_get_addr_pin(&gs_handle, &addr);
307 if (res != 0)
308 {
309 ina219_interface_debug_print("ina219: get addr pin failed.\n");
310
311 return 1;
312 }
313 ina219_interface_debug_print("ina219: check addr pin %s.\n", addr == INA219_ADDRESS_B ? "ok" : "error");
314
315 /* set address 12 */
316 res = ina219_set_addr_pin(&gs_handle, INA219_ADDRESS_C);
317 if (res != 0)
318 {
319 ina219_interface_debug_print("ina219: set addr pin failed.\n");
320
321 return 1;
322 }
323 ina219_interface_debug_print("ina219: set addr pin 12.\n");
324 res = ina219_get_addr_pin(&gs_handle, &addr);
325 if (res != 0)
326 {
327 ina219_interface_debug_print("ina219: get addr pin failed.\n");
328
329 return 1;
330 }
331 ina219_interface_debug_print("ina219: check addr pin %s.\n", addr == INA219_ADDRESS_C ? "ok" : "error");
332
333 /* set address 13 */
334 res = ina219_set_addr_pin(&gs_handle, INA219_ADDRESS_D);
335 if (res != 0)
336 {
337 ina219_interface_debug_print("ina219: set addr pin failed.\n");
338
339 return 1;
340 }
341 ina219_interface_debug_print("ina219: set addr pin 13.\n");
342 res = ina219_get_addr_pin(&gs_handle, &addr);
343 if (res != 0)
344 {
345 ina219_interface_debug_print("ina219: get addr pin failed.\n");
346
347 return 1;
348 }
349 ina219_interface_debug_print("ina219: check addr pin %s.\n", addr == INA219_ADDRESS_D ? "ok" : "error");
350
351 /* set address 14 */
352 res = ina219_set_addr_pin(&gs_handle, INA219_ADDRESS_E);
353 if (res != 0)
354 {
355 ina219_interface_debug_print("ina219: set addr pin failed.\n");
356
357 return 1;
358 }
359 ina219_interface_debug_print("ina219: set addr pin 14.\n");
360 res = ina219_get_addr_pin(&gs_handle, &addr);
361 if (res != 0)
362 {
363 ina219_interface_debug_print("ina219: get addr pin failed.\n");
364
365 return 1;
366 }
367 ina219_interface_debug_print("ina219: check addr pin %s.\n", addr == INA219_ADDRESS_E ? "ok" : "error");
368
369 /* set address 15 */
370 res = ina219_set_addr_pin(&gs_handle, INA219_ADDRESS_F);
371 if (res != 0)
372 {
373 ina219_interface_debug_print("ina219: set addr pin failed.\n");
374
375 return 1;
376 }
377 ina219_interface_debug_print("ina219: set addr pin 15.\n");
378 res = ina219_get_addr_pin(&gs_handle, &addr);
379 if (res != 0)
380 {
381 ina219_interface_debug_print("ina219: get addr pin failed.\n");
382
383 return 1;
384 }
385 ina219_interface_debug_print("ina219: check addr pin %s.\n", addr == INA219_ADDRESS_F ? "ok" : "error");
386
387 /* ina219_set_resistance/ina219_get_resistance test */
388 ina219_interface_debug_print("ina219: ina219_set_resistance/ina219_get_resistance test.\n");
389
390 /* generate the r */
391 r = (double)(rand() % 100) / 1000.0;
392 res = ina219_set_resistance(&gs_handle, r);
393 if (res != 0)
394 {
395 ina219_interface_debug_print("ina219: set resistance failed.\n");
396
397 return 1;
398 }
399 ina219_interface_debug_print("ina219: set resistance %f.\n", r);
400 res = ina219_get_resistance(&gs_handle, (double *)&r_check);
401 if (res != 0)
402 {
403 ina219_interface_debug_print("ina219: get resistance failed.\n");
404
405 return 1;
406 }
407 ina219_interface_debug_print("ina219: check resistance %f.\n", r_check);
408
409 /* set addr pin */
410 res = ina219_set_addr_pin(&gs_handle, addr_pin);
411 if (res != 0)
412 {
413 ina219_interface_debug_print("ina219: set addr pin failed.\n");
414
415 return 1;
416 }
417
418 /* init */
419 res = ina219_init(&gs_handle);
420 if (res != 0)
421 {
422 ina219_interface_debug_print("ina219: init failed.\n");
423
424 return 1;
425 }
426
427 /* ina219_set_bus_voltage_range/ina219_get_bus_voltage_range test */
428 ina219_interface_debug_print("ina219: ina219_set_bus_voltage_range/ina219_get_bus_voltage_range test.\n");
429
430 /* set bus voltage range 16V */
432 if (res != 0)
433 {
434 ina219_interface_debug_print("ina219: set bus voltage range failed.\n");
435 (void)ina219_deinit(&gs_handle);
436
437 return 1;
438 }
439 ina219_interface_debug_print("ina219: set bus voltage range 16V.\n");
440 res = ina219_get_bus_voltage_range(&gs_handle, &range);
441 if (res != 0)
442 {
443 ina219_interface_debug_print("ina219: get bus voltage range failed.\n");
444 (void)ina219_deinit(&gs_handle);
445
446 return 1;
447 }
448 ina219_interface_debug_print("ina219: check bus voltage range %s.\n", range == INA219_BUS_VOLTAGE_RANGE_16V ? "ok" : "error");
449
450 /* set bus voltage range 32V */
452 if (res != 0)
453 {
454 ina219_interface_debug_print("ina219: set bus voltage range failed.\n");
455 (void)ina219_deinit(&gs_handle);
456
457 return 1;
458 }
459 ina219_interface_debug_print("ina219: set bus voltage range 32V.\n");
460 res = ina219_get_bus_voltage_range(&gs_handle, &range);
461 if (res != 0)
462 {
463 ina219_interface_debug_print("ina219: get bus voltage range failed.\n");
464 (void)ina219_deinit(&gs_handle);
465
466 return 1;
467 }
468 ina219_interface_debug_print("ina219: check bus voltage range %s.\n", range == INA219_BUS_VOLTAGE_RANGE_32V ? "ok" : "error");
469
470 /* ina219_set_pga/ina219_get_pga test */
471 ina219_interface_debug_print("ina219: ina219_set_pga/ina219_get_pga test.\n");
472
473 /* set 40 mV */
474 res = ina219_set_pga(&gs_handle, INA219_PGA_40_MV);
475 if (res != 0)
476 {
477 ina219_interface_debug_print("ina219: set pga failed.\n");
478 (void)ina219_deinit(&gs_handle);
479
480 return 1;
481 }
482 ina219_interface_debug_print("ina219: set pga 40 mV.\n");
483 res = ina219_get_pga(&gs_handle, &pga);
484 if (res != 0)
485 {
486 ina219_interface_debug_print("ina219: get pga failed.\n");
487 (void)ina219_deinit(&gs_handle);
488
489 return 1;
490 }
491 ina219_interface_debug_print("ina219: check pga %s.\n", pga == INA219_PGA_40_MV ? "ok" : "error");
492
493 /* set 80 mV */
494 res = ina219_set_pga(&gs_handle, INA219_PGA_80_MV);
495 if (res != 0)
496 {
497 ina219_interface_debug_print("ina219: set pga failed.\n");
498 (void)ina219_deinit(&gs_handle);
499
500 return 1;
501 }
502 ina219_interface_debug_print("ina219: set pga 80 mV.\n");
503 res = ina219_get_pga(&gs_handle, &pga);
504 if (res != 0)
505 {
506 ina219_interface_debug_print("ina219: get pga failed.\n");
507 (void)ina219_deinit(&gs_handle);
508
509 return 1;
510 }
511 ina219_interface_debug_print("ina219: check pga %s.\n", pga == INA219_PGA_80_MV ? "ok" : "error");
512
513 /* set 160 mV */
514 res = ina219_set_pga(&gs_handle, INA219_PGA_160_MV);
515 if (res != 0)
516 {
517 ina219_interface_debug_print("ina219: set pga failed.\n");
518 (void)ina219_deinit(&gs_handle);
519
520 return 1;
521 }
522 ina219_interface_debug_print("ina219: set pga 160 mV.\n");
523 res = ina219_get_pga(&gs_handle, &pga);
524 if (res != 0)
525 {
526 ina219_interface_debug_print("ina219: get pga failed.\n");
527 (void)ina219_deinit(&gs_handle);
528
529 return 1;
530 }
531 ina219_interface_debug_print("ina219: check pga %s.\n", pga == INA219_PGA_160_MV ? "ok" : "error");
532
533 /* set 320 mV */
534 res = ina219_set_pga(&gs_handle, INA219_PGA_320_MV);
535 if (res != 0)
536 {
537 ina219_interface_debug_print("ina219: set pga failed.\n");
538 (void)ina219_deinit(&gs_handle);
539
540 return 1;
541 }
542 ina219_interface_debug_print("ina219: set pga 320 mV.\n");
543 res = ina219_get_pga(&gs_handle, &pga);
544 if (res != 0)
545 {
546 ina219_interface_debug_print("ina219: get pga failed.\n");
547 (void)ina219_deinit(&gs_handle);
548
549 return 1;
550 }
551 ina219_interface_debug_print("ina219: check pga %s.\n", pga == INA219_PGA_320_MV ? "ok" : "error");
552
553 /* ina219_set_bus_voltage_adc_mode/ina219_get_bus_voltage_adc_mode test */
554 ina219_interface_debug_print("ina219: ina219_set_bus_voltage_adc_mode/ina219_get_bus_voltage_adc_mode test.\n");
555
556 /* 9 bit 1 sample */
558 if (res != 0)
559 {
560 ina219_interface_debug_print("ina219: set bus voltage adc mode failed.\n");
561 (void)ina219_deinit(&gs_handle);
562
563 return 1;
564 }
565 ina219_interface_debug_print("ina219: set bus voltage adc mode 9 bit 1 sample.\n");
566 res = ina219_get_bus_voltage_adc_mode(&gs_handle, &mode);
567 if (res != 0)
568 {
569 ina219_interface_debug_print("ina219: get bus voltage adc mode failed.\n");
570 (void)ina219_deinit(&gs_handle);
571
572 return 1;
573 }
574 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_9_BIT_1_SAMPLES ? "ok" : "error");
575
576 /* 10 bit 1 sample */
578 if (res != 0)
579 {
580 ina219_interface_debug_print("ina219: set bus voltage adc mode failed.\n");
581 (void)ina219_deinit(&gs_handle);
582
583 return 1;
584 }
585 ina219_interface_debug_print("ina219: set bus voltage adc mode 10 bit 1 sample.\n");
586 res = ina219_get_bus_voltage_adc_mode(&gs_handle, &mode);
587 if (res != 0)
588 {
589 ina219_interface_debug_print("ina219: get bus voltage adc mode failed.\n");
590 (void)ina219_deinit(&gs_handle);
591
592 return 1;
593 }
594 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_10_BIT_1_SAMPLES ? "ok" : "error");
595
596 /* 11 bit 1 sample */
598 if (res != 0)
599 {
600 ina219_interface_debug_print("ina219: set bus voltage adc mode failed.\n");
601 (void)ina219_deinit(&gs_handle);
602
603 return 1;
604 }
605 ina219_interface_debug_print("ina219: set bus voltage adc mode 11 bit 1 sample.\n");
606 res = ina219_get_bus_voltage_adc_mode(&gs_handle, &mode);
607 if (res != 0)
608 {
609 ina219_interface_debug_print("ina219: get bus voltage adc mode failed.\n");
610 (void)ina219_deinit(&gs_handle);
611
612 return 1;
613 }
614 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_11_BIT_1_SAMPLES ? "ok" : "error");
615
616 /* 12 bit 1 sample */
618 if (res != 0)
619 {
620 ina219_interface_debug_print("ina219: set bus voltage adc mode failed.\n");
621 (void)ina219_deinit(&gs_handle);
622
623 return 1;
624 }
625 ina219_interface_debug_print("ina219: set bus voltage adc mode 12 bit 1 sample.\n");
626 res = ina219_get_bus_voltage_adc_mode(&gs_handle, &mode);
627 if (res != 0)
628 {
629 ina219_interface_debug_print("ina219: get bus voltage adc mode failed.\n");
630 (void)ina219_deinit(&gs_handle);
631
632 return 1;
633 }
634 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_12_BIT_1_SAMPLES ? "ok" : "error");
635
636 /* 12 bit 2 sample */
638 if (res != 0)
639 {
640 ina219_interface_debug_print("ina219: set bus voltage adc mode failed.\n");
641 (void)ina219_deinit(&gs_handle);
642
643 return 1;
644 }
645 ina219_interface_debug_print("ina219: set bus voltage adc mode 12 bit 2 sample.\n");
646 res = ina219_get_bus_voltage_adc_mode(&gs_handle, &mode);
647 if (res != 0)
648 {
649 ina219_interface_debug_print("ina219: get bus voltage adc mode failed.\n");
650 (void)ina219_deinit(&gs_handle);
651
652 return 1;
653 }
654 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_12_BIT_2_SAMPLES ? "ok" : "error");
655
656 /* 12 bit 4 sample */
658 if (res != 0)
659 {
660 ina219_interface_debug_print("ina219: set bus voltage adc mode failed.\n");
661 (void)ina219_deinit(&gs_handle);
662
663 return 1;
664 }
665 ina219_interface_debug_print("ina219: set bus voltage adc mode 12 bit 4 sample.\n");
666 res = ina219_get_bus_voltage_adc_mode(&gs_handle, &mode);
667 if (res != 0)
668 {
669 ina219_interface_debug_print("ina219: get bus voltage adc mode failed.\n");
670 (void)ina219_deinit(&gs_handle);
671
672 return 1;
673 }
674 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_12_BIT_4_SAMPLES ? "ok" : "error");
675
676 /* 12 bit 8 sample */
678 if (res != 0)
679 {
680 ina219_interface_debug_print("ina219: set bus voltage adc mode failed.\n");
681 (void)ina219_deinit(&gs_handle);
682
683 return 1;
684 }
685 ina219_interface_debug_print("ina219: set bus voltage adc mode 12 bit 8 sample.\n");
686 res = ina219_get_bus_voltage_adc_mode(&gs_handle, &mode);
687 if (res != 0)
688 {
689 ina219_interface_debug_print("ina219: get bus voltage adc mode failed.\n");
690 (void)ina219_deinit(&gs_handle);
691
692 return 1;
693 }
694 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_12_BIT_8_SAMPLES ? "ok" : "error");
695
696 /* 12 bit 16 sample */
698 if (res != 0)
699 {
700 ina219_interface_debug_print("ina219: set bus voltage adc mode failed.\n");
701 (void)ina219_deinit(&gs_handle);
702
703 return 1;
704 }
705 ina219_interface_debug_print("ina219: set bus voltage adc mode 12 bit 16 sample.\n");
706 res = ina219_get_bus_voltage_adc_mode(&gs_handle, &mode);
707 if (res != 0)
708 {
709 ina219_interface_debug_print("ina219: get bus voltage adc mode failed.\n");
710 (void)ina219_deinit(&gs_handle);
711
712 return 1;
713 }
714 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_12_BIT_16_SAMPLES ? "ok" : "error");
715
716 /* 12 bit 32 sample */
718 if (res != 0)
719 {
720 ina219_interface_debug_print("ina219: set bus voltage adc mode failed.\n");
721 (void)ina219_deinit(&gs_handle);
722
723 return 1;
724 }
725 ina219_interface_debug_print("ina219: set bus voltage adc mode 12 bit 32 sample.\n");
726 res = ina219_get_bus_voltage_adc_mode(&gs_handle, &mode);
727 if (res != 0)
728 {
729 ina219_interface_debug_print("ina219: get bus voltage adc mode failed.\n");
730 (void)ina219_deinit(&gs_handle);
731
732 return 1;
733 }
734 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_12_BIT_32_SAMPLES ? "ok" : "error");
735
736 /* 12 bit 64 sample */
738 if (res != 0)
739 {
740 ina219_interface_debug_print("ina219: set bus voltage adc mode failed.\n");
741 (void)ina219_deinit(&gs_handle);
742
743 return 1;
744 }
745 ina219_interface_debug_print("ina219: set bus voltage adc mode 12 bit 64 sample.\n");
746 res = ina219_get_bus_voltage_adc_mode(&gs_handle, &mode);
747 if (res != 0)
748 {
749 ina219_interface_debug_print("ina219: get bus voltage adc mode failed.\n");
750 (void)ina219_deinit(&gs_handle);
751
752 return 1;
753 }
754 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_12_BIT_64_SAMPLES ? "ok" : "error");
755
756 /* 12 bit 128 sample */
758 if (res != 0)
759 {
760 ina219_interface_debug_print("ina219: set bus voltage adc mode failed.\n");
761 (void)ina219_deinit(&gs_handle);
762
763 return 1;
764 }
765 ina219_interface_debug_print("ina219: set bus voltage adc mode 12 bit 128 sample.\n");
766 res = ina219_get_bus_voltage_adc_mode(&gs_handle, &mode);
767 if (res != 0)
768 {
769 ina219_interface_debug_print("ina219: get bus voltage adc mode failed.\n");
770 (void)ina219_deinit(&gs_handle);
771
772 return 1;
773 }
774 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_12_BIT_128_SAMPLES ? "ok" : "error");
775
776 /* ina219_set_shunt_voltage_adc_mode/ina219_get_shunt_voltage_adc_mode test */
777 ina219_interface_debug_print("ina219: ina219_set_shunt_voltage_adc_mode/ina219_get_shunt_voltage_adc_mode test.\n");
778
779 /* 9 bit 1 sample */
781 if (res != 0)
782 {
783 ina219_interface_debug_print("ina219: set shunt voltage adc mode failed.\n");
784 (void)ina219_deinit(&gs_handle);
785
786 return 1;
787 }
788 ina219_interface_debug_print("ina219: set shunt voltage adc mode 9 bit 1 sample.\n");
789 res = ina219_get_shunt_voltage_adc_mode(&gs_handle, &mode);
790 if (res != 0)
791 {
792 ina219_interface_debug_print("ina219: get shunt voltage adc mode failed.\n");
793 (void)ina219_deinit(&gs_handle);
794
795 return 1;
796 }
797 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_9_BIT_1_SAMPLES ? "ok" : "error");
798
799 /* 10 bit 1 sample */
801 if (res != 0)
802 {
803 ina219_interface_debug_print("ina219: set shunt voltage adc mode failed.\n");
804 (void)ina219_deinit(&gs_handle);
805
806 return 1;
807 }
808 ina219_interface_debug_print("ina219: set shunt voltage adc mode 10 bit 1 sample.\n");
809 res = ina219_get_shunt_voltage_adc_mode(&gs_handle, &mode);
810 if (res != 0)
811 {
812 ina219_interface_debug_print("ina219: get shunt voltage adc mode failed.\n");
813 (void)ina219_deinit(&gs_handle);
814
815 return 1;
816 }
817 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_10_BIT_1_SAMPLES ? "ok" : "error");
818
819 /* 11 bit 1 sample */
821 if (res != 0)
822 {
823 ina219_interface_debug_print("ina219: set shunt voltage adc mode failed.\n");
824 (void)ina219_deinit(&gs_handle);
825
826 return 1;
827 }
828 ina219_interface_debug_print("ina219: set shunt voltage adc mode 11 bit 1 sample.\n");
829 res = ina219_get_shunt_voltage_adc_mode(&gs_handle, &mode);
830 if (res != 0)
831 {
832 ina219_interface_debug_print("ina219: get shunt voltage adc mode failed.\n");
833 (void)ina219_deinit(&gs_handle);
834
835 return 1;
836 }
837 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_11_BIT_1_SAMPLES ? "ok" : "error");
838
839 /* 12 bit 1 sample */
841 if (res != 0)
842 {
843 ina219_interface_debug_print("ina219: set shunt voltage adc mode failed.\n");
844 (void)ina219_deinit(&gs_handle);
845
846 return 1;
847 }
848 ina219_interface_debug_print("ina219: set shunt voltage adc mode 12 bit 1 sample.\n");
849 res = ina219_get_shunt_voltage_adc_mode(&gs_handle, &mode);
850 if (res != 0)
851 {
852 ina219_interface_debug_print("ina219: get shunt voltage adc mode failed.\n");
853 (void)ina219_deinit(&gs_handle);
854
855 return 1;
856 }
857 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_12_BIT_1_SAMPLES ? "ok" : "error");
858
859 /* 12 bit 2 sample */
861 if (res != 0)
862 {
863 ina219_interface_debug_print("ina219: set shunt voltage adc mode failed.\n");
864 (void)ina219_deinit(&gs_handle);
865
866 return 1;
867 }
868 ina219_interface_debug_print("ina219: set shunt voltage adc mode 12 bit 2 sample.\n");
869 res = ina219_get_shunt_voltage_adc_mode(&gs_handle, &mode);
870 if (res != 0)
871 {
872 ina219_interface_debug_print("ina219: get shunt voltage adc mode failed.\n");
873 (void)ina219_deinit(&gs_handle);
874
875 return 1;
876 }
877 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_12_BIT_2_SAMPLES ? "ok" : "error");
878
879 /* 12 bit 4 sample */
881 if (res != 0)
882 {
883 ina219_interface_debug_print("ina219: set shunt voltage adc mode failed.\n");
884 (void)ina219_deinit(&gs_handle);
885
886 return 1;
887 }
888 ina219_interface_debug_print("ina219: set shunt voltage adc mode 12 bit 4 sample.\n");
889 res = ina219_get_shunt_voltage_adc_mode(&gs_handle, &mode);
890 if (res != 0)
891 {
892 ina219_interface_debug_print("ina219: get shunt voltage adc mode failed.\n");
893 (void)ina219_deinit(&gs_handle);
894
895 return 1;
896 }
897 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_12_BIT_4_SAMPLES ? "ok" : "error");
898
899 /* 12 bit 8 sample */
901 if (res != 0)
902 {
903 ina219_interface_debug_print("ina219: set shunt voltage adc mode failed.\n");
904 (void)ina219_deinit(&gs_handle);
905
906 return 1;
907 }
908 ina219_interface_debug_print("ina219: set shunt voltage adc mode 12 bit 8 sample.\n");
909 res = ina219_get_shunt_voltage_adc_mode(&gs_handle, &mode);
910 if (res != 0)
911 {
912 ina219_interface_debug_print("ina219: get shunt voltage adc mode failed.\n");
913 (void)ina219_deinit(&gs_handle);
914
915 return 1;
916 }
917 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_12_BIT_8_SAMPLES ? "ok" : "error");
918
919 /* 12 bit 16 sample */
921 if (res != 0)
922 {
923 ina219_interface_debug_print("ina219: set shunt voltage adc mode failed.\n");
924 (void)ina219_deinit(&gs_handle);
925
926 return 1;
927 }
928 ina219_interface_debug_print("ina219: set shunt voltage adc mode 12 bit 16 sample.\n");
929 res = ina219_get_shunt_voltage_adc_mode(&gs_handle, &mode);
930 if (res != 0)
931 {
932 ina219_interface_debug_print("ina219: get shunt voltage adc mode failed.\n");
933 (void)ina219_deinit(&gs_handle);
934
935 return 1;
936 }
937 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_12_BIT_16_SAMPLES ? "ok" : "error");
938
939 /* 12 bit 32 sample */
941 if (res != 0)
942 {
943 ina219_interface_debug_print("ina219: set shunt voltage adc mode failed.\n");
944 (void)ina219_deinit(&gs_handle);
945
946 return 1;
947 }
948 ina219_interface_debug_print("ina219: set shunt voltage adc mode 12 bit 32 sample.\n");
949 res = ina219_get_shunt_voltage_adc_mode(&gs_handle, &mode);
950 if (res != 0)
951 {
952 ina219_interface_debug_print("ina219: get shunt voltage adc mode failed.\n");
953 (void)ina219_deinit(&gs_handle);
954
955 return 1;
956 }
957 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_12_BIT_32_SAMPLES ? "ok" : "error");
958
959 /* 12 bit 64 sample */
961 if (res != 0)
962 {
963 ina219_interface_debug_print("ina219: set shunt voltage adc mode failed.\n");
964 (void)ina219_deinit(&gs_handle);
965
966 return 1;
967 }
968 ina219_interface_debug_print("ina219: set shunt voltage adc mode 12 bit 64 sample.\n");
969 res = ina219_get_shunt_voltage_adc_mode(&gs_handle, &mode);
970 if (res != 0)
971 {
972 ina219_interface_debug_print("ina219: get shunt voltage adc mode failed.\n");
973 (void)ina219_deinit(&gs_handle);
974
975 return 1;
976 }
977 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_12_BIT_64_SAMPLES ? "ok" : "error");
978
979 /* 12 bit 128 sample */
981 if (res != 0)
982 {
983 ina219_interface_debug_print("ina219: set shunt voltage adc mode failed.\n");
984 (void)ina219_deinit(&gs_handle);
985
986 return 1;
987 }
988 ina219_interface_debug_print("ina219: set shunt voltage adc mode 12 bit 128 sample.\n");
989 res = ina219_get_shunt_voltage_adc_mode(&gs_handle, &mode);
990 if (res != 0)
991 {
992 ina219_interface_debug_print("ina219: get shunt voltage adc mode failed.\n");
993 (void)ina219_deinit(&gs_handle);
994
995 return 1;
996 }
997 ina219_interface_debug_print("ina219: check adc mode %s.\n", mode == INA219_ADC_MODE_12_BIT_128_SAMPLES ? "ok" : "error");
998
999 /* ina219_set_mode/ina219_get_mode test */
1000 ina219_interface_debug_print("ina219: ina219_set_mode/ina219_get_mode test.\n");
1001
1002 /* set power down */
1003 res = ina219_set_mode(&gs_handle, INA219_MODE_POWER_DOWN);
1004 if (res != 0)
1005 {
1006 ina219_interface_debug_print("ina219: set mode failed.\n");
1007 (void)ina219_deinit(&gs_handle);
1008
1009 return 1;
1010 }
1011 ina219_interface_debug_print("ina219: set power down mode.\n");
1012 res = ina219_get_mode(&gs_handle, &chip_mode);
1013 if (res != 0)
1014 {
1015 ina219_interface_debug_print("ina219: get mode failed.\n");
1016 (void)ina219_deinit(&gs_handle);
1017
1018 return 1;
1019 }
1020 ina219_interface_debug_print("ina219: check chip mode %s.\n", chip_mode == INA219_MODE_POWER_DOWN ? "ok" : "error");
1021
1022 /* set adc off */
1023 res = ina219_set_mode(&gs_handle, INA219_MODE_ADC_OFF);
1024 if (res != 0)
1025 {
1026 ina219_interface_debug_print("ina219: set mode failed.\n");
1027 (void)ina219_deinit(&gs_handle);
1028
1029 return 1;
1030 }
1031 ina219_interface_debug_print("ina219: set adc off mode.\n");
1032 res = ina219_get_mode(&gs_handle, &chip_mode);
1033 if (res != 0)
1034 {
1035 ina219_interface_debug_print("ina219: get mode failed.\n");
1036 (void)ina219_deinit(&gs_handle);
1037
1038 return 1;
1039 }
1040 ina219_interface_debug_print("ina219: check chip mode %s.\n", chip_mode == INA219_MODE_ADC_OFF ? "ok" : "error");
1041
1042 /* set shunt voltage continuous */
1044 if (res != 0)
1045 {
1046 ina219_interface_debug_print("ina219: set mode failed.\n");
1047 (void)ina219_deinit(&gs_handle);
1048
1049 return 1;
1050 }
1051 ina219_interface_debug_print("ina219: set shunt voltage continuous mode.\n");
1052 res = ina219_get_mode(&gs_handle, &chip_mode);
1053 if (res != 0)
1054 {
1055 ina219_interface_debug_print("ina219: get mode failed.\n");
1056 (void)ina219_deinit(&gs_handle);
1057
1058 return 1;
1059 }
1060 ina219_interface_debug_print("ina219: check chip mode %s.\n", chip_mode == INA219_MODE_SHUNT_VOLTAGE_CONTINUOUS ? "ok" : "error");
1061
1062 /* set bus voltage continuous */
1064 if (res != 0)
1065 {
1066 ina219_interface_debug_print("ina219: set mode failed.\n");
1067 (void)ina219_deinit(&gs_handle);
1068
1069 return 1;
1070 }
1071 ina219_interface_debug_print("ina219: set bus voltage continuous mode.\n");
1072 res = ina219_get_mode(&gs_handle, &chip_mode);
1073 if (res != 0)
1074 {
1075 ina219_interface_debug_print("ina219: get mode failed.\n");
1076 (void)ina219_deinit(&gs_handle);
1077
1078 return 1;
1079 }
1080 ina219_interface_debug_print("ina219: check chip mode %s.\n", chip_mode == INA219_MODE_BUS_VOLTAGE_CONTINUOUS ? "ok" : "error");
1081
1082 /* set shunt bus voltage continuous */
1084 if (res != 0)
1085 {
1086 ina219_interface_debug_print("ina219: set mode failed.\n");
1087 (void)ina219_deinit(&gs_handle);
1088
1089 return 1;
1090 }
1091 ina219_interface_debug_print("ina219: set shunt bus voltage continuous mode.\n");
1092 res = ina219_get_mode(&gs_handle, &chip_mode);
1093 if (res != 0)
1094 {
1095 ina219_interface_debug_print("ina219: get mode failed.\n");
1096 (void)ina219_deinit(&gs_handle);
1097
1098 return 1;
1099 }
1100 ina219_interface_debug_print("ina219: check chip mode %s.\n", chip_mode == INA219_MODE_SHUNT_BUS_VOLTAGE_CONTINUOUS ? "ok" : "error");
1101
1102 /* set shunt voltage triggered */
1104 if (res != 0)
1105 {
1106 ina219_interface_debug_print("ina219: set mode failed.\n");
1107 (void)ina219_deinit(&gs_handle);
1108
1109 return 1;
1110 }
1111 ina219_interface_debug_print("ina219: set shunt voltage triggered mode.\n");
1112 res = ina219_get_mode(&gs_handle, &chip_mode);
1113 if (res != 0)
1114 {
1115 ina219_interface_debug_print("ina219: get mode failed.\n");
1116 (void)ina219_deinit(&gs_handle);
1117
1118 return 1;
1119 }
1120 ina219_interface_debug_print("ina219: check chip mode %s.\n", chip_mode == INA219_MODE_SHUNT_VOLTAGE_TRIGGERED ? "ok" : "error");
1121
1122 /* set bus voltage triggered */
1124 if (res != 0)
1125 {
1126 ina219_interface_debug_print("ina219: set mode failed.\n");
1127 (void)ina219_deinit(&gs_handle);
1128
1129 return 1;
1130 }
1131 ina219_interface_debug_print("ina219: set bus voltage triggered mode.\n");
1132 res = ina219_get_mode(&gs_handle, &chip_mode);
1133 if (res != 0)
1134 {
1135 ina219_interface_debug_print("ina219: get mode failed.\n");
1136 (void)ina219_deinit(&gs_handle);
1137
1138 return 1;
1139 }
1140 ina219_interface_debug_print("ina219: check chip mode %s.\n", chip_mode == INA219_MODE_BUS_VOLTAGE_TRIGGERED ? "ok" : "error");
1141
1142 /* set shunt bus voltage triggered */
1144 if (res != 0)
1145 {
1146 ina219_interface_debug_print("ina219: set mode failed.\n");
1147 (void)ina219_deinit(&gs_handle);
1148
1149 return 1;
1150 }
1151 ina219_interface_debug_print("ina219: set shunt bus voltage triggered mode.\n");
1152 res = ina219_get_mode(&gs_handle, &chip_mode);
1153 if (res != 0)
1154 {
1155 ina219_interface_debug_print("ina219: get mode failed.\n");
1156 (void)ina219_deinit(&gs_handle);
1157
1158 return 1;
1159 }
1160 ina219_interface_debug_print("ina219: check chip mode %s.\n", chip_mode == INA219_MODE_SHUNT_BUS_VOLTAGE_TRIGGERED ? "ok" : "error");
1161
1162 /* ina219_calculate_calibration test */
1163 ina219_interface_debug_print("ina219: ina219_calculate_calibration test.\n");
1164
1165 /* set pga 40 mV */
1166 res = ina219_set_pga(&gs_handle, INA219_PGA_40_MV);
1167 if (res != 0)
1168 {
1169 ina219_interface_debug_print("ina219: set pga failed.\n");
1170 (void)ina219_deinit(&gs_handle);
1171
1172 return 1;
1173 }
1174 ina219_interface_debug_print("ina219: set pga 40 mV.\n");
1175 res = ina219_calculate_calibration(&gs_handle, (uint16_t *)&data_check);
1176 if (res != 0)
1177 {
1178 ina219_interface_debug_print("ina219: calculate calibration failed.\n");
1179 (void)ina219_deinit(&gs_handle);
1180
1181 return 1;
1182 }
1183 ina219_interface_debug_print("ina219: calculate calibration %d.\n", data_check);
1184
1185 /* set pga 80 mV */
1186 res = ina219_set_pga(&gs_handle, INA219_PGA_80_MV);
1187 if (res != 0)
1188 {
1189 ina219_interface_debug_print("ina219: set pga failed.\n");
1190 (void)ina219_deinit(&gs_handle);
1191
1192 return 1;
1193 }
1194 ina219_interface_debug_print("ina219: set pga 80 mV.\n");
1195 res = ina219_calculate_calibration(&gs_handle, (uint16_t *)&data_check);
1196 if (res != 0)
1197 {
1198 ina219_interface_debug_print("ina219: calculate calibration failed.\n");
1199 (void)ina219_deinit(&gs_handle);
1200
1201 return 1;
1202 }
1203 ina219_interface_debug_print("ina219: calculate calibration %d.\n", data_check);
1204
1205 /* set pga 160 mV */
1206 res = ina219_set_pga(&gs_handle, INA219_PGA_160_MV);
1207 if (res != 0)
1208 {
1209 ina219_interface_debug_print("ina219: set pga failed.\n");
1210 (void)ina219_deinit(&gs_handle);
1211
1212 return 1;
1213 }
1214 ina219_interface_debug_print("ina219: set pga 160 mV.\n");
1215 res = ina219_calculate_calibration(&gs_handle, (uint16_t *)&data_check);
1216 if (res != 0)
1217 {
1218 ina219_interface_debug_print("ina219: calculate calibration failed.\n");
1219 (void)ina219_deinit(&gs_handle);
1220
1221 return 1;
1222 }
1223 ina219_interface_debug_print("ina219: calculate calibration %d.\n", data_check);
1224
1225 /* set pga 320 mV */
1226 res = ina219_set_pga(&gs_handle, INA219_PGA_320_MV);
1227 if (res != 0)
1228 {
1229 ina219_interface_debug_print("ina219: set pga failed.\n");
1230 (void)ina219_deinit(&gs_handle);
1231
1232 return 1;
1233 }
1234 ina219_interface_debug_print("ina219: set pga 320 mV.\n");
1235 res = ina219_calculate_calibration(&gs_handle, (uint16_t *)&data_check);
1236 if (res != 0)
1237 {
1238 ina219_interface_debug_print("ina219: calculate calibration failed.\n");
1239 (void)ina219_deinit(&gs_handle);
1240
1241 return 1;
1242 }
1243 ina219_interface_debug_print("ina219: calculate calibration %d.\n", data_check);
1244
1245 /* ina219_set_calibration/ina219_get_calibration test */
1246 ina219_interface_debug_print("ina219: ina219_set_calibration/ina219_get_calibration test.\n");
1247
1248 data = rand() % 65536;
1249 res = ina219_set_calibration(&gs_handle, data);
1250 if (res != 0)
1251 {
1252 ina219_interface_debug_print("ina219: set calibration failed.\n");
1253 (void)ina219_deinit(&gs_handle);
1254
1255 return 1;
1256 }
1257 ina219_interface_debug_print("ina219: set calibration %d.\n", data);
1258 res = ina219_get_calibration(&gs_handle, (uint16_t *)&data_check);
1259 if (res != 0)
1260 {
1261 ina219_interface_debug_print("ina219: get calibration failed.\n");
1262 (void)ina219_deinit(&gs_handle);
1263
1264 return 1;
1265 }
1266 ina219_interface_debug_print("ina219: check calibration %s.\n", data == data_check ? "ok" : "error");
1267
1268 /* ina219_soft_reset test */
1269 ina219_interface_debug_print("ina219: ina219_soft_reset test.\n");
1270
1271 res = ina219_soft_reset(&gs_handle);
1272 if (res != 0)
1273 {
1274 ina219_interface_debug_print("ina219: soft reset failed.\n");
1275 (void)ina219_deinit(&gs_handle);
1276
1277 return 1;
1278 }
1279
1280 /* finish register test */
1281 (void)ina219_deinit(&gs_handle);
1282 ina219_interface_debug_print("ina219: finish register test.\n");
1283
1284 return 0;
1285}
uint8_t ina219_get_pga(ina219_handle_t *handle, ina219_pga_t *pga)
get the pga
uint8_t ina219_get_resistance(ina219_handle_t *handle, double *resistance)
get the resistance
uint8_t ina219_get_bus_voltage_range(ina219_handle_t *handle, ina219_bus_voltage_range_t *range)
get the bus voltage range
uint8_t ina219_soft_reset(ina219_handle_t *handle)
soft reset the chip
struct ina219_info_s ina219_info_t
ina219 information structure definition
uint8_t ina219_set_addr_pin(ina219_handle_t *handle, ina219_address_t addr_pin)
set the iic address pin
uint8_t ina219_info(ina219_info_t *info)
get chip's information
uint8_t ina219_set_shunt_voltage_adc_mode(ina219_handle_t *handle, ina219_adc_mode_t mode)
set the shunt voltage adc mode
uint8_t ina219_get_mode(ina219_handle_t *handle, ina219_mode_t *mode)
get the mode
uint8_t ina219_get_bus_voltage_adc_mode(ina219_handle_t *handle, ina219_adc_mode_t *mode)
get the bus voltage adc mode
ina219_adc_mode_t
ina219 adc mode enumeration definition
ina219_pga_t
ina219 pga enumeration definition
uint8_t ina219_get_shunt_voltage_adc_mode(ina219_handle_t *handle, ina219_adc_mode_t *mode)
get the shunt voltage adc mode
uint8_t ina219_get_addr_pin(ina219_handle_t *handle, ina219_address_t *addr_pin)
get the iic address pin
uint8_t ina219_set_calibration(ina219_handle_t *handle, uint16_t data)
set the calibration
ina219_bus_voltage_range_t
ina219 bus voltage enumeration definition
uint8_t ina219_deinit(ina219_handle_t *handle)
close the chip
uint8_t ina219_get_calibration(ina219_handle_t *handle, uint16_t *data)
get the calibration
uint8_t ina219_set_mode(ina219_handle_t *handle, ina219_mode_t mode)
set the mode
uint8_t ina219_set_pga(ina219_handle_t *handle, ina219_pga_t pga)
set the pga
uint8_t ina219_set_bus_voltage_range(ina219_handle_t *handle, ina219_bus_voltage_range_t range)
set the bus voltage range
uint8_t ina219_calculate_calibration(ina219_handle_t *handle, uint16_t *calibration)
calculate the calibration
uint8_t ina219_init(ina219_handle_t *handle)
initialize the chip
uint8_t ina219_set_resistance(ina219_handle_t *handle, double resistance)
set the resistance
ina219_mode_t
ina219 mode enumeration definition
ina219_address_t
ina219 address enumeration definition
uint8_t ina219_set_bus_voltage_adc_mode(ina219_handle_t *handle, ina219_adc_mode_t mode)
set the bus voltage adc mode
struct ina219_handle_s ina219_handle_t
ina219 handle structure definition
@ INA219_ADC_MODE_12_BIT_128_SAMPLES
@ INA219_ADC_MODE_12_BIT_8_SAMPLES
@ INA219_ADC_MODE_10_BIT_1_SAMPLES
@ INA219_ADC_MODE_12_BIT_1_SAMPLES
@ INA219_ADC_MODE_12_BIT_4_SAMPLES
@ INA219_ADC_MODE_9_BIT_1_SAMPLES
@ INA219_ADC_MODE_12_BIT_2_SAMPLES
@ INA219_ADC_MODE_12_BIT_16_SAMPLES
@ INA219_ADC_MODE_12_BIT_32_SAMPLES
@ INA219_ADC_MODE_12_BIT_64_SAMPLES
@ INA219_ADC_MODE_11_BIT_1_SAMPLES
@ INA219_PGA_320_MV
@ INA219_PGA_40_MV
@ INA219_PGA_80_MV
@ INA219_PGA_160_MV
@ INA219_BUS_VOLTAGE_RANGE_16V
@ INA219_BUS_VOLTAGE_RANGE_32V
@ INA219_MODE_POWER_DOWN
@ INA219_MODE_ADC_OFF
@ INA219_MODE_SHUNT_BUS_VOLTAGE_CONTINUOUS
@ INA219_MODE_SHUNT_VOLTAGE_CONTINUOUS
@ INA219_MODE_SHUNT_BUS_VOLTAGE_TRIGGERED
@ INA219_MODE_SHUNT_VOLTAGE_TRIGGERED
@ INA219_MODE_BUS_VOLTAGE_TRIGGERED
@ INA219_MODE_BUS_VOLTAGE_CONTINUOUS
@ INA219_ADDRESS_D
@ INA219_ADDRESS_0
@ INA219_ADDRESS_6
@ INA219_ADDRESS_2
@ INA219_ADDRESS_3
@ INA219_ADDRESS_8
@ INA219_ADDRESS_E
@ INA219_ADDRESS_7
@ INA219_ADDRESS_9
@ INA219_ADDRESS_1
@ INA219_ADDRESS_4
@ INA219_ADDRESS_B
@ INA219_ADDRESS_C
@ INA219_ADDRESS_A
@ INA219_ADDRESS_5
@ INA219_ADDRESS_F
uint8_t ina219_interface_iic_init(void)
interface iic bus init
uint8_t ina219_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t ina219_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void ina219_interface_delay_ms(uint32_t ms)
interface delay ms
void ina219_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t ina219_interface_iic_deinit(void)
interface iic bus deinit
uint8_t ina219_register_test(ina219_address_t addr_pin)
register test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]