Giter VIP home page Giter VIP logo

mpu-6xxx's Introduction

mpu6xxx

中文页 | English

Introduction

This software package is a universal sensor driver package for InvenSense's six-axis series sensors, compatible with mpu6000, mpu6050, mpu6500, mpu9250, icm20608 and other sensors. And the new version of this software package has been connected to the Sensor framework, through the Sensor framework, developers can quickly drive this sensor. To view the README of the old version of the package, please click here.

Support

Contains equipment Accelerometer Gyroscope Magnetometer
Communication Interface
IIC
SPI
Work Mode
Polling
Interruption
FIFO
Power Mode
Power down
Low power consumption
Normal
High power consumption
Data output rate
Measuring Range
Self-check
Multi-instance

Instructions for use

Dependence

  • RT-Thread 4.0.0+
  • Sensor component
  • IIC/SPI driver: mpu6xxx devices use IIC/SPI for data communication, and need system IIC/SPI driver support;

Get the package

To use the MPU6xxx software package, you need to select it in the RT-Thread package management. The specific path is as follows:

RT-Thread online packages  --->
  peripheral libraries and drivers  --->
    sensors drivers  --->
      mpu6xxx: Universal 6-axis sensor driver package,support: accelerometer, gyroscope.
              Version (latest)  --->
        [*]   Enable mpu6xxx acce
        [*]   Enable mpu6xxx gyro
        [*]   Enable mpu6xxx mag

Enable MPU6xxx acce: Configure to enable the accelerometer function

Enable MPU6xxx gyro: Configure to turn on the gyroscope function

Enable MPU6xxx mag: Configure to turn on the Magnetometer function

Version: software package version selection

Using packages

The initialization function of MPU6xxx software package is as follows:

int rt_hw_mpu6xxx_init(const char *name, struct rt_sensor_config *cfg);

This function needs to be called by the user. The main functions of the function are:

  • Device configuration and initialization (configure interface devices and interrupt pins according to the incoming configuration information);
  • Register the corresponding sensor device and complete the registration of the MPU6xxx device;

Initialization example

#include "sensor_inven_mpu6xxx.h"

int rt_hw_mpu6xxx_port(void)
{
    struct rt_sensor_config cfg;
    
    cfg.intf.dev_name = "i2c1";
    cfg.intf.user_data = (void *)MPU6XXX_ADDR_DEFAULT;
    cfg.irq_pin.pin = RT_PIN_NONE;

    rt_hw_mpu6xxx_init("mpu", &cfg);
    return 0;
}
INIT_APP_EXPORT(rt_hw_mpu6xxx_port);

Precautions

No

contact information

Maintenance man:

mpu-6xxx's People

Contributors

armink avatar guozhanxin avatar mysterywolf avatar scratch-er avatar sogwms avatar yangjie11 avatar yqiu2018 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mpu-6xxx's Issues

rt-thread 使用该软件包编译报错

image

我这边的解决策略是,在mpu6xx.h中添加了一行 #include <stdint.h>, 但是我看该软件包中,大部分已经使用rt_uint32_t等类型,所以不是很清楚,到底应该统一使用c99标准头文件,还是rtt定义的类型

image

树莓派3B+运行此示例不成功

我在树莓派3B+上面运行这个程序,器件ID读取的结果始终为0x00,不能进入下一步。MPU6050在STM32上面运行此示例是没问题的,目前在查找原因,不知道有没有人遇到相同的问题。

注释里单位是不是写错了

/**
* This function gets the data of the gyroscope, unit: deg/10s
 *
 * @param dev the pointer of device driver structure
 * @param gyro the pointer of 3axes structure for receive data
 *
 * @return the reading status, RT_EOK reprensents  reading the data successfully.
 */
rt_err_t mpu6xxx_get_gyro(struct mpu6xxx_device *dev, struct mpu6xxx_3axes *gyro)
{
...
}

单位应该是 deg/10ms 而不是 deg/10s 是吧?

与其它I2C口冲突

