Routines for interaction with MPU6050 IMU.
More...
|
struct | MPU6050 |
| Data structure containing variables specific to individual slave devices. More...
|
|
|
uint8_t | MPU6050_setup (MPU6050 *target, uint8_t i2c_number, uint8_t address) |
| Initalizes the slave device and populates data structure variable. More...
|
|
void | MPU6050_writeByte (MPU6050 *target, uint8_t address, uint8_t data) |
| Writes a single byte to a given address. More...
|
|
uint8_t | MPU6050_readByte (MPU6050 *target, uint8_t address) |
| Read a single byte from a given address. More...
|
|
uint16_t | MPU6050_readHalf (MPU6050 *target, uint8_t address) |
| Read a half word from a given address. More...
|
|
void | MPU6050_raw (MPU6050 *target, mpu_data what, int16_t *container) |
| Get raw data values (16-bit each) More...
|
|
void | MPU6050_calc (MPU6050 *target, mpu_data what, float *container) |
| Get calculated data values. More...
|
|
void | MPU6050_setAcc (MPU6050 *target, mpu_acc range) |
| Set acceleration range. More...
|
|
void | MPU6050_setGyr (MPU6050 *target, mpu_gyr range) |
| Set gyroscope range. More...
|
|
uint8_t | MPU6050_getAcc (MPU6050 *target) |
| Get the acceleration range. More...
|
|
uint16_t | MPU6050_getGyr (MPU6050 *target) |
| Get the gyroscope range. More...
|
|
Routines for interaction with MPU6050 IMU.
The MPU6060 operates on the I2C bus. This module provides routines for
- Note
- This library requires external functions to be declared.
- I2C_start()
- I2C_address()
- I2C_write()
- I2C_read()
- I2C_repeatRead()
- I2C_stop()
- Author
- Stuart Ianna
- Version
- 1.0
- Date
- June 2018
- Copyright
- GNU GPLv3
- Warning
- None
- Bug:
- None
- Todo:
- Verified Compilers
- arm-none-eabi-gcc (15:4.9.3+svn231177-1) 4.9.3 20150529 (prerelease)
- Example - Typical usage.
#include <stm32f103cb_core.h>
int main(void)
{
USART_setup(USART_1);
MCU_debugEnable(USART_add_put(USART_1));
I2C_setup(I2C_2);
float data[7];
volatile int i;
while (1) {
for(i = 0; i < 40000;i++);
}
return 0;
}
Data structure containing variables specific to individual slave devices.
Definition at line 63 of file mpu6050.h.
Data Fields |
uint8_t | bus |
| The port the device is connected to.
|
|
uint8_t | slaveAddress |
| The address of the slave device.
|
|
uint8_t | accelSen |
| The accelerometer sesitivity, set during MPU6050_setup() by reading slave data register.
|
|
uint16_t | gyroSen |
| The gyroscope sesitivity, set during MPU6050_setup() by reading slave data register.
|
|
Enumerator |
---|
MPU_ACC_2G |
2G range for accelerometer
|
MPU_ACC_4G |
4G range for accelerometer
|
MPU_ACC_8G |
8G range for accelerometer
|
MPU_ACC_16G |
16G range for accelerometer
|
Definition at line 102 of file mpu6050.h.
Different options for getting data with MPU6050_raw() and MPU6050_calc()
Enumerator |
---|
MPU_ACCX |
Acceleration data x-axis.
|
MPU_ACCY |
Acceleration data y-axis.
|
MPU_ACCZ |
Acceleration data z-axis.
|
MPU_TEMP |
Temperature data.
|
MPU_GYRX |
Gyrometer data x-axis.
|
MPU_GYRY |
Gyrometer data y-axis.
|
MPU_GYRZ |
Gyrometer data z-axis.
|
MPU_ACC |
All raw accelerometer data.
|
MPU_GYR |
All raw gyro data.
|
MPU_IMU |
All gyro and all accelermeter.
|
MPU_ALL |
All raw data.
|
Definition at line 86 of file mpu6050.h.
Enumerator |
---|
MPU_GYR_250 |
250 degree range for gyroscope
|
MPU_GYR_500 |
500 degree range for gyroscope
|
MPU_GYR_1000 |
1000 degree range for gyroscope
|
MPU_GYR_2000 |
2000 degree range for gyroscope
|
Definition at line 111 of file mpu6050.h.
Get calculated data values.
This function calculates G-force and degrees per second using the sensitivity values defined in data structure MPU6050.
- Parameters
-
target | The target slave device |
what | The type of data to get |
container | |
- Returns
- none
Definition at line 52 of file mpu6050.c.
uint8_t MPU6050_getAcc |
( |
MPU6050 * |
target | ) |
|
Get the acceleration range.
- Parameters
-
target | The target slave device |
- Returns
- The range for the accelerometer
Definition at line 455 of file mpu6050.c.
uint16_t MPU6050_getGyr |
( |
MPU6050 * |
target | ) |
|
Get the gyroscope range.
- Parameters
-
target | The target slave device |
- Returns
- The range for the gyroscope
Definition at line 485 of file mpu6050.c.
Get raw data values (16-bit each)
- Parameters
-
target | The target slave device |
what | The type of data to get |
container | |
- Returns
- none
Definition at line 238 of file mpu6050.c.
uint8_t MPU6050_readByte |
( |
MPU6050 * |
target, |
|
|
uint8_t |
address |
|
) |
| |
Read a single byte from a given address.
This function can be used to read individual values of the device registers
- Parameters
-
target | The target slave device |
address | The target register address of the slave |
- Returns
- The data at that address.
Definition at line 368 of file mpu6050.c.
uint16_t MPU6050_readHalf |
( |
MPU6050 * |
target, |
|
|
uint8_t |
address |
|
) |
| |
Read a half word from a given address.
- Parameters
-
target | The target slave device |
address | The target register address for the first register target |
- Returns
- The data at that address.
Definition at line 380 of file mpu6050.c.
Set acceleration range.
- Parameters
-
target | The target slave device |
range | The range to set |
- Returns
- none
Definition at line 394 of file mpu6050.c.
Set gyroscope range.
- Parameters
-
target | The target slave device |
range | The range to set |
- Returns
- none
Definition at line 425 of file mpu6050.c.
uint8_t MPU6050_setup |
( |
MPU6050 * |
target, |
|
|
uint8_t |
i2c_number, |
|
|
uint8_t |
address |
|
) |
| |
Initalizes the slave device and populates data structure variable.
- Note
- The relavent I2C port must be setup before this is called
- Parameters
-
target | Pointer to the MPU6050 data structure |
i2c_number | The number of the peripheral port connected, typically I2C_1 or I2C_2 |
address | The slave address of the device MPU_DEVICE_ADDRESS or MPU_DEVICE_ADDRESS_ALTERNATE |
- Returns
- 0 if setup was ok, 1 if error occured.
Definition at line 31 of file mpu6050.c.
void MPU6050_writeByte |
( |
MPU6050 * |
target, |
|
|
uint8_t |
address, |
|
|
uint8_t |
data |
|
) |
| |
Writes a single byte to a given address.
This function can be used to modify individual registers of the device.
- Parameters
-
target | the target slave device |
address | The target register address of the slave |
data | The byte of data to write |
- Returns
- none
Definition at line 358 of file mpu6050.c.