Device driver for the Honeywell HMC5883L 3-axis digital compass. More...
Device driver for the Honeywell HMC5883L 3-axis digital compass.
The driver implements basic polling mode. The application can use different approaches to get new data, either
The data-ready interrupt (DRDY) is only be available when module hmc5883l_int
is enabled.
This driver provides [S]ensor [A]ctuator [U]ber [L]ayer capabilities.
Files | |
file | hmc5883l_params.h |
Default configuration for the Honeywell HMC5883L 3-axis digital compass. | |
file | hmc5883l_regs.h |
Register definitions for the Honeywell HMC5883L 3-axis digital compass. | |
file | hmc5883l.h |
Data Structures | |
struct | hmc5883l_data_t |
Magnetic field values in milli-Gauss (mGs) More... | |
struct | hmc5883l_raw_data_t |
Raw data set as two complements. More... | |
struct | hmc5883l_params_t |
HMC5883L device initialization parameters. More... | |
struct | hmc5883l_t |
HMC5883L sensor device data structure type. More... | |
Typedefs | |
typedef void(* | hmc5883l_drdy_int_cb_t) (void *) |
HMC5883L DRDY interrupt callback function type. More... | |
Functions | |
int | hmc5883l_init (hmc5883l_t *dev, const hmc5883l_params_t *params) |
Initialize the HMC5883L sensor device. More... | |
int | hmc5883l_init_int (hmc5883l_t *dev, hmc5883l_drdy_int_cb_t cb, void *arg) |
Initialize and activate the DRDY interrupt of HMC5883L sensor device. More... | |
int | hmc5883l_data_ready (const hmc5883l_t *dev) |
Data-ready status function. More... | |
int | hmc5883l_read (const hmc5883l_t *dev, hmc5883l_data_t *data) |
Read one sample of magnetic field values in milli-Gauss (mGs) More... | |
int | hmc5883l_read_raw (const hmc5883l_t *dev, hmc5883l_raw_data_t *raw) |
Read one sample of raw sensor data as 16 bit two's complements. More... | |
int | hmc5883l_power_down (hmc5883l_t *dev) |
Power down the sensor. More... | |
int | hmc5883l_power_up (hmc5883l_t *dev) |
Power up the sensor. More... | |
typedef void(* hmc5883l_drdy_int_cb_t) (void *) |
HMC5883L DRDY interrupt callback function type.
Function prototype for the function which is called on DRDY interrupt if the interrupt is activated by hmc5883l_init_int and the interrupt pin is defined in device initialization parameters.
cb
function is called in interrupt context. The application should do nothing time consuming and not directly access sensor data. Definition at line 151 of file hmc5883l.h.
enum hmc5883l_dor_t |
Data output rates (DOR)
The values correspond to bits <4:2> of the HMC5883L_REG_CFG_A register.
Enumerator | |
---|---|
HMC5883L_DOR_0_75 | 0.75 Hz |
HMC5883L_DOR_1_5 | 1.5 Hz |
HMC5883L_DOR_3 | 3 Hz |
HMC5883L_DOR_7_5 | 7.5 Hz |
HMC5883L_DOR_15 | 15 Hz (default) |
HMC5883L_DOR_30 | 30 Hz |
HMC5883L_DOR_75 | 75 Hz |
Definition at line 61 of file hmc5883l.h.
Definition of error codes.
Definition at line 47 of file hmc5883l.h.
enum hmc5883l_gain_t |
Gain (determines the sensitivity and the range)
The values correspond to bits <7:5> of the HMC5883L_REG_CFG_B_GN register.
Definition at line 110 of file hmc5883l.h.
enum hmc5883l_meas_avg_t |
Measurement avaraging (number of samples are averaged for output)
The values correspond to bits <6:5> of the HMC5883L_REG_CFG_A register.
Enumerator | |
---|---|
HMC5883L_MEAS_AVG_NONE | No averaging. |
HMC5883L_MEAS_AVG_2 | 2 samples are averaged |
HMC5883L_MEAS_AVG_4 | 4 samples are averaged |
HMC5883L_MEAS_AVG_8 | 8 samples are averaged |
Definition at line 87 of file hmc5883l.h.
enum hmc5883l_meas_mode_t |
Measurement modes.
The values correspond to bits <1:0> of the HMC5883L_REG_CFG_A register.
Enumerator | |
---|---|
HMC5883L_MEAS_MODE_NORMAL | Normal measurement config. |
HMC5883L_MEAS_MODE_BIAS_POS | Positive bias config for all axes. |
HMC5883L_MEAS_MODE_BIAS_NEG | Negative bias config for all axes. |
Definition at line 76 of file hmc5883l.h.
enum hmc5883l_op_mode_t |
Operation modes.
Values correspond to bits <1:0> of HMC5883L_REG_MODE register
Enumerator | |
---|---|
HMC5883L_OP_MODE_CONTINUOUS | Continuous measurement. |
HMC5883L_OP_MODE_SINGLE | Single measurement. |
HMC5883L_OP_MODE_IDLE | Idle mode. |
Definition at line 99 of file hmc5883l.h.
int hmc5883l_data_ready | ( | const hmc5883l_t * | dev | ) |
Data-ready status function.
The function checks the status register and returns
[in] | dev | device descriptor of HMC5883L sensor |
HMC5883L_OK | new data available |
HMC5883L_ERROR_NO_DATA | no new data available |
HMC5883L_ERROR_* | negative error code, see hmc5883l_error_codes_t |
int hmc5883l_init | ( | hmc5883l_t * | dev, |
const hmc5883l_params_t * | params | ||
) |
Initialize the HMC5883L sensor device.
This function resets the sensor and initializes the sensor according to given initialization parameters. All registers are reset to default values.
[in] | dev | device descriptor of HMC5883L sensor to be initialized |
[in] | params | HMC5883L initialization parameters |
HMC5883L_OK | on success |
HMC5883L_ERROR_* | a negative error code on error, see hmc5883l_error_codes_t |
int hmc5883l_init_int | ( | hmc5883l_t * | dev, |
hmc5883l_drdy_int_cb_t | cb, | ||
void * | arg | ||
) |
Initialize and activate the DRDY interrupt of HMC5883L sensor device.
This function activates the DRDY interrupt and initializes the pin defined as the interrupt pin in the initialization parameters of the device. The cb
parameter specifies the function, along with an optional argument arg
, which is called when a DRDY interrupt is triggered.
cb
is executed in interrupt context. Make sure not to call any driver API function in that context. hmc5883l_int
is enabled.[in] | dev | device descriptor of HMC5883L sensor |
[in] | cb | function called when DRDY interrupt is triggered |
[in] | arg | argument for the callback function |
HMC5883L_OK | on success |
HMC5883L_ERROR_* | a negative error code on error, see hmc5883l_error_codes_t |
int hmc5883l_power_down | ( | hmc5883l_t * | dev | ) |
Power down the sensor.
Changes the sensor operation mode to HMC5883L_OP_MODE_IDLE in which almost all internal blocks are switched off. I2C interface is still active. The content of the configuration registers is preserved.
[in] | dev | Device descriptor of HMC5883L device to read from |
HMC5883L_OK | on success |
HMC5883L_ERROR_* | negative error code, see hmc5883l_error_codes_t |
int hmc5883l_power_up | ( | hmc5883l_t * | dev | ) |
Power up the sensor.
Swichtes the sensor back into the last active operation mode.
[in] | dev | Device descriptor of HMC5883L device to read from |
HMC5883L_OK | on success |
HMC5883L_ERROR_* | negative error code, see hmc5883l_error_codes_t |
int hmc5883l_read | ( | const hmc5883l_t * | dev, |
hmc5883l_data_t * | data | ||
) |
Read one sample of magnetic field values in milli-Gauss (mGs)
Raw magnetometer data are read from the sensor and normalized them with respect to configured gain. Magnetic field values are given in milli-Gauss (mGs) to preserve full resolution:
[in] | dev | device descriptor of HMC5883L sensor |
[out] | data | result vector in milli-Gauss (mGs) per axis |
HMC5883L_OK | on success |
HMC5883L_ERROR_* | a negative error code on error, see hmc5883l_error_codes_t |
int hmc5883l_read_raw | ( | const hmc5883l_t * | dev, |
hmc5883l_raw_data_t * | raw | ||
) |
Read one sample of raw sensor data as 16 bit two's complements.
[in] | dev | device descriptor of HMC5883L sensor |
raw | raw data vector |
HMC5883L_OK | on success |
HMC5883L_ERROR_* | a negative error code on error, see hmc5883l_error_codes_t |