/*
$License:
Copyright (C) 2011-2012 InvenSense Corporation, All Rights Reserved.
$
*/
/**
* @addtogroup DRIVERS Sensor Driver Layer
* @brief Hardware drivers to communicate with sensors via I2C.
*
* @{
* @file inv_mpu.c
* @brief An I2C-based driver for Invensense gyroscopes.
* @details This driver currently works for the following devices:
* MPU6050
* MPU6500
* MPU9150 (or MPU6050 w/ AK8975 on the auxiliary bus)
* MPU9250 (or MPU6500 w/ AK8963 on the auxiliary bus)
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "inv_mpu.h"
#include <math.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include "I2Cdev/I2Cdev.h"
/* The following functions must be defined for this platform:
* i2c_write(uint8_t slave_addr, uint8_t reg_addr, uint8_t length, uint8_t const *data)
* i2c_read(uint8_t slave_addr, uint8_t reg_addr, uint8_t length, uint8_t *data)
* delay_ms(uint32_t num_ms)
* min(int a, int b)
*/
#define min(a,b) ((a)<(b)?(a):(b))
#define i2c_write writeBytes
#define i2c_read(a,b,c,d) (readBytes(a,b,c,d)!=-1?0:1)
#define delay_ms(a) usleep(a*1000)
#define printf_P printf
#if !defined MPU6050 && !defined MPU9150 && !defined MPU6500 && !defined MPU9250
#error Which gyro are you using? Define MPUxxxx in your compiler options.
#endif
/* Time for some messy macro work. =]
* #define MPU9150
* is equivalent to..
* #define MPU6050
* #define AK8975_SECONDARY
*
* #define MPU9250
* is equivalent to..
* #define MPU6500
* #define AK8963_SECONDARY
*/
#if defined MPU9150
#ifndef MPU6050
#define MPU6050
#endif /* #ifndef MPU6050 */
#if defined AK8963_SECONDARY
#error "MPU9150 and AK8963_SECONDARY cannot both be defined."
#elif !defined AK8975_SECONDARY /* #if defined AK8963_SECONDARY */
#define AK8975_SECONDARY
#endif /* #if defined AK8963_SECONDARY */
#elif defined MPU9250 /* #if defined MPU9150 */
#ifndef MPU6500
#define MPU6500
#endif /* #ifndef MPU6500 */
#if defined AK8975_SECONDARY
#error "MPU9250 and AK8975_SECONDARY cannot both be defined."
#elif !defined AK8963_SECONDARY /* #if defined AK8975_SECONDARY */
#define AK8963_SECONDARY
#endif /* #if defined AK8975_SECONDARY */
#endif /* #if defined MPU9150 */
#if defined AK8975_SECONDARY || defined AK8963_SECONDARY
#define AK89xx_SECONDARY
#else
/* #warning "No compass = less profit for Invensense. Lame." */
#endif
static int set_int_enable(uint8_t enable);
/* Hardware registers needed by driver. */
struct gyro_reg_s
{
uint8_t who_am_i;
uint8_t rate_div;
uint8_t lpf;
uint8_t prod_id;
uint8_t user_ctrl;
uint8_t fifo_en;
uint8_t gyro_cfg;
uint8_t accel_cfg;
uint8_t accel_cfg2;
uint8_t lp_accel_odr;
uint8_t motion_thr;
uint8_t motion_dur;
uint8_t fifo_count_h;
uint8_t fifo_r_w;
uint8_t raw_gyro;
uint8_t raw_accel;
uint8_t temp;
uint8_t int_enable;
uint8_t dmp_int_status;
uint8_t int_status;
uint8_t accel_intel;
uint8_t pwr_mgmt_1;
uint8_t pwr_mgmt_2;
uint8_t int_pin_cfg;
uint8_t mem_r_w;
uint8_t accel_offs;
uint8_t i2c_mst;
uint8_t bank_sel;
uint8_t mem_start_addr;
uint8_t prgm_start_h;
#if defined AK89xx_SECONDARY
uint8_t s0_addr;
uint8_t s0_reg;
uint8_t s0_ctrl;
uint8_t s1_addr;
uint8_t s1_reg;
uint8_t s1_ctrl;
uint8_t s4_ctrl;
uint8_t s0_do;
uint8_t s1_do;
uint8_t i2c_delay_ctrl;
uint8_t raw_compass;
/* The I2C_MST_VDDIO bit is in this register. */
uint8_t yg_offs_tc;
#endif
};
/* Information specific to a particular device. */
struct hw_s
{
uint8_t addr;
uint16_t max_fifo;
uint8_t num_reg;
uint16_t temp_sens;
int16_t temp_offset;
uint16_t bank_size;
#if defined AK89xx_SECONDARY
uint16_t compass_fsr;
#endif
};
/* When entering motion interrupt mode, the driver keeps track of the
* previous state so that it can be restored at a later time.
* TODO: This is tacky. Fix it.
*/
struct motion_int_cache_s
{
uint16_t gyro_fsr;
uint8_t accel_fsr;
uint16_t lpf;
uint16_t sample_rate;
uint8_t sensors_on;
uint8_t fifo_sensors;
uint8_t dmp_on;
};
/* Cached chip configuration data.
* TODO: A lot of these can be handled with a bitmask.
*/
struct chip_cfg_s
{
/* Matches gyro_cfg >> 3 & 0x03 */
uint8_t gyro_fsr;
/* Matches accel_cfg >> 3 & 0x03 */
uint8_t accel_fsr;
/* Enabled sensors. Uses same masks as fifo_en, NOT pwr_mgmt_2. */
uint8_t sensors;
/* Matches config register. */
uint8_t lpf;
uint8_t clk_src;
/* Sample rate, NOT rate divider. */
uint16_t sample_rate;
/* Matches fifo_en register. */
uint8_t fifo_enable;
/* Matches int enable register. */
uint8_t int_enable;
/* 1 if devices on auxiliary I2C bus appear on the primary. */
uint8_t bypass_mode;
/* 1 if half-sensitivity.
* NOTE: This doesn't beint32_t here, but everything else in hw_s is const,
* and this allows us to save some precious RAM.
*/
uint8_t accel_half;
/* 1 if device in low-power accel-only mode. */
uint8_t lp_accel_mode;
/* 1 if interrupts are only triggered on motion events. */
uint8_t int_motion_only;
struct motion_int_cache_s cache;
/* 1 for active low interrupts. */
uint8_t active_low_int;
/* 1 for latched interrupts. */
uint8_t latched_int;
/* 1 if DMP is enabled. */
uint8_t dmp_on;
/* Ensures that DMP will only be loaded once. */
uint8_t dmp_loaded;
/* Sampling rate used when DMP is enabled. */
uint16_t dmp_sample_rate;
#ifdef AK89xx_SECONDARY
/* Compass sample rate. */
uint16_t compass_sample_rate;
uint8_t compass_addr;
int16_t mag_sens_adj[3];
#endif
};
/* Information for self-test. */
struct test_s
{
uint32_t gyro_sens;
uint32_t accel_sens;
uint8_t reg_rate_div;
uint8_t reg_lpf;
uint8_t reg_gyro_fsr;
uint8_t reg_accel_fsr;
uint16_t wait_ms;
uint8_t packet_thresh;
float min_dps;
float max_dps;
float max_gyro_var;
float min_g;
float max_g;
float max_accel_var;
};
/* Gyro driver state variables. */
struct gyro_state_s
{
const struct gyro_reg_s *reg;
const struct hw_s *hw;
const struct test_s *test;
struct chip_cfg_s chip_cfg;
};
/* Filter configurations. */
enum lpf_e
{
INV_FILTER_256HZ_NOLPF2 = 0,
INV_FILTER_188HZ,
INV_FILTER_98HZ,
INV_FILTER_42HZ,
INV_FILTER_20HZ,
INV_FILTER_10HZ,
INV_FILTER_5HZ,
INV_FILTER_2100HZ_NOLPF,
NUM_FILTER
};
/* Full scale ranges. */
enum gyro_fsr_e
{
INV_FSR_250DPS = 0,
INV_FSR_500DPS,
INV_FSR_1000DPS,
INV_FSR_2000DPS,
NUM_GYRO_FSR
};
/* Full scale ranges. */
enum accel_fsr_e
{
INV_FSR_2G = 0,
INV_FSR_4G,
INV_FSR_8G,
INV_FSR_16G,
NUM_ACCEL_FSR
};
/* Clock sources. */
enum clock_sel_e
{
INV_CLK_INTERNAL = 0,
INV_CLK_PLL,
NUM_CLK
};
/* Low-power accel wakeup rates. */
enum lp_accel_rate_e
{
#if defined MPU6050
INV_LPA_1_25HZ,
INV_LPA_5HZ,
INV_LPA_20HZ,
INV_LPA_40HZ
#elif defined MPU6500
INV_LPA_0_3125HZ,
INV_LPA_0_625HZ,
INV_LPA_1_25HZ,
INV_LPA_2_5HZ,
INV_LPA_5HZ,
INV_LPA_10HZ,
INV_LPA_20HZ,
INV_LPA_40HZ,
INV_LPA_80HZ,
INV_LPA_160HZ,
INV_LPA_320HZ,
INV_LPA_640HZ
#endif
};
#define BIT_I2C_MST_VDDIO (0x80)
#define BIT_FIFO_EN (0x40)
#define BIT_DMP_EN (0x80)
#define BIT_FIFO_RST (0x04)
#define BIT_DMP_RST (0x08)
#define BIT_FIFO_OVERFLOW (0x10)
#define BIT_DATA_RDY_EN (0x01)
#define BIT_DMP_INT_EN (0x02)
#define BIT_MOT_INT_EN (0x40)
#define BITS_FSR (0x18)
#define BITS_LPF (0x07)
#define BITS_HPF (0x07)
#define BITS_CLK (0x07)
#define BIT_FIFO_SIZE_1024 (0x40)
#define BIT_FIFO_SIZE_2048 (0x80)
#define BIT_FIFO_SIZE_4096 (0xC0)
#define BIT_RESET (0x80)
#define BIT_SLEEP (0x40)
#define BIT_S0_DELAY_EN (0x01)
#define BIT_S2_DELAY_EN (0x04)
#define BITS_SLAVE_LENGTH (0x0F)
#define BIT_SLAVE_BYTE_SW (0x40)
#define BIT_SLAVE_GROUP (0x10)
#define BIT_SLAVE_EN (0x80)
#defi
没有合适的资源?快使用搜索试试~ 我知道了~
MPU6050/MPU6500/MPU9150/MPU9250 over I2c for RaspberryPi

