MPU6500 Bare-Metal Driver
Public API reference for the MPU6500 driver
Loading...
Searching...
No Matches
Basic Driver

Blocking API functions. More...

Collaboration diagram for Basic Driver:

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.
 

Detailed Description

Blocking API functions.

Function Documentation

◆ MPU6500_Gyro_Calibration()

int8_t MPU6500_Gyro_Calibration ( MPU6500_Config config,
int8_t  return_offset[3] 
)

Calibrate gyroscope zero-rate offsets.

Collects 512 samples while the device is stationary and averages them to compute per-axis offsets. Stores the result in the internal driver config. Uses the split-phase DMA functions with delay_ms() between each sample.

Parameters
configDriver configuration.
return_offsetOptional output array [X,Y,Z] for the offsets. Can be NULL.
Returns
0 on success, -1 on failure.

References MPU6500_Config::delay_ms, MPU6500_Config::Gyro_Offset_Calibration, MPU6500_Process_Gyro_DMA(), and MPU6500_Read_Gyro_DMA().

◆ MPU6500_Init()

int8_t MPU6500_Init ( MPU6500_Config config)

Initialize the MPU6500 sensor.

Reads WHO_AM_I, clears the SLEEP bit, and verifies the device is awake. Uses delay_ms() between I2C operations for non-blocking compatibility.

Parameters
configPointer to a fully populated MPU6500_Config.
Returns
0 on success, -1 on failure.

References MPU6500_Config::delay_ms, MPU6500_I2C_ADDR, MPU6500_SLEEP_WAKE_MASK, MPU6500_Config::read, and MPU6500_Config::write.

◆ MPU6500_Read_Accel_Data()

int8_t MPU6500_Read_Accel_Data ( MPU6500_Config config,
MPU6500_Accel_Data Accel_Data 
)

Read and process accelerometer data in a single blocking call.

Reads 6 raw bytes and applies sensitivity scaling.

Note
Assumes config->read() is blocking (data is in the buffer on return).
Parameters
configDriver configuration.
Accel_DataOutput struct for processed accel values (g).
Returns
0 on success, -1 on failure.

References MPU6500_Config::Accel_Setting, MPU6500_I2C_ADDR, MPU6500_REG_ACCEL_MEASURE, and MPU6500_Config::read.

◆ MPU6500_Read_Gyro_Data()

int8_t MPU6500_Read_Gyro_Data ( MPU6500_Config config,
MPU6500_Gyro_Data Gyro_Data 
)

Read and process gyroscope data in a single blocking call.

Reads 6 raw bytes, applies sensitivity scaling and calibration offsets.

Note
Assumes config->read() is blocking (data is in the buffer on return).
Parameters
configDriver configuration.
Gyro_DataOutput struct for processed gyro values (dps).
Returns
0 on success, -1 on failure.

References MPU6500_Config::Gyro_Offset_Calibration, MPU6500_Config::Gyro_Setting, MPU6500_I2C_ADDR, MPU6500_REG_GYRO_MEASURE, and MPU6500_Config::read.

◆ MPU6500_SetAccelRange()

int8_t MPU6500_SetAccelRange ( MPU6500_Config config,
Accel_Range  range 
)

Set the accelerometer full-scale range.

Parameters
configDriver configuration.
rangeDesired range (2G, 4G, 8G, or 16G).
Returns
0 on success, -1 on failure.

References MPU6500_Config::Accel_Setting, MPU6500_Config::delay_ms, MPU6500_I2C_ADDR, MPU6500_Config::read, and MPU6500_Config::write.

◆ MPU6500_SetRotationRange()

int8_t MPU6500_SetRotationRange ( MPU6500_Config config,
Gyro_Range  range 
)

Set the gyroscope full-scale range.

Parameters
configDriver configuration.
rangeDesired range (250, 500, 1000, or 2000 dps).
Returns
0 on success, -1 on failure.

References MPU6500_Config::delay_ms, MPU6500_Config::Gyro_Setting, MPU6500_I2C_ADDR, MPU6500_Config::read, and MPU6500_Config::write.