Atmel Software Framework

hmc5883l.h File Reference

Honeywell HMC5883L 3-axis magnetometer.

This file contains functions for initializing and reading data from a Honeywell HMC5883L 3-axis magnetometer.

Copyright (c) 2014-2015 Atmel Corporation. All rights reserved.

#include <asf.h>

Macros

#define HMC5883L_DATA_RESOLUTION   (12)
 
#define HMC5883L_TWI_ADDR   (0x1e)
 
#define SCALE_0_9GA   (1370) /* 0.9 Ga (1370 counts / Gauss) */
 Data scaling - varies by range/gain setting. More...
 
#define SCALE_1_3GA   (1090) /* 1.3 Ga (1090 counts / Gauss) */
 
#define SCALE_1_9GA   (820) /* 1.9 Ga (820 counts / Gauss) */
 
#define SCALE_2_5GA   (660) /* 2.5 Ga (660 counts / Gauss) */
 
#define SCALE_4_0GA   (440) /* 4.0 Ga (440 counts / Gauss) */
 
#define SCALE_4_7GA   (390) /* 4.7 Ga (390 counts / Gauss) */
 
#define SCALE_5_6GA   (330) /* 5.6 Ga (330 counts / Gauss) */
 
#define SCALE_8_1GA   (230) /* 8.1 Ga (230 counts / Gauss) */
 
#define ID_A_DEFAULT   (0x48) /* normal value of ID register A */
 Device ID Definitions. More...
 
#define ID_B_DEFAULT   (0x34) /* normal value of ID register B */
 
#define ID_C_DEFAULT   (0x33) /* normal value of ID register C */
 
#define HMC5883L_DEV_ID   (0x483433) /* combined ID value */
 
#define HMC5883L_CONFIG_REG_A   (0x00) /* configuration register A */
 HMC5883L Register Addresses. More...
 
#define HMC5883L_CONFIG_REG_B   (0x01) /* configuration register B */
 
#define HMC5883L_MODE_REG   (0x02) /* mode register */
 
#define HMC5883L_MAG_X_HI   (0x03) /* X mag reading - MSB */
 
#define HMC5883L_MAG_X_LO   (0x04) /* X mag reading - LSB */
 
#define HMC5883L_MAG_Z_HI   (0x05) /* Z mag reading - MSB */
 
#define HMC5883L_MAG_Z_LO   (0x06) /* Z mag reading - LSB */
 
#define HMC5883L_MAG_Y_HI   (0x07) /* Y mag reading - MSB */
 
#define HMC5883L_MAG_Y_LO   (0x08) /* Y mag reading - LSB */
 
#define HMC5883L_STATUS_REG   (0x09) /* device status */
 
#define HMC5883L_ID_REG_A   (0x0a) /* ID register A */
 
#define HMC5883L_ID_REG_B   (0x0b) /* ID register B */
 
#define HMC5883L_ID_REG_C   (0x0c) /* ID register C */
 
#define MEAS_MODE   (0x03) /* measurement mode mask (2 bits) */
 HMC5883L Register Bit Definitions. More...
 
#define MEAS_MODE_NORM   (0x00) /* normal measurement mode */
 
#define MEAS_MODE_POS   (0x01) /* positive bias */
 
#define MEAS_MODE_NEG   (0x02) /* negative bias */
 
#define DATA_RATE   (0x1c) /* data rate mask (3 bits) */
 
#define DATA_RATE_0_75HZ   (0x00) /* 0.75 Hz */
 
#define DATA_RATE_1_5HZ   (0x04) /* 1.5 Hz */
 
#define DATA_RATE_3HZ   (0x08) /* 3 Hz */
 
#define DATA_RATE_7_5HZ   (0x0c) /* 7.5 Hz */
 
#define DATA_RATE_15HZ   (0x10) /* 15 Hz */
 
#define DATA_RATE_30HZ   (0x14) /* 30 Hz */
 
#define DATA_RATE_75HZ   (0x18) /* 75 Hz */
 
#define MEAS_AVG   (0x60) /* sample average mask (2 bits) */
 
#define MEAS_AVG_1   (0x00) /* output = 1 sample (no avg.) */
 
#define MEAS_AVG_2   (0x20) /* output = 2 samples averaged */
 
#define MEAS_AVG_4   (0x40) /* output = 4 samples averaged */
 
#define MEAS_AVG_8   (0x60) /* output = 8 samples averaged */
 
#define GAIN_0_9GA   (0x00) /* +/- 0.9 Ga (1370 counts/ Gauss) */
 
