mpu9250.h 7.3 KB

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