共17个文件
h:8个
c:5个
makefile:3个

1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉

温馨提示
_C语言_代码_相关文件_下载 MPU6050/MPU6500/MPU9150/MPU9250 over I2c for RaspberryPi 使用官方 Invensense 库 (v5.1): 这是一个使用 Rasperry Pi 测试 MPU 运动传感器的示例程序。 它执行所有初始化并收集: - 陀螺仪 - 加速 - 四元数 - 指南针(用于 MPU9XXX) - 温度 并以度数计算 Yaw、Pitch、Roll,然后将其显示为输出。 **接线** I2C 仅使用 2 根线进行数据传输:SCL 和 SDA RPi 引脚 3 -> MPU SDA RPi 引脚 5 -> MPU SCL 您还需要为 MPU 提供电源 (3.3V)。您可以使用外部电源或将其与 RPi 连接。 例如: RPi 引脚 1 (3.3V) -> MPU VCC RPi 引脚 6(接地)-> MPU GND **汇编:** 在 RPi 上,编辑 MotionSensor/Makefile 并调整 CXX_OPTS 以指定您的板 更多详情、使用方法,请下载后细读README.md文件
资源详情
资源评论
资源推荐
收起资源包目录























共 17 条
- 1



























快撑死的鱼
- 粉丝: 2w+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 基于MATLAB的语音信号设计.doc
- PLC自动装箱控制系统(1)(1).doc
- PLC实训报告.doc
- PLC在机械手远程控制系统的应用研讨.doc
- PLC在电镀生产线控制系统中的应用设计.doc
- ofdm无线通信系统中降低峰均比技术的研究电子与通信工程大学毕设论文(1).doc
- 探讨计算机网络安全问题(1).docx
- 大数据背景下留学行业的新发展(1).docx
- PLC在热处理电阻炉温度控制系统设计中的应用.doc
- 2023年教育信息化改革进展评估报告(1).pptx
- 网络发展对中学计算机教学的影响(1).docx
- 毕业设计基于matlab的二进制移相键控2psk调制与解调设计论文任务书(1).doc
- 基于SPOC的高职计算机类课程教学方法的调查研究(1).docx
- 软件购销合同范本(1).docx
- 中国移动通信客户入网服务协议(6)(1).doc
- 计算机网络安全存在的问题及其防范措施(2)(1).doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

评论1