#define GAIN_1_3GA   (0x20) /* +/- 1.3 Ga (1090 counts/ Gauss) */
 
#define GAIN_1_9GA   (0x40) /* +/- 1.9 Ga (820 counts / Gauss) */
 
#define GAIN_2_5GA   (0x60) /* +/- 2.5 Ga (660 counts / Gauss) */
 
#define GAIN_4_0GA   (0x80) /* +/- 4.0 Ga (440 counts / Gauss) */
 
#define GAIN_4_7GA   (0xa0) /* +/- 4.7 Ga (390 counts / Gauss) */
 
#define GAIN_5_6GA   (0xc0) /* +/- 5.6 Ga (330 counts / Gauss) */
 
#define GAIN_8_1GA   (0xe0) /* +/- 8.1 Ga (230 counts / Gauss) */
 
#define MODE_CONTIN   (0x00) /* continuous conversion mode */
 
#define MODE_SINGLE   (0x01) /* single measurement mode */
 
#define MODE_IDLE   (0x02) /* idle mode */
 
#define MODE_SLEEP   (0x03) /* sleep mode */
 
#define STATUS_RDY   (0x01) /* data ready */
 
#define STATUS_LOCK   (0x02) /* data output locked */
 
#define HMC5883L_TEST_GAIN   GAIN_2_5GA /* gain value during self-test */
 
#define HMC5883L_TEST_X_MIN   550 /* min X */
 
#define HMC5883L_TEST_X_NORM   766 /* normal X */
 
#define HMC5883L_TEST_X_MAX   850 /* max X */
 
#define HMC5883L_TEST_Y_MIN   550 /* min Y */
 
#define HMC5883L_TEST_Y_NORM   766 /* normal Y */
 
#define HMC5883L_TEST_Y_MAX   850 /* max Y */
 
#define HMC5883L_TEST_Z_MIN   550 /* min Z */
 
#define HMC5883L_TEST_Z_NORM   713 /* normal Z */
 
#define HMC5883L_TEST_Z_MAX   850 /* max Z */
 

Functions

bool hmc5883l_init (sensor_t *, int)
 Honeywell HMC5883L magnetometer driver initialization. More...
 

#define DATA_RATE   (0x1c) /* data rate mask (3 bits) */

Referenced by hmc5883l_set_bandwidth().

#define DATA_RATE_0_75HZ   (0x00) /* 0.75 Hz */
#define DATA_RATE_15HZ   (0x10) /* 15 Hz */

Referenced by hmc5883l_init(), and hmc5883l_selftest().

#define DATA_RATE_1_5HZ   (0x04) /* 1.5 Hz */
#define DATA_RATE_30HZ   (0x14) /* 30 Hz */
#define DATA_RATE_3HZ   (0x08) /* 3 Hz */
#define DATA_RATE_75HZ   (0x18) /* 75 Hz */
#define DATA_RATE_7_5HZ   (0x0c) /* 7.5 Hz */
#define GAIN_0_9GA   (0x00) /* +/- 0.9 Ga (1370 counts/ Gauss) */
#define GAIN_1_3GA   (0x20) /* +/- 1.3 Ga (1090 counts/ Gauss) */
#define GAIN_1_9GA   (0x40) /* +/- 1.9 Ga (820 counts / Gauss) */
#define GAIN_2_5GA   (0x60) /* +/- 2.5 Ga (660 counts / Gauss) */
#define GAIN_4_0GA   (0x80) /* +/- 4.0 Ga (440 counts / Gauss) */
#define GAIN_4_7GA   (0xa0) /* +/- 4.7 Ga (390 counts / Gauss) */
#define GAIN_5_6GA   (0xc0) /* +/- 5.6 Ga (330 counts / Gauss) */
#define GAIN_8_1GA   (0xe0) /* +/- 8.1 Ga (230 counts / Gauss) */
#define HMC5883L_CONFIG_REG_A   (0x00) /* configuration register A */

HMC5883L Register Addresses.

Referenced by hmc5883l_init(), hmc5883l_selftest(), and hmc5883l_set_bandwidth().

#define HMC5883L_CONFIG_REG_B   (0x01) /* configuration register B */
#define HMC5883L_DATA_RESOLUTION   (12)

Referenced by hmc5883l_init().

#define HMC5883L_DEV_ID   (0x483433) /* combined ID value */

Referenced by hmc5883l_init().

#define HMC5883L_ID_REG_A   (0x0a) /* ID register A */

Referenced by hmc5883l_device_id().

