1
0

MPU6050.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2020  Jinan Bosai Network Technology Co., LTD
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #ifndef __MPU6050_H__
  16. #define __MPU6050_H__
  17. /* 宏定义 --------------------------------------------------------------------*/
  18. #define MPU6050_GYRO_OUT 0x43 //MPU6050陀螺仪数据寄存器地址
  19. #define MPU6050_ACC_OUT 0x3B //MPU6050加速度数据寄存器地址
  20. #define MPU6050_SLAVE_ADDRESS 0x68 //MPU6050器件读地址
  21. #define MPU6050_ADDRESS_AD0_LOW 0x68 // address pin low (GND), default for InvenSense evaluation board
  22. #define MPU6050_RA_CONFIG 0x1A
  23. #define MPU6050_RA_ACCEL_CONFIG 0x1C
  24. #define MPU6050_RA_FF_THR 0x1D
  25. #define MPU6050_RA_FF_DUR 0x1E
  26. #define MPU6050_RA_MOT_THR 0x1F //运动检测阀值设置寄存器
  27. #define MPU6050_RA_MOT_DUR 0x20 //运动检测时间阀值
  28. #define MPU6050_RA_ZRMOT_THR 0x21
  29. #define MPU6050_RA_ZRMOT_DUR 0x22
  30. #define MPU6050_RA_FIFO_EN 0x23
  31. #define MPU6050_RA_INT_PIN_CFG 0x37 //中断/旁路设置寄存器
  32. #define MPU6050_RA_INT_ENABLE 0x38 //中断使能寄存器
  33. #define MPU6050_RA_TEMP_OUT_H 0x41
  34. #define MPU6050_RA_USER_CTRL 0x6A
  35. #define MPU6050_RA_PWR_MGMT_1 0x6B
  36. #define MPU6050_RA_WHO_AM_I 0x75
  37. #define SENSOR_DATA_WIDTH_8_BIT 8 // 8 bit
  38. #define ACCEL_DATA_LEN 6
  39. #define TEMP_DATA_LEN 2
  40. typedef enum
  41. {
  42. OFF = 0,
  43. ON
  44. } SwitchStatus;
  45. enum AccelAxisNum {
  46. ACCEL_X_AXIS = 0,
  47. ACCEL_Y_AXIS = 1,
  48. ACCEL_Z_AXIS = 2,
  49. ACCEL_AXIS_NUM = 3,
  50. };
  51. enum AccelAxisPart {
  52. ACCEL_X_AXIS_LSB = 0,
  53. ACCEL_X_AXIS_MSB = 1,
  54. ACCEL_Y_AXIS_LSB = 2,
  55. ACCEL_Y_AXIS_MSB = 3,
  56. ACCEL_Z_AXIS_LSB = 4,
  57. ACCEL_Z_AXIS_MSB = 5,
  58. ACCEL_AXIS_BUTT,
  59. };
  60. enum TempPart {
  61. TEMP_LSB = 0,
  62. TEMP_MSB = 1,
  63. };
  64. /* MPU6050传感器数据类型定义 ------------------------------------------------------------*/
  65. typedef struct
  66. {
  67. short Temperature;
  68. short Accel[3];
  69. } MPU6050Data;
  70. int BoardInit(void);
  71. int MPU6050ReadData(MPU6050Data *ReadData);
  72. void LedD1StatusSet(SwitchStatus status);
  73. void LedD2StatusSet(SwitchStatus status);
  74. #endif