GlobLib
HAL and API libraries for MCUs and hardware.
mpu6050.h
Go to the documentation of this file.
1 
43 #ifndef MPU6050_H_
44 #define MPU6050_H_
45 #include <stdio.h>
46 
50 #define MPU_DEVICE_ADDRESS 0x68
51 
54 #define MPU_DEVICE_ADDRESS_ALTERNATE 0x69
55 
58 #define MPU_DATA_RANGE 32767.0f
59 
63 typedef struct{
64 
68  uint8_t bus;
72  uint8_t slaveAddress;
76  uint8_t accelSen;
80  uint16_t gyroSen;
81 }MPU6050;
82 
86 typedef enum{
87 
99 
100 }mpu_data;
101 
102 typedef enum{
103 
104  MPU_ACC_2G = 0x00,
105  MPU_ACC_4G = 0x08,
106  MPU_ACC_8G = 0x10,
107  MPU_ACC_16G = 0x18,
108 
109 }mpu_acc;
110 
111 typedef enum{
112 
113  MPU_GYR_250 = 0x00,
114  MPU_GYR_500 = 0x08,
115  MPU_GYR_1000 = 0x10,
116  MPU_GYR_2000 = 0x18,
117 
118 }mpu_gyr;
119 
120 
121 //Device register addresses
122 #define MPU6050_ADD_ACCX 0x3B
123 #define MPU6050_ADD_ACCY 0x3D
124 #define MPU6050_ADD_ACCZ 0x3F
125 #define MPU6050_ADD_TEMP 0x41
126 #define MPU6050_ADD_GYRX 0x43
127 #define MPU6050_ADD_GYRY 0x45
128 #define MPU6050_ADD_GYRZ 0x47
129 #define MPU6050_ADD_WAI 0x75
130 #define MPU6050_ADD_PWR_MGMT_1 0x6B
131 #define MPU6050_ADD_ACCEL_CONFIG 0x1C
132 #define MPU6050_ADD_GYRO_CONFIG 0x1B
133 
143 uint8_t MPU6050_setup(MPU6050 *target, uint8_t i2c_number, uint8_t address);
155 void MPU6050_writeByte(MPU6050 *target, uint8_t address, uint8_t data);
166 uint8_t MPU6050_readByte(MPU6050 *target, uint8_t address);
176 uint16_t MPU6050_readHalf(MPU6050 *target, uint8_t address);
186 void MPU6050_raw(MPU6050 *target, mpu_data what, int16_t *container);
199 void MPU6050_calc(MPU6050 *target, mpu_data what, float *container);
208 void MPU6050_setAcc(MPU6050 *target, mpu_acc range);
217 void MPU6050_setGyr(MPU6050 *target, mpu_gyr range);
225 uint8_t MPU6050_getAcc(MPU6050 *target);
233 uint16_t MPU6050_getGyr(MPU6050 *target);
236 #endif
237 
uint8_t slaveAddress
The address of the slave device.
Definition: mpu6050.h:72
uint8_t MPU6050_getAcc(MPU6050 *target)
Get the acceleration range.
Definition: mpu6050.c:455
All gyro and all accelermeter.
Definition: mpu6050.h:97
1000 degree range for gyroscope
Definition: mpu6050.h:115
void MPU6050_writeByte(MPU6050 *target, uint8_t address, uint8_t data)
Writes a single byte to a given address.
Definition: mpu6050.c:358
Gyrometer data z-axis.
Definition: mpu6050.h:94
500 degree range for gyroscope
Definition: mpu6050.h:114
250 degree range for gyroscope
Definition: mpu6050.h:113
uint8_t MPU6050_readByte(MPU6050 *target, uint8_t address)
Read a single byte from a given address.
Definition: mpu6050.c:368
8G range for accelerometer
Definition: mpu6050.h:106
void MPU6050_setAcc(MPU6050 *target, mpu_acc range)
Set acceleration range.
Definition: mpu6050.c:394
4G range for accelerometer
Definition: mpu6050.h:105
uint16_t gyroSen
The gyroscope sesitivity, set during MPU6050_setup() by reading slave data register.
Definition: mpu6050.h:80
void MPU6050_setGyr(MPU6050 *target, mpu_gyr range)
Set gyroscope range.
Definition: mpu6050.c:425
16G range for accelerometer
Definition: mpu6050.h:107
Gyrometer data y-axis.
Definition: mpu6050.h:93
uint16_t MPU6050_readHalf(MPU6050 *target, uint8_t address)
Read a half word from a given address.
Definition: mpu6050.c:380
uint8_t accelSen
The accelerometer sesitivity, set during MPU6050_setup() by reading slave data register.
Definition: mpu6050.h:76
Acceleration data x-axis.
Definition: mpu6050.h:88
Gyrometer data x-axis.
Definition: mpu6050.h:92
uint8_t bus
The port the device is connected to.
Definition: mpu6050.h:68
All raw data.
Definition: mpu6050.h:98
Acceleration data y-axis.
Definition: mpu6050.h:89
void MPU6050_raw(MPU6050 *target, mpu_data what, int16_t *container)
Get raw data values (16-bit each)
Definition: mpu6050.c:238
All raw accelerometer data.
Definition: mpu6050.h:95
mpu_acc
Definition: mpu6050.h:102
void MPU6050_calc(MPU6050 *target, mpu_data what, float *container)
Get calculated data values.
Definition: mpu6050.c:52
mpu_gyr
Definition: mpu6050.h:111
uint8_t MPU6050_setup(MPU6050 *target, uint8_t i2c_number, uint8_t address)
Initalizes the slave device and populates data structure variable.
Definition: mpu6050.c:31
Acceleration data z-axis.
Definition: mpu6050.h:90
mpu_data
Different options for getting data with MPU6050_raw() and MPU6050_calc()
Definition: mpu6050.h:86
Temperature data.
Definition: mpu6050.h:91
All raw gyro data.
Definition: mpu6050.h:96
2G range for accelerometer
Definition: mpu6050.h:104
Data structure containing variables specific to individual slave devices.
Definition: mpu6050.h:63
2000 degree range for gyroscope
Definition: mpu6050.h:116
uint16_t MPU6050_getGyr(MPU6050 *target)
Get the gyroscope range.
Definition: mpu6050.c:485