| LibDriver MPU9250 1.0.0 MPU9250 full function driver

Enumerations | Functions
mpu9250 magnetometer driver function
mpu9250 driver function

mpu9250 magnetometer driver modules More...

## Enumerations
enum | mpu9250_magnetometer_status1_t { MPU9250_MAGNETOMETER_STATUS1_DRDY = (1 << 0) , MPU9250_MAGNETOMETER_STATUS1_DOR = (1 << 1) }
| mpu9250 magnetometer status1 enumeration definition More...
enum | mpu9250_magnetometer_status2_t { MPU9250_MAGNETOMETER_STATUS2_HOFL = (1 << 3) , MPU9250_MAGNETOMETER_STATUS2_BITM = (1 << 4) }
| mpu9250 magnetometer status2 enumeration definition More...
enum | mpu9250_magnetometer_mode_t { MPU9250_MAGNETOMETER_MODE_POWER_DOWN = 0x00 , MPU9250_MAGNETOMETER_MODE_SINGLE = 0x01 , MPU9250_MAGNETOMETER_MODE_CONTINUOUS1 = 0x02 , MPU9250_MAGNETOMETER_MODE_CONTINUOUS2 = 0x06 , MPU9250_MAGNETOMETER_MODE_EXT_TRIGGER = 0x04 , MPU9250_MAGNETOMETER_MODE_SELF_TEST = 0x08 , MPU9250_MAGNETOMETER_MODE_FUSE_ROM = 0x0F }
| mpu9250 magnetometer mode enumeration definition More...
enum | mpu9250_magnetometer_bits_t { MPU9250_MAGNETOMETER_BITS_14 = 0x00 , MPU9250_MAGNETOMETER_BITS_16 = 0x01 }
| mpu9250 magnetometer bits enumeration definition More...

## Functions
uint8_t | mpu9250_mag_init (mpu9250_handle_t *handle)
| initialize the magnetometer of mpu9250 More...
uint8_t | mpu9250_mag_deinit (mpu9250_handle_t *handle)
| magnetometer deinit More...
uint8_t | mpu9250_mag_read (mpu9250_handle_t *handle, int16_t mag_raw[3], float mag_ut[3])
| mag read the data More...
uint8_t | mpu9250_mag_get_info (mpu9250_handle_t *handle, uint8_t *info)
| magnetometer get the information More...
uint8_t | mpu9250_mag_get_status1 (mpu9250_handle_t *handle, uint8_t *status)
| magnetometer get the status1 More...
uint8_t | mpu9250_mag_get_status2 (mpu9250_handle_t *handle, uint8_t *status)
| magnetometer get the status2 More...
uint8_t | mpu9250_mag_set_mode (mpu9250_handle_t *handle, mpu9250_magnetometer_mode_t mode)
| magnetometer set the mode More...
uint8_t | mpu9250_mag_get_mode (mpu9250_handle_t *handle, mpu9250_magnetometer_mode_t *mode)
| magnetometer get the mode More...
uint8_t | mpu9250_mag_set_bits (mpu9250_handle_t *handle, mpu9250_magnetometer_bits_t bits)
| magnetometer set the bits More...
uint8_t | mpu9250_mag_get_bits (mpu9250_handle_t *handle, mpu9250_magnetometer_bits_t *bits)
| magnetometer get the bits More...
uint8_t | mpu9250_mag_set_reset (mpu9250_handle_t *handle, mpu9250_bool_t enable)
| magnetometer enable or disable reset More...
uint8_t | mpu9250_mag_get_reset (mpu9250_handle_t *handle, mpu9250_bool_t *enable)
| magnetometer get the reset status More...
uint8_t | mpu9250_mag_set_self_test (mpu9250_handle_t *handle, mpu9250_bool_t enable)
| magnetometer enable or disable self test More...
uint8_t | mpu9250_mag_get_self_test (mpu9250_handle_t *handle, mpu9250_bool_t *enable)
| magnetometer get the self test status More...
uint8_t | mpu9250_mag_iic_disable (mpu9250_handle_t *handle)
| magnetometer disable the iic More...
uint8_t | mpu9250_mag_get_asa (mpu9250_handle_t *handle, uint8_t asa[3])
| magnetometer get the asa data More...
uint8_t | mpu9250_mag_set_fifo_mode (mpu9250_handle_t *handle)
| magnetometer set into fifo mode More...

## Detailed Description

mpu9250 magnetometer driver modules

## Enumeration Type Documentation

## ◆ mpu9250_magnetometer_bits_t

enum mpu9250_magnetometer_bits_t

mpu9250 magnetometer bits enumeration definition

Enumerator
MPU9250_MAGNETOMETER_BITS_14 | 14 bits output
MPU9250_MAGNETOMETER_BITS_16 | 16 bits output

Definition at line 425 of file driver_mpu9250.h.

## ◆ mpu9250_magnetometer_mode_t

enum mpu9250_magnetometer_mode_t

mpu9250 magnetometer mode enumeration definition

