LibDriver MPU6500
Loading...
Searching...
No Matches
driver_mpu6500_read_test.c
Go to the documentation of this file.
1
36
38
39static mpu6500_handle_t gs_handle;
40
51uint8_t mpu6500_read_test(mpu6500_interface_t interface, mpu6500_address_t addr, uint32_t times)
52{
53 uint8_t res;
54 uint32_t i;
55 mpu6500_info_t info;
56
57 /* link interface function */
70
71 /* get information */
72 res = mpu6500_info(&info);
73 if (res != 0)
74 {
75 mpu6500_interface_debug_print("mpu6500: get info failed.\n");
76
77 return 1;
78 }
79 else
80 {
81 /* print chip info */
82 mpu6500_interface_debug_print("mpu6500: chip is %s.\n", info.chip_name);
83 mpu6500_interface_debug_print("mpu6500: manufacturer is %s.\n", info.manufacturer_name);
84 mpu6500_interface_debug_print("mpu6500: interface is %s.\n", info.interface);
85 mpu6500_interface_debug_print("mpu6500: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
86 mpu6500_interface_debug_print("mpu6500: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
87 mpu6500_interface_debug_print("mpu6500: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
88 mpu6500_interface_debug_print("mpu6500: max current is %0.2fmA.\n", info.max_current_ma);
89 mpu6500_interface_debug_print("mpu6500: max temperature is %0.1fC.\n", info.temperature_max);
90 mpu6500_interface_debug_print("mpu6500: min temperature is %0.1fC.\n", info.temperature_min);
91 }
92
93 /* start read test */
94 mpu6500_interface_debug_print("mpu6500: start read test.\n");
95
96 /* set the interface */
97 res = mpu6500_set_interface(&gs_handle, interface);
98 if (res != 0)
99 {
100 mpu6500_interface_debug_print("mpu6500: set interface failed.\n");
101
102 return 1;
103 }
104
105 /* set the addr pin */
106 res = mpu6500_set_addr_pin(&gs_handle, addr);
107 if (res != 0)
108 {
109 mpu6500_interface_debug_print("mpu6500: set addr pin failed.\n");
110
111 return 1;
112 }
113
114 /* init */
115 res = mpu6500_init(&gs_handle);
116 if (res != 0)
117 {
118 mpu6500_interface_debug_print("mpu6500: init failed.\n");
119
120 return 1;
121 }
122
123 /* delay 100 ms */
125
126 /* disable sleep */
127 res = mpu6500_set_sleep(&gs_handle, MPU6500_BOOL_FALSE);
128 if (res != 0)
129 {
130 mpu6500_interface_debug_print("mpu6500: set sleep failed.\n");
131 (void)mpu6500_deinit(&gs_handle);
132
133 return 1;
134 }
135
136 /* if spi interface, disable iic interface */
137 if (interface == MPU6500_INTERFACE_SPI)
138 {
139 /* disable iic */
141 if (res != 0)
142 {
143 mpu6500_interface_debug_print("mpu6500: set disable iic slave failed.\n");
144 (void)mpu6500_deinit(&gs_handle);
145
146 return 1;
147 }
148 }
149
150 /* set fifo 1024kb */
151 res = mpu6500_set_fifo_1024kb(&gs_handle);
152 if (res != 0)
153 {
154 mpu6500_interface_debug_print("mpu6500: set fifo 1024kb failed.\n");
155 (void)mpu6500_deinit(&gs_handle);
156
157 return 1;
158 }
159
160 /* set pll */
162 if (res != 0)
163 {
164 mpu6500_interface_debug_print("mpu6500: set clock source failed.\n");
165 (void)mpu6500_deinit(&gs_handle);
166
167 return 1;
168 }
169
170 /* set 50Hz */
171 res = mpu6500_set_sample_rate_divider(&gs_handle, (1000 / 50) - 1);
172 if (res != 0)
173 {
174 mpu6500_interface_debug_print("mpu6500: set sample rate divider failed.\n");
175 (void)mpu6500_deinit(&gs_handle);
176
177 return 1;
178 }
179
180 /* enable temperature sensor */
181 res = mpu6500_set_ptat(&gs_handle, MPU6500_BOOL_TRUE);
182 if (res != 0)
183 {
184 mpu6500_interface_debug_print("mpu6500: set ptat failed.\n");
185 (void)mpu6500_deinit(&gs_handle);
186
187 return 1;
188 }
189
190 /* disable cycle wake up */
192 if (res != 0)
193 {
194 mpu6500_interface_debug_print("mpu6500: set cycle wake up failed.\n");
195 (void)mpu6500_deinit(&gs_handle);
196
197 return 1;
198 }
199
200 /* enable acc x */
202 if (res != 0)
203 {
204 mpu6500_interface_debug_print("mpu6500: set standby mode failed.\n");
205 (void)mpu6500_deinit(&gs_handle);
206
207 return 1;
208 }
209
210 /* enable acc y */
212 if (res != 0)
213 {
214 mpu6500_interface_debug_print("mpu6500: set standby mode failed.\n");
215 (void)mpu6500_deinit(&gs_handle);
216
217 return 1;
218 }
219
220 /* enable acc z */
222 if (res != 0)
223 {
224 mpu6500_interface_debug_print("mpu6500: set standby mode failed.\n");
225 (void)mpu6500_deinit(&gs_handle);
226
227 return 1;
228 }
229
230 /* enable gyro x */
232 if (res != 0)
233 {
234 mpu6500_interface_debug_print("mpu6500: set standby mode failed.\n");
235 (void)mpu6500_deinit(&gs_handle);
236
237 return 1;
238 }
239
240 /* enable gyro y */
242 if (res != 0)
243 {
244 mpu6500_interface_debug_print("mpu6500: set standby mode failed.\n");
245 (void)mpu6500_deinit(&gs_handle);
246
247 return 1;
248 }
249
250 /* enable gyro z */
252 if (res != 0)
253 {
254 mpu6500_interface_debug_print("mpu6500: set standby mode failed.\n");
255 (void)mpu6500_deinit(&gs_handle);
256
257 return 1;
258 }
259
260 /* disable gyroscope x test */
262 if (res != 0)
263 {
264 mpu6500_interface_debug_print("mpu6500: set gyroscope test failed.\n");
265 (void)mpu6500_deinit(&gs_handle);
266
267 return 1;
268 }
269
270 /* disable gyroscope y test */
272 if (res != 0)
273 {
274 mpu6500_interface_debug_print("mpu6500: set gyroscope test failed.\n");
275 (void)mpu6500_deinit(&gs_handle);
276
277 return 1;
278 }
279
280 /* disable gyroscope z test */
282 if (res != 0)
283 {
284 mpu6500_interface_debug_print("mpu6500: set gyroscope test failed.\n");
285 (void)mpu6500_deinit(&gs_handle);
286
287 return 1;
288 }
289
290 /* disable accelerometer x test */
292 if (res != 0)
293 {
294 mpu6500_interface_debug_print("mpu6500: set accelerometer test failed.\n");
295 (void)mpu6500_deinit(&gs_handle);
296
297 return 1;
298 }
299
300 /* disable accelerometer y test */
302 if (res != 0)
303 {
304 mpu6500_interface_debug_print("mpu6500: set accelerometer test failed.\n");
305 (void)mpu6500_deinit(&gs_handle);
306
307 return 1;
308 }
309
310 /* disable accelerometer z test */
312 if (res != 0)
313 {
314 mpu6500_interface_debug_print("mpu6500: set accelerometer test failed.\n");
315 (void)mpu6500_deinit(&gs_handle);
316
317 return 1;
318 }
319
320 /* disable fifo */
321 res = mpu6500_set_fifo(&gs_handle, MPU6500_BOOL_FALSE);
322 if (res != 0)
323 {
324 mpu6500_interface_debug_print("mpu6500: set fifo failed.\n");
325 (void)mpu6500_deinit(&gs_handle);
326
327 return 1;
328 }
329
330 /* disable temp fifo */
332 if (res != 0)
333 {
334 mpu6500_interface_debug_print("mpu6500: set fifo enable failed.\n");
335 (void)mpu6500_deinit(&gs_handle);
336
337 return 1;
338 }
339
340 /* disable xg fifo */
342 if (res != 0)
343 {
344 mpu6500_interface_debug_print("mpu6500: set fifo enable failed.\n");
345 (void)mpu6500_deinit(&gs_handle);
346
347 return 1;
348 }
349
350 /* disable yg fifo */
352 if (res != 0)
353 {
354 mpu6500_interface_debug_print("mpu6500: set fifo enable failed.\n");
355 (void)mpu6500_deinit(&gs_handle);
356
357 return 1;
358 }
359
360 /* disable zg fifo */
362 if (res != 0)
363 {
364 mpu6500_interface_debug_print("mpu6500: set fifo enable failed.\n");
365 (void)mpu6500_deinit(&gs_handle);
366
367 return 1;
368 }
369
370 /* disable accel fifo */
372 if (res != 0)
373 {
374 mpu6500_interface_debug_print("mpu6500: set fifo enable failed.\n");
375 (void)mpu6500_deinit(&gs_handle);
376
377 return 1;
378 }
379
380 /* set interrupt level low */
382 if (res != 0)
383 {
384 mpu6500_interface_debug_print("mpu6500: set interrupt level failed.\n");
385 (void)mpu6500_deinit(&gs_handle);
386
387 return 1;
388 }
389
390 /* push-pull */
392 if (res != 0)
393 {
394 mpu6500_interface_debug_print("mpu6500: set interrupt pin type failed.\n");
395 (void)mpu6500_deinit(&gs_handle);
396
397 return 1;
398 }
399
400 /* disable motion */
402 if (res != 0)
403 {
404 mpu6500_interface_debug_print("mpu6500: set interrupt failed.\n");
405 (void)mpu6500_deinit(&gs_handle);
406
407 return 1;
408 }
409
410 /* disable fifo overflow */
412 if (res != 0)
413 {
414 mpu6500_interface_debug_print("mpu6500: set interrupt failed.\n");
415 (void)mpu6500_deinit(&gs_handle);
416
417 return 1;
418 }
419
420 /* disable dmp interrupt */
422 if (res != 0)
423 {
424 mpu6500_interface_debug_print("mpu6500: set interrupt failed.\n");
425 (void)mpu6500_deinit(&gs_handle);
426
427 return 1;
428 }
429
430 /* disable fsync int */
432 if (res != 0)
433 {
434 mpu6500_interface_debug_print("mpu6500: set interrupt failed.\n");
435 (void)mpu6500_deinit(&gs_handle);
436
437 return 1;
438 }
439
440 /* disable data ready */
442 if (res != 0)
443 {
444 mpu6500_interface_debug_print("mpu6500: set interrupt failed.\n");
445 (void)mpu6500_deinit(&gs_handle);
446
447 return 1;
448 }
449
450 /* enable latch */
452 if (res != 0)
453 {
454 mpu6500_interface_debug_print("mpu6500: set interrupt latch failed.\n");
455 (void)mpu6500_deinit(&gs_handle);
456
457 return 1;
458 }
459
460 /* enable interrupt read clear */
462 if (res != 0)
463 {
464 mpu6500_interface_debug_print("mpu6500: set interrupt read clear failed.\n");
465 (void)mpu6500_deinit(&gs_handle);
466
467 return 1;
468 }
469
470 /* disable sync input */
472 if (res != 0)
473 {
474 mpu6500_interface_debug_print("mpu6500: set extern sync failed.\n");
475 (void)mpu6500_deinit(&gs_handle);
476
477 return 1;
478 }
479
480 /* disable fsync interrupt */
482 if (res != 0)
483 {
484 mpu6500_interface_debug_print("mpu6500: set fsync interrupt failed.\n");
485 (void)mpu6500_deinit(&gs_handle);
486
487 return 1;
488 }
489
490 /* fsync interrupt level low */
492 if (res != 0)
493 {
494 mpu6500_interface_debug_print("mpu6500: set fsync interrupt level failed.\n");
495 (void)mpu6500_deinit(&gs_handle);
496
497 return 1;
498 }
499
500 /* disable iic master */
502 if (res != 0)
503 {
504 mpu6500_interface_debug_print("mpu6500: set iic master failed.\n");
505 (void)mpu6500_deinit(&gs_handle);
506
507 return 1;
508 }
509
510 /* disable iic bypass */
512 if (res != 0)
513 {
514 mpu6500_interface_debug_print("mpu6500: set iic bypass failed.\n");
515 (void)mpu6500_deinit(&gs_handle);
516
517 return 1;
518 }
519
520 /* disable gyro standby */
522 if (res != 0)
523 {
524 mpu6500_interface_debug_print("mpu6500: set gyro standby failed.\n");
525 (void)mpu6500_deinit(&gs_handle);
526
527 return 1;
528 }
529
530 /* set the fifo normal mode */
532 if (res != 0)
533 {
534 mpu6500_interface_debug_print("mpu6500: set fifo mode failed.\n");
535 (void)mpu6500_deinit(&gs_handle);
536
537 return 1;
538 }
539
540 /* set gyroscope choice 0 */
541 res = mpu6500_set_gyroscope_choice(&gs_handle, 0);
542 if (res != 0)
543 {
544 mpu6500_interface_debug_print("mpu6500: set gyroscope choice failed.\n");
545 (void)mpu6500_deinit(&gs_handle);
546
547 return 1;
548 }
549
550 /* set low pass filter 3 */
552 if (res != 0)
553 {
554 mpu6500_interface_debug_print("mpu6500: set low pass filter failed.\n");
555 (void)mpu6500_deinit(&gs_handle);
556
557 return 1;
558 }
559
560 /* set accelerometer choice 0 */
561 res = mpu6500_set_accelerometer_choice(&gs_handle, 0);
562 if (res != 0)
563 {
564 mpu6500_interface_debug_print("mpu6500: set accelerometer choice failed.\n");
565 (void)mpu6500_deinit(&gs_handle);
566
567 return 1;
568 }
569
570 /* set accelerometer low pass filter 3 */
572 if (res != 0)
573 {
574 mpu6500_interface_debug_print("mpu6500: set accelerometer low pass filter failed.\n");
575 (void)mpu6500_deinit(&gs_handle);
576
577 return 1;
578 }
579
580 /* set low power accel output rate 62.5Hz */
582 if (res != 0)
583 {
584 mpu6500_interface_debug_print("mpu6500: set low power accel output rate failed.\n");
585 (void)mpu6500_deinit(&gs_handle);
586
587 return 1;
588 }
589
590 /* disable wake on motion */
592 if (res != 0)
593 {
594 mpu6500_interface_debug_print("mpu6500: set wake on motion failed.\n");
595 (void)mpu6500_deinit(&gs_handle);
596
597 return 1;
598 }
599
600 /* enable accel compare with previous sample */
602 if (res != 0)
603 {
604 mpu6500_interface_debug_print("mpu6500: set accel compare with previous sample failed.\n");
605 (void)mpu6500_deinit(&gs_handle);
606
607 return 1;
608 }
609
610 /* ±2g */
612 if (res != 0)
613 {
614 mpu6500_interface_debug_print("mpu6500: set accelerometer range failed.\n");
615 (void)mpu6500_deinit(&gs_handle);
616
617 return 1;
618 }
619
620 /* delay 100 ms */
622
623 mpu6500_interface_debug_print("mpu6500: set accelerometer range 2g.\n");
624 for (i = 0; i < times; i++)
625 {
626 int16_t accel_raw[1][3];
627 float accel_g[1][3];
628 int16_t gyro_raw[1][3];
629 float gyro_dps[1][3];
630 uint16_t len;
631
632 len = 1;
633 res = mpu6500_read(&gs_handle, accel_raw, accel_g, gyro_raw, gyro_dps, &len);
634 if (res != 0)
635 {
636 mpu6500_interface_debug_print("mpu6500: read failed.\n");
637 (void)mpu6500_deinit(&gs_handle);
638
639 return 1;
640 }
641 mpu6500_interface_debug_print("mpu6500: acc x is %0.2fg.\n", accel_g[0][0]);
642 mpu6500_interface_debug_print("mpu6500: acc y is %0.2fg.\n", accel_g[0][1]);
643 mpu6500_interface_debug_print("mpu6500: acc z is %0.2fg.\n", accel_g[0][2]);
644
645 /* delay 1000 ms */
647 }
648
649 /* ±4g */
651 if (res != 0)
652 {
653 mpu6500_interface_debug_print("mpu6500: set accelerometer range failed.\n");
654 (void)mpu6500_deinit(&gs_handle);
655
656 return 1;
657 }
658
659 /* delay 100 ms */
661
662 mpu6500_interface_debug_print("mpu6500: set accelerometer range 4g.\n");
663 for (i = 0; i < times; i++)
664 {
665 int16_t accel_raw[1][3];
666 float accel_g[1][3];
667 int16_t gyro_raw[1][3];
668 float gyro_dps[1][3];
669 uint16_t len;
670
671 len = 1;
672 res = mpu6500_read(&gs_handle, accel_raw, accel_g, gyro_raw, gyro_dps, &len);
673 if (res != 0)
674 {
675 mpu6500_interface_debug_print("mpu6500: read failed.\n");
676 (void)mpu6500_deinit(&gs_handle);
677
678 return 1;
679 }
680 mpu6500_interface_debug_print("mpu6500: acc x is %0.2fg.\n", accel_g[0][0]);
681 mpu6500_interface_debug_print("mpu6500: acc y is %0.2fg.\n", accel_g[0][1]);
682 mpu6500_interface_debug_print("mpu6500: acc z is %0.2fg.\n", accel_g[0][2]);
683
684 /* delay 1000 ms */
686 }
687
688 /* ±8g */
690 if (res != 0)
691 {
692 mpu6500_interface_debug_print("mpu6500: set accelerometer range failed.\n");
693 (void)mpu6500_deinit(&gs_handle);
694
695 return 1;
696 }
697
698 /* delay 100 ms */
700
701 mpu6500_interface_debug_print("mpu6500: set accelerometer range 8g.\n");
702 for (i = 0; i < times; i++)
703 {
704 int16_t accel_raw[1][3];
705 float accel_g[1][3];
706 int16_t gyro_raw[1][3];
707 float gyro_dps[1][3];
708 uint16_t len;
709
710 len = 1;
711 res = mpu6500_read(&gs_handle, accel_raw, accel_g, gyro_raw, gyro_dps, &len);
712 if (res != 0)
713 {
714 mpu6500_interface_debug_print("mpu6500: read failed.\n");
715 (void)mpu6500_deinit(&gs_handle);
716
717 return 1;
718 }
719 mpu6500_interface_debug_print("mpu6500: acc x is %0.2fg.\n", accel_g[0][0]);
720 mpu6500_interface_debug_print("mpu6500: acc y is %0.2fg.\n", accel_g[0][1]);
721 mpu6500_interface_debug_print("mpu6500: acc z is %0.2fg.\n", accel_g[0][2]);
722
723 /* delay 1000 ms */
725 }
726
727 /* ±16g */
729 if (res != 0)
730 {
731 mpu6500_interface_debug_print("mpu6500: set accelerometer range failed.\n");
732 (void)mpu6500_deinit(&gs_handle);
733
734 return 1;
735 }
736
737 /* delay 100 ms */
739
740 mpu6500_interface_debug_print("mpu6500: set accelerometer range 16g.\n");
741 for (i = 0; i < times; i++)
742 {
743 int16_t accel_raw[1][3];
744 float accel_g[1][3];
745 int16_t gyro_raw[1][3];
746 float gyro_dps[1][3];
747 uint16_t len;
748
749 len = 1;
750 res = mpu6500_read(&gs_handle, accel_raw, accel_g, gyro_raw, gyro_dps, &len);
751 if (res != 0)
752 {
753 mpu6500_interface_debug_print("mpu6500: read failed.\n");
754 (void)mpu6500_deinit(&gs_handle);
755
756 return 1;
757 }
758 mpu6500_interface_debug_print("mpu6500: acc x is %0.2fg.\n", accel_g[0][0]);
759 mpu6500_interface_debug_print("mpu6500: acc y is %0.2fg.\n", accel_g[0][1]);
760 mpu6500_interface_debug_print("mpu6500: acc z is %0.2fg.\n", accel_g[0][2]);
761
762 /* delay 1000 ms */
764 }
765
766 /* ±250dps */
768 if (res != 0)
769 {
770 mpu6500_interface_debug_print("mpu6500: set gyroscope range failed.\n");
771 (void)mpu6500_deinit(&gs_handle);
772
773 return 1;
774 }
775
776 /* delay 100 ms */
778
779 mpu6500_interface_debug_print("mpu6500: set gyroscope range 250dps.\n");
780 for (i = 0; i < times; i++)
781 {
782 int16_t accel_raw[1][3];
783 float accel_g[1][3];
784 int16_t gyro_raw[1][3];
785 float gyro_dps[1][3];
786 uint16_t len;
787
788 len = 1;
789 res = mpu6500_read(&gs_handle, accel_raw, accel_g, gyro_raw, gyro_dps, &len);
790 if (res != 0)
791 {
792 mpu6500_interface_debug_print("mpu6500: read failed.\n");
793 (void)mpu6500_deinit(&gs_handle);
794
795 return 1;
796 }
797 mpu6500_interface_debug_print("mpu6500: gyro x is %0.2fdps.\n", gyro_dps[0][0]);
798 mpu6500_interface_debug_print("mpu6500: gyro y is %0.2fdps.\n", gyro_dps[0][1]);
799 mpu6500_interface_debug_print("mpu6500: gyro z is %0.2fdps.\n", gyro_dps[0][2]);
800
801 /* delay 1000 ms */
803 }
804
805 /* ±500dps */
807 if (res != 0)
808 {
809 mpu6500_interface_debug_print("mpu6500: set gyroscope range failed.\n");
810 (void)mpu6500_deinit(&gs_handle);
811
812 return 1;
813 }
814
815 /* delay 100 ms */
817
818 mpu6500_interface_debug_print("mpu6500: set gyroscope range 500dps.\n");
819 for (i = 0; i < times; i++)
820 {
821 int16_t accel_raw[1][3];
822 float accel_g[1][3];
823 int16_t gyro_raw[1][3];
824 float gyro_dps[1][3];
825 uint16_t len;
826
827 len = 1;
828 res = mpu6500_read(&gs_handle, accel_raw, accel_g, gyro_raw, gyro_dps, &len);
829 if (res != 0)
830 {
831 mpu6500_interface_debug_print("mpu6500: read failed.\n");
832 (void)mpu6500_deinit(&gs_handle);
833
834 return 1;
835 }
836 mpu6500_interface_debug_print("mpu6500: gyro x is %0.2fdps.\n", gyro_dps[0][0]);
837 mpu6500_interface_debug_print("mpu6500: gyro y is %0.2fdps.\n", gyro_dps[0][1]);
838 mpu6500_interface_debug_print("mpu6500: gyro z is %0.2fdps.\n", gyro_dps[0][2]);
839
840 /* delay 1000 ms */
842 }
843
844 /* ±1000dps */
846 if (res != 0)
847 {
848 mpu6500_interface_debug_print("mpu6500: set gyroscope range failed.\n");
849 (void)mpu6500_deinit(&gs_handle);
850
851 return 1;
852 }
853
854 /* delay 100 ms */
856
857 mpu6500_interface_debug_print("mpu6500: set gyroscope range 1000dps.\n");
858 for (i = 0; i < times; i++)
859 {
860 int16_t accel_raw[1][3];
861 float accel_g[1][3];
862 int16_t gyro_raw[1][3];
863 float gyro_dps[1][3];
864 uint16_t len;
865
866 len = 1;
867 res = mpu6500_read(&gs_handle, accel_raw, accel_g, gyro_raw, gyro_dps, &len);
868 if (res != 0)
869 {
870 mpu6500_interface_debug_print("mpu6500: read failed.\n");
871 (void)mpu6500_deinit(&gs_handle);
872
873 return 1;
874 }
875 mpu6500_interface_debug_print("mpu6500: gyro x is %0.2fdps.\n", gyro_dps[0][0]);
876 mpu6500_interface_debug_print("mpu6500: gyro y is %0.2fdps.\n", gyro_dps[0][1]);
877 mpu6500_interface_debug_print("mpu6500: gyro z is %0.2fdps.\n", gyro_dps[0][2]);
878
879 /* delay 1000 ms */
881 }
882
883 /* ±2000dps */
885 if (res != 0)
886 {
887 mpu6500_interface_debug_print("mpu6500: set gyroscope range failed.\n");
888 (void)mpu6500_deinit(&gs_handle);
889
890 return 1;
891 }
892
893 /* delay 100 ms */
895
896 mpu6500_interface_debug_print("mpu6500: set gyroscope range 2000dps.\n");
897 for (i = 0; i < times; i++)
898 {
899 int16_t accel_raw[1][3];
900 float accel_g[1][3];
901 int16_t gyro_raw[1][3];
902 float gyro_dps[1][3];
903 uint16_t len;
904
905 len = 1;
906 res = mpu6500_read(&gs_handle, accel_raw, accel_g, gyro_raw, gyro_dps, &len);
907 if (res != 0)
908 {
909 mpu6500_interface_debug_print("mpu6500: read failed.\n");
910 (void)mpu6500_deinit(&gs_handle);
911
912 return 1;
913 }
914 mpu6500_interface_debug_print("mpu6500: gyro x is %0.2fdps.\n", gyro_dps[0][0]);
915 mpu6500_interface_debug_print("mpu6500: gyro y is %0.2fdps.\n", gyro_dps[0][1]);
916 mpu6500_interface_debug_print("mpu6500: gyro z is %0.2fdps.\n", gyro_dps[0][2]);
917
918 /* delay 1000 ms */
920 }
921
922 mpu6500_interface_debug_print("mpu6500: read temperature.\n");
923 for (i = 0; i < times; i++)
924 {
925 int16_t raw;
926 float degrees;
927
928 /* read temperature */
929 res = mpu6500_read_temperature(&gs_handle, &raw, &degrees);
930 if (res != 0)
931 {
932 mpu6500_interface_debug_print("mpu6500: read temperature failed.\n");
933 (void)mpu6500_deinit(&gs_handle);
934
935 return 1;
936 }
937 mpu6500_interface_debug_print("mpu6500: temperature %0.2fC.\n", degrees);
938
939 /* delay 1000 ms */
941 }
942
943 /* finish read test */
944 mpu6500_interface_debug_print("mpu6500: finish read test.\n");
945 (void)mpu6500_deinit(&gs_handle);
946
947 return 0;
948}
driver mpu6500 read test header file
uint8_t mpu6500_set_ptat(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the temperature sensor
uint8_t mpu6500_set_accelerometer_choice(mpu6500_handle_t *handle, uint8_t choice)
set the accelerometer choice
uint8_t mpu6500_set_interface(mpu6500_handle_t *handle, mpu6500_interface_t interface)
set the chip interface
mpu6500_address_t
mpu6500 address enumeration definition
uint8_t mpu6500_set_gyro_standby(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the gyro standby
struct mpu6500_info_s mpu6500_info_t
mpu6500 information structure definition
uint8_t mpu6500_set_addr_pin(mpu6500_handle_t *handle, mpu6500_address_t addr_pin)
set the chip address pin
uint8_t mpu6500_set_iic_bypass(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the iic bypass
uint8_t mpu6500_set_accel_compare_with_previous_sample(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable accel compare with previous sample
uint8_t mpu6500_set_fifo(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable fifo
uint8_t mpu6500_set_interrupt_level(mpu6500_handle_t *handle, mpu6500_pin_level_t level)
set the interrupt level
uint8_t mpu6500_set_fsync_interrupt_level(mpu6500_handle_t *handle, mpu6500_pin_level_t level)
set the fsync interrupt level
uint8_t mpu6500_read(mpu6500_handle_t *handle, int16_t(*accel_raw)[3], float(*accel_g)[3], int16_t(*gyro_raw)[3], float(*gyro_dps)[3], uint16_t *len)
read the data
struct mpu6500_handle_s mpu6500_handle_t
mpu6500 handle structure definition
uint8_t mpu6500_set_gyroscope_choice(mpu6500_handle_t *handle, uint8_t choice)
set the gyroscope choice
uint8_t mpu6500_set_fsync_interrupt(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the fsync interrupt
uint8_t mpu6500_set_sleep(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the sleep mode
uint8_t mpu6500_read_temperature(mpu6500_handle_t *handle, int16_t(*raw), float *degrees)
read the temperature
uint8_t mpu6500_set_interrupt_latch(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the interrupt latch
uint8_t mpu6500_set_gyroscope_range(mpu6500_handle_t *handle, mpu6500_gyroscope_range_t range)
set the gyroscope range
uint8_t mpu6500_info(mpu6500_info_t *info)
get the chip's information
uint8_t mpu6500_set_clock_source(mpu6500_handle_t *handle, mpu6500_clock_source_t clock_source)
set the chip clock source
uint8_t mpu6500_set_wake_on_motion(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable wake on motion
uint8_t mpu6500_set_interrupt_read_clear(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the interrupt reading clear
uint8_t mpu6500_set_interrupt(mpu6500_handle_t *handle, mpu6500_interrupt_t type, mpu6500_bool_t enable)
enable or disable the interrupt
uint8_t mpu6500_set_fifo_enable(mpu6500_handle_t *handle, mpu6500_fifo_t fifo, mpu6500_bool_t enable)
enable or disable the fifo function
uint8_t mpu6500_deinit(mpu6500_handle_t *handle)
close the chip
uint8_t mpu6500_set_low_pass_filter(mpu6500_handle_t *handle, mpu6500_low_pass_filter_t filter)
set the low pass filter
uint8_t mpu6500_set_extern_sync(mpu6500_handle_t *handle, mpu6500_extern_sync_t sync)
set the extern sync type
uint8_t mpu6500_set_low_power_accel_output_rate(mpu6500_handle_t *handle, mpu6500_low_power_accel_output_rate_t rate)
set the low power accel output rate
uint8_t mpu6500_set_fifo_mode(mpu6500_handle_t *handle, mpu6500_fifo_mode mode)
set the fifo mode
uint8_t mpu6500_set_disable_iic_slave(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the iic slave mode
uint8_t mpu6500_set_iic_master(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the iic master mode
uint8_t mpu6500_set_cycle_wake_up(mpu6500_handle_t *handle, mpu6500_bool_t enable)
enable or disable the cycle wake up mode
uint8_t mpu6500_init(mpu6500_handle_t *handle)
initialize the chip
uint8_t mpu6500_set_accelerometer_range(mpu6500_handle_t *handle, mpu6500_accelerometer_range_t range)
set the accelerometer range
uint8_t mpu6500_set_accelerometer_test(mpu6500_handle_t *handle, mpu6500_axis_t axis, mpu6500_bool_t enable)
set the accelerometer test
mpu6500_interface_t
mpu6500 interface enumeration definition
uint8_t mpu6500_set_fifo_1024kb(mpu6500_handle_t *handle)
set fifo 1024kb
uint8_t mpu6500_set_standby_mode(mpu6500_handle_t *handle, mpu6500_source_t source, mpu6500_bool_t enable)
set source into standby mode
uint8_t mpu6500_set_accelerometer_low_pass_filter(mpu6500_handle_t *handle, mpu6500_accelerometer_low_pass_filter_t filter)
set the accelerometer low pass filter
uint8_t mpu6500_set_interrupt_pin_type(mpu6500_handle_t *handle, mpu6500_pin_type_t type)
set the interrupt pin type
uint8_t mpu6500_set_gyroscope_test(mpu6500_handle_t *handle, mpu6500_axis_t axis, mpu6500_bool_t enable)
set the gyroscope test
uint8_t mpu6500_set_sample_rate_divider(mpu6500_handle_t *handle, uint8_t d)
set the sample rate divider
@ MPU6500_ACCELEROMETER_LOW_PASS_FILTER_3
@ MPU6500_BOOL_FALSE
@ MPU6500_BOOL_TRUE
@ MPU6500_PIN_LEVEL_LOW
@ MPU6500_INTERRUPT_DATA_READY
@ MPU6500_INTERRUPT_FIFO_OVERFLOW
@ MPU6500_INTERRUPT_MOTION
@ MPU6500_INTERRUPT_FSYNC_INT
@ MPU6500_INTERRUPT_DMP
@ MPU6500_CLOCK_SOURCE_PLL
@ MPU6500_GYROSCOPE_RANGE_1000DPS
@ MPU6500_GYROSCOPE_RANGE_500DPS
@ MPU6500_GYROSCOPE_RANGE_2000DPS
@ MPU6500_GYROSCOPE_RANGE_250DPS
@ MPU6500_SOURCE_ACC_Y
@ MPU6500_SOURCE_GYRO_X
@ MPU6500_SOURCE_GYRO_Y
@ MPU6500_SOURCE_ACC_X
@ MPU6500_SOURCE_ACC_Z
@ MPU6500_SOURCE_GYRO_Z
@ MPU6500_AXIS_Y
@ MPU6500_AXIS_Z
@ MPU6500_AXIS_X
@ MPU6500_FIFO_MODE_NORMAL
@ MPU6500_EXTERN_SYNC_INPUT_DISABLED
@ MPU6500_LOW_POWER_ACCEL_OUTPUT_RATE_62P50
@ MPU6500_FIFO_TEMP
@ MPU6500_FIFO_YG
@ MPU6500_FIFO_ZG
@ MPU6500_FIFO_ACCEL
@ MPU6500_FIFO_XG
@ MPU6500_ACCELEROMETER_RANGE_2G
@ MPU6500_ACCELEROMETER_RANGE_8G
@ MPU6500_ACCELEROMETER_RANGE_16G
@ MPU6500_ACCELEROMETER_RANGE_4G
@ MPU6500_PIN_TYPE_PUSH_PULL
@ MPU6500_INTERFACE_SPI
@ MPU6500_LOW_PASS_FILTER_3
uint8_t mpu6500_interface_spi_deinit(void)
interface spi bus deinit
void mpu6500_interface_delay_ms(uint32_t ms)
interface delay ms
void mpu6500_interface_receive_callback(uint8_t type)
interface receive callback
uint8_t mpu6500_interface_iic_init(void)
interface iic bus init
uint8_t mpu6500_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t mpu6500_interface_iic_deinit(void)
interface iic bus deinit
uint8_t mpu6500_interface_spi_init(void)
interface spi bus init
uint8_t mpu6500_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
void mpu6500_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t mpu6500_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t mpu6500_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t mpu6500_read_test(mpu6500_interface_t interface, mpu6500_address_t addr, uint32_t times)
read test
uint32_t driver_version
char manufacturer_name[32]