使用I2C通信时,假设MPU6050是使用I2C2,有其它设备使用的是I2C1,使用该软件包时,其它I2C口用不了,怎么解决冲突的问题

RT-Thread latest version 下编译报错

../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c: In function '_mpu6xxx_set_range':
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:28:30: error: 'RT_SENSOR_CLASS_ACCE' undeclared (first use in this function); did you mean 'RT_SENSOR_TYPE_ACCE'?
   28 |     if (sensor->info.type == RT_SENSOR_CLASS_ACCE)
      |                              ^~~~~~~~~~~~~~~~~~~~
      |                              RT_SENSOR_TYPE_ACCE
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:28:30: note: each undeclared identifier is reported only once for each function it appears in
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:45:35: error: 'RT_SENSOR_CLASS_GYRO' undeclared (first use in this function); did you mean 'RT_SENSOR_TYPE_GYRO'?
   45 |     else if (sensor->info.type == RT_SENSOR_CLASS_GYRO)
      |                                   ^~~~~~~~~~~~~~~~~~~~
      |                                   RT_SENSOR_TYPE_GYRO
arm-none-eabi-gcc "../libraries/drivers/drv_sdio.c"
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c: In function '_mpu6xxx_acc_set_mode':
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:67:17: error: 'RT_SENSOR_MODE_POLLING' undeclared (first use in this function); did you mean 'RT_SENSOR_MODE_FETCH_POLLING'?
   67 |     if (mode == RT_SENSOR_MODE_POLLING)
      |                 ^~~~~~~~~~~~~~~~~~~~~~
      |                 RT_SENSOR_MODE_FETCH_POLLING
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c: In function '_mpu6xxx_set_power':
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:83:18: error: 'RT_SENSOR_POWER_DOWN' undeclared (first use in this function); did you mean 'RT_SENSOR_MODE_POWER_DOWN'?
   83 |     if (power == RT_SENSOR_POWER_DOWN)
      |                  ^~~~~~~~~~~~~~~~~~~~
      |                  RT_SENSOR_MODE_POWER_DOWN
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:96:23: error: 'RT_SENSOR_POWER_NORMAL' undeclared (first use in this function); did you mean 'RT_SENSOR_TYPE_MAG'?
   96 |     else if (power == RT_SENSOR_POWER_NORMAL)
      |                       ^~~~~~~~~~~~~~~~~~~~~~
      |                       RT_SENSOR_TYPE_MAG
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c: In function '_mpu6xxx_polling_get_data':
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:111:30: error: 'RT_SENSOR_CLASS_ACCE' undeclared (first use in this function); did you mean 'RT_SENSOR_TYPE_ACCE'?
  111 |     if (sensor->info.type == RT_SENSOR_CLASS_ACCE)
      |                              ^~~~~~~~~~~~~~~~~~~~
      |                              RT_SENSOR_TYPE_ACCE
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:125:35: error: 'RT_SENSOR_CLASS_GYRO' undeclared (first use in this function); did you mean 'RT_SENSOR_TYPE_GYRO'?
  125 |     else if (sensor->info.type == RT_SENSOR_CLASS_GYRO)
      |                                   ^~~~~~~~~~~~~~~~~~~~
      |                                   RT_SENSOR_TYPE_GYRO
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:140:35: error: 'RT_SENSOR_CLASS_MAG' undeclared (first use in this function); did you mean 'RT_SENSOR_TYPE_MAG'?
  140 |     else if (sensor->info.type == RT_SENSOR_CLASS_MAG)
      |                                   ^~~~~~~~~~~~~~~~~~~
      |                                   RT_SENSOR_TYPE_MAG
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c: In function 'mpu6xxx_fetch_data':
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:162:23: error: 'struct rt_sensor_config' has no member named 'mode'
  162 |     if (sensor->config.mode == RT_SENSOR_MODE_POLLING)
      |                       ^
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:162:32: error: 'RT_SENSOR_MODE_POLLING' undeclared (first use in this function); did you mean 'RT_SENSOR_MODE_FETCH_POLLING'?
  162 |     if (sensor->config.mode == RT_SENSOR_MODE_POLLING)
      |                                ^~~~~~~~~~~~~~~~~~~~~~
      |                                RT_SENSOR_MODE_FETCH_POLLING
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c: In function 'mpu6xxx_control':
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:181:10: error: 'RT_SENSOR_CTRL_SET_RANGE' undeclared (first use in this function); did you mean 'RT_SENSOR_CTRL_SOFT_RESET'?
  181 |     case RT_SENSOR_CTRL_SET_RANGE:
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
      |          RT_SENSOR_CTRL_SOFT_RESET
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:184:10: error: 'RT_SENSOR_CTRL_SET_MODE' undeclared (first use in this function); did you mean 'RT_SENSOR_CTRL_GET_ID'?
  184 |     case RT_SENSOR_CTRL_SET_MODE:
      |          ^~~~~~~~~~~~~~~~~~~~~~~
      |          RT_SENSOR_CTRL_GET_ID
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:187:10: error: 'RT_SENSOR_CTRL_SET_POWER' undeclared (first use in this function); did you mean 'RT_SENSOR_MODE_SET_POWER'?
  187 |     case RT_SENSOR_CTRL_SET_POWER:
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
      |          RT_SENSOR_MODE_SET_POWER
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:191:10: error: 'RT_SENSOR_CTRL_SET_ODR' undeclared (first use in this function); did you mean 'RT_SENSOR_CTRL_GET_ID'?
  191 |     case RT_SENSOR_CTRL_SET_ODR:
      |          ^~~~~~~~~~~~~~~~~~~~~~
      |          RT_SENSOR_CTRL_GET_ID
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c: In function 'rt_hw_mpu6xxx_init':
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:224:40: error: 'RT_SENSOR_CLASS_ACCE' undeclared (first use in this function); did you mean 'RT_SENSOR_TYPE_ACCE'?
  224 |         sensor_acce->info.type       = RT_SENSOR_CLASS_ACCE;
      |                                        ^~~~~~~~~~~~~~~~~~~~
      |                                        RT_SENSOR_TYPE_ACCE
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:226:27: error: 'struct rt_sensor_info' has no member named 'model'; did you mean 'mode'?
  226 |         sensor_acce->info.model      = "mpu6xxx_acc";
      |                           ^~~~~
      |                           mode
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:229:26: error: 'struct rt_sensor_info' has no member named 'range_max'
  229 |         sensor_acce->info.range_max  = 16000;
      |                          ^
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:230:26: error: 'struct rt_sensor_info' has no member named 'range_min'
  230 |         sensor_acce->info.range_min  = 2000;
      |                          ^
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:231:26: error: 'struct rt_sensor_info' has no member named 'period_min'
  231 |         sensor_acce->info.period_min = 5;
      |                          ^