Enumerator
MPU9250_MAGNETOMETER_MODE_POWER_DOWN | power down mode
MPU9250_MAGNETOMETER_MODE_SINGLE | single measurement mode
MPU9250_MAGNETOMETER_MODE_CONTINUOUS1 | continuous measurement mode 1
MPU9250_MAGNETOMETER_MODE_CONTINUOUS2 | continuous measurement mode 2
MPU9250_MAGNETOMETER_MODE_EXT_TRIGGER | external trigger measurement mode
MPU9250_MAGNETOMETER_MODE_SELF_TEST | self test mode
MPU9250_MAGNETOMETER_MODE_FUSE_ROM | fuse rom access mode

Definition at line 411 of file driver_mpu9250.h.

## ◆ mpu9250_magnetometer_status1_t

enum mpu9250_magnetometer_status1_t

mpu9250 magnetometer status1 enumeration definition

Enumerator
MPU9250_MAGNETOMETER_STATUS1_DRDY | data is ready
MPU9250_MAGNETOMETER_STATUS1_DOR | data overrun

Definition at line 393 of file driver_mpu9250.h.

## ◆ mpu9250_magnetometer_status2_t

enum mpu9250_magnetometer_status2_t

mpu9250 magnetometer status2 enumeration definition

Enumerator
MPU9250_MAGNETOMETER_STATUS2_HOFL | magnetic sensor overflow occurred
MPU9250_MAGNETOMETER_STATUS2_BITM | 0: 14bits / 1: 16bits

Definition at line 402 of file driver_mpu9250.h.

## Function Documentation

## ◆ mpu9250_mag_deinit()

uint8_t mpu9250_mag_deinit | ( | mpu9250_handle_t * | handle | ) |

magnetometer deinit

Parameters

  [in] | *handle | points to an mpu9250 handle structure

Returns
  status code
  - 0 success
  - 1 mag deinit failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 mag is not inited

Note
  none

Definition at line 4894 of file driver_mpu9250.c.

## ◆ mpu9250_mag_get_asa()

uint8_t mpu9250_mag_get_asa | ( | mpu9250_handle_t * | handle,
|  | uint8_t | asa[3]
| ) |  |

magnetometer get the asa data

Parameters

  [in] | *handle | points to an mpu9250 handle structure
  [out] | *asa | points to an asa buffer

Returns
  status code
  - 0 success
  - 1 mag get asa failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 mag is not inited

Note
  none

Definition at line 5613 of file driver_mpu9250.c.

## ◆ mpu9250_mag_get_bits()

uint8_t mpu9250_mag_get_bits | ( | mpu9250_handle_t * | handle,
|  | mpu9250_magnetometer_bits_t * | bits
| ) |  |

magnetometer get the bits

Parameters

  [in] | *handle | points to an mpu9250 handle structure
  [out] | *bits | points to a magnetometer bits buffer

Returns
  status code
  - 0 success
  - 1 mag get bits failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 mag is not inited

Note
  none

Definition at line 5334 of file driver_mpu9250.c.

## ◆ mpu9250_mag_get_info()

uint8_t mpu9250_mag_get_info | ( | mpu9250_handle_t * | handle,
|  | uint8_t * | info
| ) |  |

magnetometer get the information

Parameters

  [in] | *handle | points to an mpu9250 handle structure
  [out] | *info | points to an info buffer

Returns
  status code
  - 0 success
  - 1 mag get info failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 mag is not inited

Note
  none

Definition at line 5060 of file driver_mpu9250.c.

## ◆ mpu9250_mag_get_mode()

uint8_t mpu9250_mag_get_mode | ( | mpu9250_handle_t * | handle,
|  | mpu9250_magnetometer_mode_t * | mode
| ) |  |

magnetometer get the mode

Parameters

  [in] | *handle | points to an mpu9250 handle structure
  [out] | *mode | points to a magnetometer mode buffer

Returns
  status code
  - 0 success
  - 1 mag get mode failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 mag is not inited

Note
  none

Definition at line 5238 of file driver_mpu9250.c.

## ◆ mpu9250_mag_get_reset()

uint8_t mpu9250_mag_get_reset | ( | mpu9250_handle_t * | handle,
|  | mpu9250_bool_t * | enable
| ) |  |

magnetometer get the reset status

Parameters

  [in] | *handle | points to an mpu9250 handle structure
  [out] | *enable | points to a bool value buffer

Returns
  status code
  - 0 success
  - 1 mag get reset failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 mag is not inited

Note
  none

Definition at line 5430 of file driver_mpu9250.c.

## ◆ mpu9250_mag_get_self_test()

uint8_t mpu9250_mag_get_self_test | ( | mpu9250_handle_t * | handle,
|  | mpu9250_bool_t * | enable
| ) |  |

magnetometer get the self test status

Parameters

  [in] | *handle | points to an mpu9250 handle structure
  [out] | *enable | points to a bool value buffer

Returns
  status code
  - 0 success
  - 1 mag get self test failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 mag is not inited

Note
  none

Definition at line 5526 of file driver_mpu9250.c.

## ◆ mpu9250_mag_get_status1()