#define HMC5883L_ID_REG_B   (0x0b) /* ID register B */
#define HMC5883L_ID_REG_C   (0x0c) /* ID register C */
#define HMC5883L_MAG_X_HI   (0x03) /* X mag reading - MSB */

Referenced by hmc5883l_get_data().

#define HMC5883L_MAG_X_LO   (0x04) /* X mag reading - LSB */
#define HMC5883L_MAG_Y_HI   (0x07) /* Y mag reading - MSB */
#define HMC5883L_MAG_Y_LO   (0x08) /* Y mag reading - LSB */
#define HMC5883L_MAG_Z_HI   (0x05) /* Z mag reading - MSB */
#define HMC5883L_MAG_Z_LO   (0x06) /* Z mag reading - LSB */
#define HMC5883L_MODE_REG   (0x02) /* mode register */
#define HMC5883L_STATUS_REG   (0x09) /* device status */
#define HMC5883L_TEST_GAIN   GAIN_2_5GA /* gain value during self-test */

Referenced by hmc5883l_selftest().

#define HMC5883L_TEST_X_MAX   850 /* max X */

Referenced by hmc5883l_selftest().

#define HMC5883L_TEST_X_MIN   550 /* min X */

Referenced by hmc5883l_selftest().

#define HMC5883L_TEST_X_NORM   766 /* normal X */

Referenced by hmc5883l_calibrate().

#define HMC5883L_TEST_Y_MAX   850 /* max Y */

Referenced by hmc5883l_selftest().

#define HMC5883L_TEST_Y_MIN   550 /* min Y */

Referenced by hmc5883l_selftest().

#define HMC5883L_TEST_Y_NORM   766 /* normal Y */

Referenced by hmc5883l_calibrate().

#define HMC5883L_TEST_Z_MAX   850 /* max Z */

Referenced by hmc5883l_selftest().

#define HMC5883L_TEST_Z_MIN   550 /* min Z */

Referenced by hmc5883l_selftest().

#define HMC5883L_TEST_Z_NORM   713 /* normal Z */

Referenced by hmc5883l_calibrate().

#define HMC5883L_TWI_ADDR   (0x1e)
#define ID_A_DEFAULT   (0x48) /* normal value of ID register A */

Device ID Definitions.

#define ID_B_DEFAULT   (0x34) /* normal value of ID register B */
#define ID_C_DEFAULT   (0x33) /* normal value of ID register C */
#define MEAS_AVG   (0x60) /* sample average mask (2 bits) */
#define MEAS_AVG_1   (0x00) /* output = 1 sample (no avg.) */

Referenced by hmc5883l_selftest().

#define MEAS_AVG_2   (0x20) /* output = 2 samples averaged */
#define MEAS_AVG_4   (0x40) /* output = 4 samples averaged */
#define MEAS_AVG_8   (0x60) /* output = 8 samples averaged */
#define MEAS_MODE   (0x03) /* measurement mode mask (2 bits) */

HMC5883L Register Bit Definitions.

#define MEAS_MODE_NEG   (0x02) /* negative bias */

Referenced by hmc5883l_selftest().

#define MEAS_MODE_NORM   (0x00) /* normal measurement mode */

Referenced by hmc5883l_init().

#define MEAS_MODE_POS   (0x01) /* positive bias */

Referenced by hmc5883l_selftest().

#define MODE_CONTIN   (0x00) /* continuous conversion mode */

Referenced by hmc5883l_init().

#define MODE_IDLE   (0x02) /* idle mode */
#define MODE_SINGLE   (0x01) /* single measurement mode */
#define MODE_SLEEP   (0x03) /* sleep mode */
#define SCALE_0_9GA   (1370) /* 0.9 Ga (1370 counts / Gauss) */

Data scaling - varies by range/gain setting.

#define SCALE_1_3GA   (1090) /* 1.3 Ga (1090 counts / Gauss) */
#define SCALE_1_9GA   (820) /* 1.9 Ga (820 counts / Gauss) */
#define SCALE_2_5GA   (660) /* 2.5 Ga (660 counts / Gauss) */
#define SCALE_4_0GA   (440) /* 4.0 Ga (440 counts / Gauss) */
#define SCALE_4_7GA   (390) /* 4.7 Ga (390 counts / Gauss) */
#define SCALE_5_6GA   (330) /* 5.6 Ga (330 counts / Gauss) */
#define SCALE_8_1GA   (230) /* 8.1 Ga (230 counts / Gauss) */
#define STATUS_LOCK   (0x02) /* data output locked */
#define STATUS_RDY   (0x01) /* data ready */