arm-none-eabi-gcc "../libraries/drivers/drv_sdram.c"
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:251:40: error: 'RT_SENSOR_CLASS_GYRO' undeclared (first use in this function); did you mean 'RT_SENSOR_TYPE_GYRO'?
  251 |         sensor_gyro->info.type       = RT_SENSOR_CLASS_GYRO;
      |                                        ^~~~~~~~~~~~~~~~~~~~
      |                                        RT_SENSOR_TYPE_GYRO
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:253:27: error: 'struct rt_sensor_info' has no member named 'model'; did you mean 'mode'?
  253 |         sensor_gyro->info.model      = "mpu6xxx_gyro";
      |                           ^~~~~
      |                           mode
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:256:26: error: 'struct rt_sensor_info' has no member named 'range_max'
  256 |         sensor_gyro->info.range_max  = 2000000;
      |                          ^
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:257:26: error: 'struct rt_sensor_info' has no member named 'range_min'
  257 |         sensor_gyro->info.range_min  = 250000;
      |                          ^
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:258:26: error: 'struct rt_sensor_info' has no member named 'period_min'
  258 |         sensor_gyro->info.period_min = 5;
      |                          ^
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:279:39: error: 'RT_SENSOR_CLASS_MAG' undeclared (first use in this function); did you mean 'RT_SENSOR_TYPE_MAG'?
  279 |         sensor_mag->info.type       = RT_SENSOR_CLASS_MAG;
      |                                       ^~~~~~~~~~~~~~~~~~~
      |                                       RT_SENSOR_TYPE_MAG
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:281:26: error: 'struct rt_sensor_info' has no member named 'model'; did you mean 'mode'?
  281 |         sensor_mag->info.model      = "mpu6xxx_mag";
      |                          ^~~~~
      |                          mode
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:284:25: error: 'struct rt_sensor_info' has no member named 'range_max'
  284 |         sensor_mag->info.range_max  = 49120;
      |                         ^
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:285:25: error: 'struct rt_sensor_info' has no member named 'range_min'
  285 |         sensor_mag->info.range_min  = -49120;
      |                         ^
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:286:25: error: 'struct rt_sensor_info' has no member named 'period_min'
  286 |         sensor_mag->info.period_min = 100;
      |                         ^
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c: In function '_mpu6xxx_set_power':
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:107:1: warning: control reaches end of non-void function [-Wreturn-type]
  107 | }
      | ^
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c: In function 'mpu6xxx_fetch_data':
../packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.c:170:1: warning: control reaches end of non-void function [-Wreturn-type]
  170 | }
      | ^
