mpu6050.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef _MPU6050_H_
  2. #define _MPU6050_H_
  3. #include <stdint.h>
  4. #include <string.h>
  5. typedef __packed struct {
  6. int16_t ax,ay,az;
  7. int16_t temp;
  8. int16_t gx,gy,gz;
  9. }ad0x0_gyrodata_s;
  10. typedef ad0x0_gyrodata_s ad0x0_gyrodata_t;
  11. typedef uint8_t u8;
  12. // note: DMP code memory blocks defined at end of header file
  13. #define MPU6050_ADDRESS_W (MPU6050_ADDRESS_AD0_LOW <<1)
  14. #define MPU6050_ADDRESS_R (MPU6050_ADDRESS_AD0_LOW <<1)|0x1
  15. void mpu6050_init(void);
  16. void mpu6050_writebyte(u8 _reg,u8 _byte);
  17. void mpu6050_readbyte(u8 _reg);
  18. void mpu6050_writebits_mask(u8 _reg, u8 _byte, u8 _andmask);
  19. void mpu6050_writebit(u8 _reg, u8 _bitNum, u8 _value);
  20. //void mpu6050_readbytes(u8 _reg,u8 *_pbuf,u8 _count);
  21. void mpu6050_read14(void);
  22. void update_gdata(void);
  23. //void mpu6050_damn_lendian(void);
  24. //void mpu6050_stop(void);
  25. uint8_t mpu6050_zavis(void);
  26. ad0x0_gyrodata_s *mpu6050_get_gyrodata_s(void);
  27. ad0x0_gyrodata_s *mpu6050_get_gyrodata_s_le(void);
  28. void mpu6050_pin_irq(void);
  29. void mpu6050_start(void);
  30. uint32_t mpu6050_get_last_update_tick(void);
  31. /*чтобы все заработало, в main.c должны быть
  32. ...
  33. #include "ad0x0_i2c1.h" или #include "ad0x0_i2c2.h"
  34. #include "mpu6050.h"
  35. ...
  36. ad0x0_i2c1_init();
  37. mpu6050_init();
  38. mpu6050_start();
  39. ....
  40. ------------
  41. stm32f1xx_it.c
  42. #include "i2c/ad0x0_i2c1.h"
  43. #include "mpu6050/mpu6050.h"
  44. .....
  45. void I2C1_EV_IRQHandler(void)
  46. extern void ad0x0_i2c1_irq(void);
  47. ad0x0_i2c1_irq();
  48. ...
  49. void I2C1_ER_IRQHandler(void)
  50. {
  51. ad0x0_i2c1_irq_err();
  52. ...
  53. */
  54. #endif /* _MPU6050_H_ */