MPU6500 Bare-Metal Driver
Public API reference for the MPU6500 driver
Loading...
Searching...
No Matches
mpu6500.h File Reference

Platform-agnostic MPU6500 6-axis IMU driver. More...

#include <stdint.h>
Include dependency graph for mpu6500.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  MPU6500_Gyro_Data
 Processed gyroscope output in degrees per second (dps). More...
 
struct  MPU6500_Accel_Data
 Processed accelerometer output in g-force (g). More...
 
struct  MPU6500_Config
 Driver configuration and platform abstraction. More...
 

Macros

#define MPU6500_I2C_ADDR   (0x68U << 1)
 MPU6500 I2C address (0x68), left-shifted for HAL compatibility.
 
#define MPU6500_SLEEP_WAKE_MASK   0xBFU
 Bitmask to clear the SLEEP bit in PWR_MGMT_1 (bit 6).
 
#define MPU6500_REG_WHO_AM_I   0x75U
 
#define MPU6500_REG_PWR_MGMT_1   0x6BU
 
#define MPU6500_REG_ACCEL_CONFIG   0x1CU
 
#define MPU6500_REG_GYRO_CONFIG   0x1BU
 
#define MPU6500_REG_ACCEL_MEASURE   0x3BU
 Registers 59 to 64 – Accelerometer Measurements.
 
#define MPU6500_REG_GYRO_MEASURE   0x43U
 Registers 67 to 72 – Gyroscope Measurements.
 

Enumerations

enum  Accel_Range { MPU6500_ACC_SET_2G = 0x00 , MPU6500_ACC_SET_4G = 0x08 , MPU6500_ACC_SET_8G = 0x10 , MPU6500_ACC_SET_16G = 0x18 }
 Full-scale accelerometer range register values.
 
enum  Gyro_Range { MPU6500_Gyro_SET_250 = 0x00 , MPU6500_Gyro_SET_500 = 0x08 , MPU6500_Gyro_SET_1000 = 0x10 , MPU6500_Gyro_SET_2000 = 0x18 }
 Full-scale gyroscope range register values.
 
enum  Accel_Calculation { MPU6500_Accel_2G = 0 , MPU6500_Accel_4G , MPU6500_Accel_8G , MPU6500_Accel_16G }
 Internal index for accelerometer sensitivity lookup.
 
enum  Gyro_Calculation { MPU6500_Gyro_250 = 0 , MPU6500_Gyro_500 , MPU6500_Gyro_1000 , MPU6500_Gyro_2000 }
 Internal index for gyroscope sensitivity lookup.
 

Functions

int8_t MPU6500_Init (MPU6500_Config *config)
 Initialize the MPU6500 sensor.
 
int8_t MPU6500_SetAccelRange (MPU6500_Config *config, Accel_Range range)
 Set the accelerometer full-scale range.
 
int8_t MPU6500_SetRotationRange (MPU6500_Config *config, Gyro_Range range)
 Set the gyroscope full-scale range.
 
int8_t MPU6500_Read_Gyro_Data (MPU6500_Config *config, MPU6500_Gyro_Data *Gyro_Data)
 Read and process gyroscope data in a single blocking call.
 
int8_t MPU6500_Read_Accel_Data (MPU6500_Config *config, MPU6500_Accel_Data *Accel_Data)
 Read and process accelerometer data in a single blocking call.
 
int8_t MPU6500_Gyro_Calibration (MPU6500_Config *config, int8_t return_offset[3])
 Calibrate gyroscope zero-rate offsets.
 
int8_t MPU6500_Read_Gyro_DMA (MPU6500_Config *config, uint8_t raw_buf[6])
 Start a gyroscope I2C read into a caller-owned buffer.
 
int8_t MPU6500_Read_Accel_DMA (MPU6500_Config *config, uint8_t raw_buf[6])
 Start an accelerometer I2C read into a caller-owned buffer.
 
void MPU6500_Process_Gyro_DMA (MPU6500_Config *config, const uint8_t raw_buf[6], MPU6500_Gyro_Data *data)
 Process a completed gyroscope raw buffer into scaled output.
 
void MPU6500_Process_Accel_DMA (MPU6500_Config *config, const uint8_t raw_buf[6], MPU6500_Accel_Data *data)
 Process a completed accelerometer raw buffer into scaled output.
 

Detailed Description

Platform-agnostic MPU6500 6-axis IMU driver.

Provides both a blocking API (for polling/blocking I2C) and a split-phase non-blocking API (for DMA or interrupt-driven I2C). The driver is decoupled from any specific HAL through user-supplied function pointers in MPU6500_Config.

Author
Anthony Hua ... Rather SleepyPandas