arm-none-eabi-gcc "../libraries/drivers/drv_spi.c"
arm-none-eabi-gcc "../libraries/drivers/drv_usart.c"
arm-none-eabi-gcc "../libraries/drivers/drv_wlan.c"
make: *** [packages/mpu6xxx-latest/src/subdir.mk:21: packages/mpu6xxx-latest/src/sensor_inven_mpu6xxx.o] Error 1
make: *** Waiting for unfinished jobs....
../libraries/drivers/drv_common.c:16:13: warning: 'reboot' defined but not used [-Wunused-function]
   16 | static void reboot(uint8_t argc, char **argv)
      |             ^~~~~~
../libraries/drivers/drv_gpio.c:411:5: warning: initialization of 'void (*)(struct rt_device *, rt_base_t,  rt_uint8_t)' {aka 'void (*)(struct rt_device *, long int,  unsigned char)'} from incompatible pointer type 'void (*)(struct rt_device *, rt_base_t,  rt_base_t)' {aka 'void (*)(struct rt_device *, long int,  long int)'} [-Wincompatible-pointer-types]
  411 |     stm32_pin_mode,
      |     ^~~~~~~~~~~~~~
../libraries/drivers/drv_gpio.c:411:5: note: (near initialization for '_stm32_pin_ops.pin_mode')
../libraries/drivers/drv_gpio.c:412:5: warning: initialization of 'void (*)(struct rt_device *, rt_base_t,  rt_uint8_t)' {aka 'void (*)(struct rt_device *, long int,  unsigned char)'} from incompatible pointer type 'void (*)(struct rt_device *, rt_base_t,  rt_base_t)' {aka 'void (*)(struct rt_device *, long int,  long int)'} [-Wincompatible-pointer-types]
  412 |     stm32_pin_write,
      |     ^~~~~~~~~~~~~~~
../libraries/drivers/drv_gpio.c:412:5: note: (near initialization for '_stm32_pin_ops.pin_write')
../libraries/drivers/drv_gpio.c:413:5: warning: initialization of 'rt_int8_t (*)(struct rt_device *, rt_base_t)' {aka 'signed char (*)(struct rt_device *, long int)'} from incompatible pointer type 'int (*)(struct rt_device *, rt_base_t)' {aka 'int (*)(struct rt_device *, long int)'} [-Wincompatible-pointer-types]
  413 |     stm32_pin_read,
      |     ^~~~~~~~~~~~~~
