bsp_mpu9250.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #ifndef __bsp_mpu9250_H
  2. #define __bsp_mpu9250_H
  3. #include "main.h"
  4. /* ---- MPU9250 Reg In MPU9250 ---------------------------------------------- */
  5. #define MPU9250_I2C_ADDR ((uint8_t)0xD0)
  6. #define MPU9250_Device_ID ((uint8_t)0x71) // In MPU9250
  7. #define MPU9250_SELF_TEST_XG ((uint8_t)0x00)
  8. #define MPU9250_SELF_TEST_YG ((uint8_t)0x01)
  9. #define MPU9250_SELF_TEST_ZG ((uint8_t)0x02)
  10. #define MPU9250_SELF_TEST_XA ((uint8_t)0x0D)
  11. #define MPU9250_SELF_TEST_YA ((uint8_t)0x0E)
  12. #define MPU9250_SELF_TEST_ZA ((uint8_t)0x0F)
  13. #define MPU9250_XG_OFFSET_H ((uint8_t)0x13)
  14. #define MPU9250_XG_OFFSET_L ((uint8_t)0x14)
  15. #define MPU9250_YG_OFFSET_H ((uint8_t)0x15)
  16. #define MPU9250_YG_OFFSET_L ((uint8_t)0x16)
  17. #define MPU9250_ZG_OFFSET_H ((uint8_t)0x17)
  18. #define MPU9250_ZG_OFFSET_L ((uint8_t)0x18)
  19. #define MPU9250_SMPLRT_DIV ((uint8_t)0x19)
  20. #define MPU9250_CONFIG ((uint8_t)0x1A)
  21. #define MPU9250_GYRO_CONFIG ((uint8_t)0x1B)
  22. #define MPU9250_ACCEL_CONFIG ((uint8_t)0x1C)
  23. #define MPU9250_ACCEL_CONFIG_2 ((uint8_t)0x1D)
  24. #define MPU9250_LP_ACCEL_ODR ((uint8_t)0x1E)
  25. #define MPU9250_MOT_THR ((uint8_t)0x1F)
  26. #define MPU9250_FIFO_EN ((uint8_t)0x23)
  27. #define MPU9250_I2C_MST_CTRL ((uint8_t)0x24)
  28. #define MPU9250_I2C_SLV0_ADDR ((uint8_t)0x25)
  29. #define MPU9250_I2C_SLV0_REG ((uint8_t)0x26)
  30. #define MPU9250_I2C_SLV0_CTRL ((uint8_t)0x27)
  31. #define MPU9250_I2C_SLV1_ADDR ((uint8_t)0x28)
  32. #define MPU9250_I2C_SLV1_REG ((uint8_t)0x29)
  33. #define MPU9250_I2C_SLV1_CTRL ((uint8_t)0x2A)
  34. #define MPU9250_I2C_SLV2_ADDR ((uint8_t)0x2B)
  35. #define MPU9250_I2C_SLV2_REG ((uint8_t)0x2C)
  36. #define MPU9250_I2C_SLV2_CTRL ((uint8_t)0x2D)
  37. #define MPU9250_I2C_SLV3_ADDR ((uint8_t)0x2E)
  38. #define MPU9250_I2C_SLV3_REG ((uint8_t)0x2F)
  39. #define MPU9250_I2C_SLV3_CTRL ((uint8_t)0x30)
  40. #define MPU9250_I2C_SLV4_ADDR ((uint8_t)0x31)
  41. #define MPU9250_I2C_SLV4_REG ((uint8_t)0x32)
  42. #define MPU9250_I2C_SLV4_DO ((uint8_t)0x33)
  43. #define MPU9250_I2C_SLV4_CTRL ((uint8_t)0x34)
  44. #define MPU9250_I2C_SLV4_DI ((uint8_t)0x35)
  45. #define MPU9250_I2C_MST_STATUS ((uint8_t)0x36)
  46. #define MPU9250_INT_PIN_CFG ((uint8_t)0x37)
  47. #define MPU9250_INT_ENABLE ((uint8_t)0x38)
  48. #define MPU9250_INT_STATUS ((uint8_t)0x3A)
  49. #define MPU9250_ACCEL_XOUT_H ((uint8_t)0x3B)
  50. #define MPU9250_ACCEL_XOUT_L ((uint8_t)0x3C)
  51. #define MPU9250_ACCEL_YOUT_H ((uint8_t)0x3D)
  52. #define MPU9250_ACCEL_YOUT_L ((uint8_t)0x3E)
  53. #define MPU9250_ACCEL_ZOUT_H ((uint8_t)0x3F)
  54. #define MPU9250_ACCEL_ZOUT_L ((uint8_t)0x40)
  55. #define MPU9250_TEMP_OUT_H ((uint8_t)0x41)
  56. #define MPU9250_TEMP_OUT_L ((uint8_t)0x42)
  57. #define MPU9250_GYRO_XOUT_H ((uint8_t)0x43)
  58. #define MPU9250_GYRO_XOUT_L ((uint8_t)0x44)
  59. #define MPU9250_GYRO_YOUT_H ((uint8_t)0x45)
  60. #define MPU9250_GYRO_YOUT_L ((uint8_t)0x46)
  61. #define MPU9250_GYRO_ZOUT_H ((uint8_t)0x47)
  62. #define MPU9250_GYRO_ZOUT_L ((uint8_t)0x48)
  63. #define MPU9250_EXT_SENS_DATA_00 ((uint8_t)0x49)
  64. #define MPU9250_EXT_SENS_DATA_01 ((uint8_t)0x4A)
  65. #define MPU9250_EXT_SENS_DATA_02 ((uint8_t)0x4B)
  66. #define MPU9250_EXT_SENS_DATA_03 ((uint8_t)0x4C)
  67. #define MPU9250_EXT_SENS_DATA_04 ((uint8_t)0x4D)
  68. #define MPU9250_EXT_SENS_DATA_05 ((uint8_t)0x4E)
  69. #define MPU9250_EXT_SENS_DATA_06 ((uint8_t)0x4F)
  70. #define MPU9250_EXT_SENS_DATA_07 ((uint8_t)0x50)
  71. #define MPU9250_EXT_SENS_DATA_08 ((uint8_t)0x51)
  72. #define MPU9250_EXT_SENS_DATA_09 ((uint8_t)0x52)
  73. #define MPU9250_EXT_SENS_DATA_10 ((uint8_t)0x53)
  74. #define MPU9250_EXT_SENS_DATA_11 ((uint8_t)0x54)
  75. #define MPU9250_EXT_SENS_DATA_12 ((uint8_t)0x55)
  76. #define MPU9250_EXT_SENS_DATA_13 ((uint8_t)0x56)
  77. #define MPU9250_EXT_SENS_DATA_14 ((uint8_t)0x57)
  78. #define MPU9250_EXT_SENS_DATA_15 ((uint8_t)0x58)
  79. #define MPU9250_EXT_SENS_DATA_16 ((uint8_t)0x59)
  80. #define MPU9250_EXT_SENS_DATA_17 ((uint8_t)0x5A)
  81. #define MPU9250_EXT_SENS_DATA_18 ((uint8_t)0x5B)
  82. #define MPU9250_EXT_SENS_DATA_19 ((uint8_t)0x5C)
  83. #define MPU9250_EXT_SENS_DATA_20 ((uint8_t)0x5D)
  84. #define MPU9250_EXT_SENS_DATA_21 ((uint8_t)0x5E)
  85. #define MPU9250_EXT_SENS_DATA_22 ((uint8_t)0x5F)
  86. #define MPU9250_EXT_SENS_DATA_23 ((uint8_t)0x60)
  87. #define MPU9250_I2C_SLV0_DO ((uint8_t)0x63)
  88. #define MPU9250_I2C_SLV1_DO ((uint8_t)0x64)
  89. #define MPU9250_I2C_SLV2_DO ((uint8_t)0x65)
  90. #define MPU9250_I2C_SLV3_DO ((uint8_t)0x66)
  91. #define MPU9250_I2C_MST_DELAY_CTRL ((uint8_t)0x67)
  92. #define MPU9250_SIGNAL_PATH_RESET ((uint8_t)0x68)
  93. #define MPU9250_MOT_DETECT_CTRL ((uint8_t)0x69)
  94. #define MPU9250_USER_CTRL ((uint8_t)0x6A)
  95. #define MPU9250_PWR_MGMT_1 ((uint8_t)0x6B)
  96. #define MPU9250_PWR_MGMT_2 ((uint8_t)0x6C)
  97. #define MPU9250_FIFO_COUNTH ((uint8_t)0x72)
  98. #define MPU9250_FIFO_COUNTL ((uint8_t)0x73)
  99. #define MPU9250_FIFO_R_W ((uint8_t)0x74)
  100. #define MPU9250_WHO_AM_I ((uint8_t)0x75) // ID = 0x71 In MPU9250
  101. #define MPU9250_XA_OFFSET_H ((uint8_t)0x77)
  102. #define MPU9250_XA_OFFSET_L ((uint8_t)0x78)
  103. #define MPU9250_YA_OFFSET_H ((uint8_t)0x7A)
  104. #define MPU9250_YA_OFFSET_L ((uint8_t)0x7B)
  105. #define MPU9250_ZA_OFFSET_H ((uint8_t)0x7D)
  106. #define MPU9250_ZA_OFFSET_L ((uint8_t)0x7E)
  107. /* ---- AK8963 Reg In MPU9250 ----------------------------------------------- */
  108. #define AK8963_I2C_ADDR ((uint8_t)0x18)
  109. #define AK8963_Device_ID ((uint8_t)0x48)
  110. // Read-only Reg
  111. #define AK8963_WIA ((uint8_t)0x00)
  112. #define AK8963_INFO ((uint8_t)0x01)
  113. #define AK8963_ST1 ((uint8_t)0x02)
  114. #define AK8963_HXL ((uint8_t)0x03)
  115. #define AK8963_HXH ((uint8_t)0x04)
  116. #define AK8963_HYL ((uint8_t)0x05)
  117. #define AK8963_HYH ((uint8_t)0x06)
  118. #define AK8963_HZL ((uint8_t)0x07)
  119. #define AK8963_HZH ((uint8_t)0x08)
  120. #define AK8963_ST2 ((uint8_t)0x09)
  121. // Write/Read Reg
  122. #define AK8963_CNTL1 ((uint8_t)0x0A)
  123. #define AK8963_CNTL2 ((uint8_t)0x0B)
  124. #define AK8963_ASTC ((uint8_t)0x0C)
  125. #define AK8963_TS1 ((uint8_t)0x0D)
  126. #define AK8963_TS2 ((uint8_t)0x0E)
  127. #define AK8963_I2CDIS ((uint8_t)0x0F)
  128. // Read-only Reg ( ROM )
  129. #define AK8963_ASAX ((uint8_t)0x10)
  130. #define AK8963_ASAY ((uint8_t)0x11)
  131. #define AK8963_ASAZ ((uint8_t)0x12)
  132. int MPU9250_init(void);
  133. int MPU9250_Read(int16_t* acc,int16_t* gyr,int16_t* mag,int16_t* temperature);
  134. #endif