Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
mpu9250.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Felix Ruess <felix.ruess@gmail.com>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
30 #include "peripherals/mpu9250.h"
31 
32 const float MPU9250_GYRO_SENS[4] = {
37 };
38 
44 };
45 
46 const float MPU9250_ACCEL_SENS[4] = {
51 };
52 
58 };
59 
61 {
62  c->clk_sel = MPU9250_DEFAULT_CLK_SEL;
63  c->smplrt_div = MPU9250_DEFAULT_SMPLRT_DIV;
64  c->dlpf_gyro_cfg = MPU9250_DEFAULT_DLPF_GYRO_CFG;
65  c->dlpf_accel_cfg = MPU9250_DEFAULT_DLPF_ACCEL_CFG;
66  c->gyro_range = MPU9250_DEFAULT_FS_SEL;
67  c->accel_range = MPU9250_DEFAULT_AFS_SEL;
68  c->drdy_int_enable = false;
69 
70  /* Number of bytes to read starting with MPU9250_REG_INT_STATUS
71  * By default read only gyro and accel data -> 15 bytes.
72  * Increase to include slave data.
73  */
74  c->nb_bytes = 15;
75  c->nb_slaves = 0;
76  c->nb_slave_init = 0;
77 
78  c->i2c_bypass = false;
79 }
80 
81 void mpu9250_send_config(Mpu9250ConfigSet mpu_set, void *mpu, struct Mpu9250Config *config)
82 {
83  switch (config->init_status) {
84  case MPU9250_CONF_RESET:
85  /* device reset, set register values to defaults */
86  mpu_set(mpu, MPU9250_REG_PWR_MGMT_1, (1 << 6));
87  config->init_status++;
88  break;
90  /* trigger FIFO, I2C_MST and SIG_COND resets */
91  mpu_set(mpu, MPU9250_REG_USER_CTRL, ((1 << MPU9250_FIFO_RESET) |
92  (1 << MPU9250_I2C_MST_RESET) |
93  (1 << MPU9250_SIG_COND_RESET)));
94  config->init_status++;
95  break;
96  case MPU9250_CONF_PWR:
97  /* switch to gyroX clock by default */
98  mpu_set(mpu, MPU9250_REG_PWR_MGMT_1, ((config->clk_sel) | (0 << 6)));
99  config->init_status++;
100  break;
101  case MPU9250_CONF_SD:
102  /* configure sample rate divider */
103  mpu_set(mpu, MPU9250_REG_SMPLRT_DIV, config->smplrt_div);
104  config->init_status++;
105  break;
107  /* configure digital low pass filter for gyroscope */
108  mpu_set(mpu, MPU9250_REG_CONFIG, config->dlpf_gyro_cfg);
109  config->init_status++;
110  break;
112  /* configure digital low pass filter fir accelerometer */
113  mpu_set(mpu, MPU9250_REG_ACCEL_CONFIG_2, config->dlpf_accel_cfg);
114  config->init_status++;
115  break;
116  case MPU9250_CONF_GYRO:
117  /* configure gyro range */
118  mpu_set(mpu, MPU9250_REG_GYRO_CONFIG, (config->gyro_range << 3));
119  config->init_status++;
120  break;
121  case MPU9250_CONF_ACCEL:
122  /* configure accelerometer range */
123  mpu_set(mpu, MPU9250_REG_ACCEL_CONFIG, (config->accel_range << 3));
124  config->init_status++;
125  break;
127  /* if any, set MPU for I2C slaves and configure them*/
128  if (config->nb_slaves > 0) {
129  /* returns TRUE when all slaves are configured */
130  if (mpu9250_configure_i2c_slaves(mpu_set, mpu)) {
131  config->init_status++;
132  }
133  } else {
134  config->init_status++;
135  }
136  break;
138  /* configure data ready interrupt */
139  mpu_set(mpu, MPU9250_REG_INT_ENABLE, (config->drdy_int_enable << 0));
140  config->init_status++;
141  break;
142  case MPU9250_CONF_DONE:
143  config->initialized = true;
144  break;
145  default:
146  break;
147  }
148 }
c
VIC slots used for the LPC2148 define name e g gps UART1_VIC_SLOT e g modem SPI1_VIC_SLOT SPI1 in mcu_periph spi_arch c or spi_slave_hs_arch c(and some others not using the SPI peripheral yet..) I2C0_VIC_SLOT 8 mcu_periph/i2c_arch.c I2C1_VIC_SLOT 9 mcu_periph/i2c_arch.c USB_VIC_SLOT 10 usb
MPU9250_REG_INT_ENABLE
#define MPU9250_REG_INT_ENABLE
Definition: mpu9250_regs.h:92
MPU9250_CONF_INT_ENABLE
@ MPU9250_CONF_INT_ENABLE
Definition: mpu9250.h:112
MPU9250_ACCEL_SENS_4G
#define MPU9250_ACCEL_SENS_4G
Definition: mpu9250.h:86
MPU9250_CONF_RESET
@ MPU9250_CONF_RESET
Definition: mpu9250.h:103
MPU9250_GYRO_SENS
const float MPU9250_GYRO_SENS[4]
Definition: mpu9250.c:32
MPU9250_SIG_COND_RESET
#define MPU9250_SIG_COND_RESET
Definition: mpu9250_regs.h:127
MPU9250_REG_ACCEL_CONFIG
#define MPU9250_REG_ACCEL_CONFIG
Definition: mpu9250_regs.h:55
MPU9250_ACCEL_SENS_2G
#define MPU9250_ACCEL_SENS_2G
default accel sensitivy from the datasheet sens = 9.81 [m/s^2] / [LSB/g] * 2^INT32_ACCEL_FRAC ex: MPU...
Definition: mpu9250.h:83
MPU9250_DEFAULT_SMPLRT_DIV
#define MPU9250_DEFAULT_SMPLRT_DIV
Default sample rate divider.
Definition: mpu9250.h:36
MPU9250_DEFAULT_DLPF_ACCEL_CFG
#define MPU9250_DEFAULT_DLPF_ACCEL_CFG
Default internal sampling (1kHz, 42Hz LP Bandwidth)
Definition: mpu9250.h:42
MPU9250_ACCEL_SENS_16G_NUM
#define MPU9250_ACCEL_SENS_16G_NUM
Definition: mpu9250.h:93
MPU9250_GYRO_SENS_1000
#define MPU9250_GYRO_SENS_1000
Definition: mpu9250.h:66
MPU9250_ACCEL_SENS_2G_DEN
#define MPU9250_ACCEL_SENS_2G_DEN
Definition: mpu9250.h:85
MPU9250_GYRO_SENS_2000
#define MPU9250_GYRO_SENS_2000
Definition: mpu9250.h:69
mpu9250_send_config
void mpu9250_send_config(Mpu9250ConfigSet mpu_set, void *mpu, struct Mpu9250Config *config)
Configuration sequence called once before normal use.
Definition: mpu9250.c:81
MPU9250_ACCEL_SENS_4G_NUM
#define MPU9250_ACCEL_SENS_4G_NUM
Definition: mpu9250.h:87
MPU9250_GYRO_SENS_1000_NUM
#define MPU9250_GYRO_SENS_1000_NUM
Definition: mpu9250.h:67
MPU9250_GYRO_SENS_250
#define MPU9250_GYRO_SENS_250
default gyro sensitivy from the datasheet sens = 1/ [LSB/(deg/s)] * pi/180 * 2^INT32_RATE_FRAC ex: MP...
Definition: mpu9250.h:60
MPU9250_DEFAULT_DLPF_GYRO_CFG
#define MPU9250_DEFAULT_DLPF_GYRO_CFG
Default internal sampling (1kHz, 42Hz LP Bandwidth)
Definition: mpu9250.h:44
mpu9250_set_default_config
void mpu9250_set_default_config(struct Mpu9250Config *c)
Definition: mpu9250.c:60
MPU9250_CONF_DLPF_ACCEL
@ MPU9250_CONF_DLPF_ACCEL
Definition: mpu9250.h:107
MPU9250_FIFO_RESET
#define MPU9250_FIFO_RESET
Definition: mpu9250_regs.h:129
config
static const struct usb_config_descriptor config
Definition: usb_ser_hw.c:200
MPU9250_REG_CONFIG
#define MPU9250_REG_CONFIG
Definition: mpu9250_regs.h:53
MPU9250_CONF_USER_RESET
@ MPU9250_CONF_USER_RESET
Definition: mpu9250.h:104
MPU9250_ACCEL_SENS_8G
#define MPU9250_ACCEL_SENS_8G
Definition: mpu9250.h:89
MPU9250_I2C_MST_RESET
#define MPU9250_I2C_MST_RESET
Definition: mpu9250_regs.h:128
MPU9250_GYRO_SENS_2000_NUM
#define MPU9250_GYRO_SENS_2000_NUM
Definition: mpu9250.h:70
mpu9250.h
MPU9250_ACCEL_SENS
const float MPU9250_ACCEL_SENS[4]
Definition: mpu9250.c:46
mpu9250_configure_i2c_slaves
bool mpu9250_configure_i2c_slaves(Mpu9250ConfigSet mpu_set, void *mpu)
Configure I2C slaves of the MPU.
Definition: mpu9250_i2c.c:175
MPU9250_REG_ACCEL_CONFIG_2
#define MPU9250_REG_ACCEL_CONFIG_2
Definition: mpu9250_regs.h:56
MPU9250_GYRO_SENS_2000_DEN
#define MPU9250_GYRO_SENS_2000_DEN
Definition: mpu9250.h:71
MPU9250_REG_PWR_MGMT_1
#define MPU9250_REG_PWR_MGMT_1
Definition: mpu9250_regs.h:42
MPU9250_DEFAULT_FS_SEL
#define MPU9250_DEFAULT_FS_SEL
Default gyro full scale range +- 2000°/s.
Definition: mpu9250.h:38
MPU9250_ACCEL_SENS_16G_DEN
#define MPU9250_ACCEL_SENS_16G_DEN
Definition: mpu9250.h:94
MPU9250_GYRO_SENS_FRAC
const int32_t MPU9250_GYRO_SENS_FRAC[4][2]
Definition: mpu9250.c:39
MPU9250_CONF_DONE
@ MPU9250_CONF_DONE
Definition: mpu9250.h:113
MPU9250_ACCEL_SENS_2G_NUM
#define MPU9250_ACCEL_SENS_2G_NUM
Definition: mpu9250.h:84
MPU9250_ACCEL_SENS_8G_NUM
#define MPU9250_ACCEL_SENS_8G_NUM
Definition: mpu9250.h:90
MPU9250_CONF_DLPF_GYRO
@ MPU9250_CONF_DLPF_GYRO
Definition: mpu9250.h:108
MPU9250_GYRO_SENS_1000_DEN
#define MPU9250_GYRO_SENS_1000_DEN
Definition: mpu9250.h:68
MPU9250_CONF_ACCEL
@ MPU9250_CONF_ACCEL
Definition: mpu9250.h:110
int32_t
signed long int32_t
Definition: types.h:19
MPU9250_CONF_PWR
@ MPU9250_CONF_PWR
Definition: mpu9250.h:105
MPU9250_GYRO_SENS_500_NUM
#define MPU9250_GYRO_SENS_500_NUM
Definition: mpu9250.h:64
MPU9250_GYRO_SENS_500
#define MPU9250_GYRO_SENS_500
Definition: mpu9250.h:63
MPU9250_ACCEL_SENS_4G_DEN
#define MPU9250_ACCEL_SENS_4G_DEN
Definition: mpu9250.h:88
Mpu9250ConfigSet
void(* Mpu9250ConfigSet)(void *mpu, uint8_t _reg, uint8_t _val)
Configuration function prototype.
Definition: mpu9250.h:117
MPU9250_CONF_GYRO
@ MPU9250_CONF_GYRO
Definition: mpu9250.h:109
MPU9250_DEFAULT_AFS_SEL
#define MPU9250_DEFAULT_AFS_SEL
Default accel full scale range +- 16g.
Definition: mpu9250.h:40
MPU9250_ACCEL_SENS_8G_DEN
#define MPU9250_ACCEL_SENS_8G_DEN
Definition: mpu9250.h:91
MPU9250_REG_GYRO_CONFIG
#define MPU9250_REG_GYRO_CONFIG
Definition: mpu9250_regs.h:54
MPU9250_GYRO_SENS_250_NUM
#define MPU9250_GYRO_SENS_250_NUM
Definition: mpu9250.h:61
MPU9250_CONF_SD
@ MPU9250_CONF_SD
Definition: mpu9250.h:106
Mpu9250Config
Definition: mpu9250.h:126
MPU9250_DEFAULT_CLK_SEL
#define MPU9250_DEFAULT_CLK_SEL
Default clock: PLL with X gyro reference.
Definition: mpu9250.h:48
MPU9250_REG_USER_CTRL
#define MPU9250_REG_USER_CTRL
Definition: mpu9250_regs.h:41
MPU9250_ACCEL_SENS_16G
#define MPU9250_ACCEL_SENS_16G
Definition: mpu9250.h:92
MPU9250_GYRO_SENS_500_DEN
#define MPU9250_GYRO_SENS_500_DEN
Definition: mpu9250.h:65
MPU9250_REG_SMPLRT_DIV
#define MPU9250_REG_SMPLRT_DIV
Definition: mpu9250_regs.h:52
MPU9250_CONF_I2C_SLAVES
@ MPU9250_CONF_I2C_SLAVES
Definition: mpu9250.h:111
MPU9250_ACCEL_SENS_FRAC
const int32_t MPU9250_ACCEL_SENS_FRAC[4][2]
Definition: mpu9250.c:53
MPU9250_GYRO_SENS_250_DEN
#define MPU9250_GYRO_SENS_250_DEN
Definition: mpu9250.h:62