../libraries/drivers/drv_gpio.c:413:5: note: (near initialization for '_stm32_pin_ops.pin_read')
../libraries/drivers/drv_gpio.c:414:5: warning: initialization of 'rt_err_t (*)(struct rt_device *, rt_base_t,  rt_uint8_t,  void (*)(void *), void *)' {aka 'long int (*)(struct rt_device *, long int,  unsigned char,  void (*)(void *), void *)'} from incompatible pointer type 'rt_err_t (*)(struct rt_device *, rt_int32_t,  rt_uint32_t,  void (*)(void *), void *)' {aka 'long int (*)(struct rt_device *, long int,  long unsigned int,  void (*)(void *), void *)'} [-Wincompatible-pointer-types]
  414 |     stm32_pin_attach_irq,
      |     ^~~~~~~~~~~~~~~~~~~~
../libraries/drivers/drv_gpio.c:414:5: note: (near initialization for '_stm32_pin_ops.pin_attach_irq')
../libraries/drivers/drv_gpio.c:416:5: warning: initialization of 'rt_err_t (*)(struct rt_device *, rt_base_t,  rt_uint8_t)' {aka 'long int (*)(struct rt_device *, long int,  unsigned char)'} from incompatible pointer type 'rt_err_t (*)(struct rt_device *, rt_base_t,  rt_uint32_t)' {aka 'long int (*)(struct rt_device *, long int,  long unsigned int)'} [-Wincompatible-pointer-types]
  416 |     stm32_pin_irq_enable,
      |     ^~~~~~~~~~~~~~~~~~~~
../libraries/drivers/drv_gpio.c:416:5: note: (near initialization for '_stm32_pin_ops.pin_irq_enable')
../libraries/drivers/drv_usart.c:643:21: warning: initialization of 'rt_ssize_t (*)(struct rt_serial_device *, rt_uint8_t *, rt_size_t,  int)' {aka 'int (*)(struct rt_serial_device *, unsigned char *, unsigned int,  int)'} from incompatible pointer type 'rt_size_t (*)(struct rt_serial_device *, rt_uint8_t *, rt_size_t,  int)' {aka 'unsigned int (*)(struct rt_serial_device *, unsigned char *, unsigned int,  int)'} [-Wincompatible-pointer-types]
  643 |     .dma_transmit = stm32_dma_transmit
      |                     ^~~~~~~~~~~~~~~~~~
../libraries/drivers/drv_usart.c:643:21: note: (near initialization for 'stm32_uart_ops.dma_transmit')
"make -j12 all" terminated with exit code 2. Build might be incomplete.

21:01:04 Build Failed. 31 errors, 9 warnings. (took 3s.933ms)

应该是因为 Sensor 库更新了,导致项目不再兼容最新版本

这个模块还在继续完善吗?

使用过程存在些不解或者存在问题的地方,跟大家请教下:
Q1:
struct rt_sensor_config cfg;

cfg.intf.dev_name = "i2c2";
cfg.intf.user_data = (void *)MPU6XXX_ADDR_DEFAULT;
cfg.irq_pin.pin = RT_PIN_NONE;

rt_hw_mpu6xxx_init("mpu", &cfg);

请教下,rt_hw_mpu6xxx_init("mpu", &cfg); 这里的"mpu"不是注册的设备名称吗?为什么通过“i2c2"可以找到设备,"mpu"找不到呢?

Q2:中断管脚现在是不是还不支持呢? 下一版本能否考虑加上这个?

Q3:通过rt_device_read读不到数据,有没有示例代码?

谢谢!!

一处可能导致hardfault的bug

在初始化部分

result = rt_hw_sensor_register(sensor_gyro, name, RT_DEVICE_FLAG_RDWR, RT_NULL);
if (result != RT_EOK)
{
LOG_E("device register err code: %d", result);
goto __exit;
}

此处初始化失败之后free掉了申请的内存
__exit:
if (sensor_acce)
rt_free(sensor_acce);
if (sensor_gyro)
rt_free(sensor_gyro);
if (mpu_dev)
mpu6xxx_deinit(mpu_dev);

但是前面向系统注册的设备还是在系统设备链表里面,之后再进行申请内存写值的时候就会破坏系统设备链表,进而访问不可访问的内存引发hardfault错误。建议这里初始化在设备注册成功的情况下不要free掉设备对象占用的内存

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.