uint8_t mpu9250_mag_get_status1 | ( | mpu9250_handle_t * | handle,
|  | uint8_t * | status
| ) |  |

magnetometer get the status1

Parameters

  [in] | *handle | points to an mpu9250 handle structure
  [out] | *status | points to a status1 buffer

Returns
  status code
  - 0 success
  - 1 mag get status1 failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 mag is not inited

Note
  none

Definition at line 5102 of file driver_mpu9250.c.

## ◆ mpu9250_mag_get_status2()

uint8_t mpu9250_mag_get_status2 | ( | mpu9250_handle_t * | handle,
|  | uint8_t * | status
| ) |  |

magnetometer get the status2

Parameters

  [in] | *handle | points to an mpu9250 handle structure
  [out] | *status | points to a status2 buffer

Returns
  status code
  - 0 success
  - 1 mag get status2 failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 mag is not inited

Note
  none

Definition at line 5144 of file driver_mpu9250.c.

## ◆ mpu9250_mag_iic_disable()

uint8_t mpu9250_mag_iic_disable | ( | mpu9250_handle_t * | handle | ) |

magnetometer disable the iic

Parameters

  [in] | *handle | points to an mpu9250 handle structure

Returns
  status code
  - 0 success
  - 1 mag iic disable failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 mag is not inited

Note
  none

Definition at line 5569 of file driver_mpu9250.c.

## ◆ mpu9250_mag_init()

uint8_t mpu9250_mag_init | ( | mpu9250_handle_t * | handle | ) |

initialize the magnetometer of mpu9250

Parameters

  [in] | *handle | points to an mpu9250 handle structure

Returns
  status code
  - 0 success
  - 1 mag init failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 reset failed
  - 5 mag id is invalid
  - 6 spi don't support

Note
  none

Definition at line 4742 of file driver_mpu9250.c.

## ◆ mpu9250_mag_read()

uint8_t mpu9250_mag_read | ( | mpu9250_handle_t * | handle,
|  | int16_t | mag_raw[3],
|  | float | mag_ut[3]
| ) |  |

mag read the data

Parameters

  [in] | *handle | points to an mpu9250 handle structure
  [out] | *mag_raw | points to a mag raw data buffer
  [out] | *mag_ut | points to a converted mag data buffer

Returns
  status code
  - 0 success
  - 1 mag read failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 mag is not inited

Note
  none

Definition at line 4995 of file driver_mpu9250.c.

## ◆ mpu9250_mag_set_bits()

uint8_t mpu9250_mag_set_bits | ( | mpu9250_handle_t * | handle,
|  | mpu9250_magnetometer_bits_t | bits
| ) |  |

magnetometer set the bits

Parameters

  [in] | *handle | points to an mpu9250 handle structure
  [in] | bits | is the magnetometer bits

Returns
  status code
  - 0 success
  - 1 mag set bits failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 mag is not inited

Note
  none

Definition at line 5282 of file driver_mpu9250.c.

## ◆ mpu9250_mag_set_fifo_mode()

uint8_t mpu9250_mag_set_fifo_mode | ( | mpu9250_handle_t * | handle | ) |

magnetometer set into fifo mode

Parameters

  [in] | *handle | points to an mpu9250 handle structure

Returns
  status code
  - 0 success
  - 1 mag set fifo mode failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 mag is not inited

Note
  fifo mode will use slave 0

Definition at line 5654 of file driver_mpu9250.c.

## ◆ mpu9250_mag_set_mode()

uint8_t mpu9250_mag_set_mode | ( | mpu9250_handle_t * | handle,
|  | mpu9250_magnetometer_mode_t | mode
| ) |  |

magnetometer set the mode

Parameters

  [in] | *handle | points to an mpu9250 handle structure
  [in] | mode | is the magnetometer mode

Returns
  status code
  - 0 success
  - 1 mag set mode failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 mag is not inited

Note
  none

Definition at line 5186 of file driver_mpu9250.c.

## ◆ mpu9250_mag_set_reset()

uint8_t mpu9250_mag_set_reset | ( | mpu9250_handle_t * | handle,
|  | mpu9250_bool_t | enable
| ) |  |

magnetometer enable or disable reset

Parameters

  [in] | *handle | points to an mpu9250 handle structure
  [in] | enable | is a bool value

Returns
  status code
  - 0 success
  - 1 mag set reset failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 mag is not inited

Note
  none

Definition at line 5378 of file driver_mpu9250.c.

## ◆ mpu9250_mag_set_self_test()

uint8_t mpu9250_mag_set_self_test | ( | mpu9250_handle_t * | handle,
|  | mpu9250_bool_t | enable
| ) |  |

magnetometer enable or disable self test

Parameters

  [in] | *handle | points to an mpu9250 handle structure
  [in] | enable | is a bool value

Returns
  status code
  - 0 success
  - 1 mag set self test failed
  - 2 handle is NULL
  - 3 handle is not initialized
  - 4 mag is not inited

Note
  none

Definition at line 5474 of file driver_mpu9250.c.