MAG3110 3-Axis Digital Magnetometer

Driver for the Freescale MAG3110 magnetometer.

After initialization and set activ the magnetometer will make measurements at periodic times. The output rate and over sample ratio can be determined by magnetometer initialization. The measured values of magnetic field strength and die temperature have uncalibrated offsets. To get correct measurement values, the individual offsets must be measured and set accordingly.

This driver provides [S]ensor [A]ctuator [U]ber [L]ayer capabilities.

MAG3110_DROS_8000_16

Output Rate 80 Hz, Over Sample Ratio 16.

1
0
MAG3110_DROS_4000_32

Output Rate 40 Hz, Over Sample Ratio 32.

1
1
MAG3110_DROS_2000_64

Output Rate 20 Hz, Over Sample Ratio 64.

1
2
MAG3110_DROS_1000_128

Output Rate 10 Hz, Over Sample Ratio 128.

1
3
MAG3110_DROS_4000_16

Output Rate 40 Hz, Over Sample Ratio 16.

1
4
MAG3110_DROS_2000_32

Output Rate 20 Hz, Over Sample Ratio 32.

1
5
MAG3110_DROS_1000_64

Output Rate 10 Hz, Over Sample Ratio 64.

1
6
MAG3110_DROS_0500_128

Output Rate 5 Hz, Over Sample Ratio 128.

1
7
MAG3110_DROS_2000_16

Output Rate 20 Hz, Over Sample Ratio 16.

1
8
MAG3110_DROS_1000_32

Output Rate 10 Hz, Over Sample Ratio 32.

1
9
MAG3110_DROS_0500_64

Output Rate 5 Hz, Over Sample Ratio 64.

1
10
MAG3110_DROS_0250_128

Output Rate 2.5 Hz, Over Sample Ratio 128.

1
11
MAG3110_DROS_1000_16

Output Rate 10 Hz, Over Sample Ratio 16.

1
12
MAG3110_DROS_0500_32

Output Rate 5 Hz, Over Sample Ratio 32.

1
13
MAG3110_DROS_0250_64

Output Rate 2.5 Hz, Over Sample Ratio 64.

1
14
MAG3110_DROS_0125_128

Output Rate 1.25 Hz, Over Sample Ratio 128.

1
15
MAG3110_DROS_0500_16

Output Rate 5 Hz, Over Sample Ratio 16.

1
16
MAG3110_DROS_0250_32

Output Rate 2.5 Hz, Over Sample Ratio 32.

1
17
MAG3110_DROS_0125_64

Output Rate 1.25 Hz, Over Sample Ratio 64.

1
18
MAG3110_DROS_0063_128

Output Rate 0.63 Hz, Over Sample Ratio 128.

1
19
MAG3110_DROS_0250_16

Output Rate 2.5 Hz, Over Sample Ratio 16.

1
20
MAG3110_DROS_0125_32

Output Rate 1.25 Hz, Over Sample Ratio 32.

1
21
MAG3110_DROS_0063_64

Output Rate 0.63 Hz, Over Sample Ratio 64.

1
22
MAG3110_DROS_0031_128

Output Rate 0.31 Hz, Over Sample Ratio 128.

1
23
MAG3110_DROS_0125_16

Output Rate 1.25 Hz, Over Sample Ratio 16.

1
24
MAG3110_DROS_0063_32

Output Rate 0.63 Hz, Over Sample Ratio 32.

1
25
MAG3110_DROS_0031_64

Output Rate 0.31 Hz, Over Sample Ratio 64.

1
26
MAG3110_DROS_0016_128

Output Rate 0.16 Hz, Over Sample Ratio 128.

1
27
MAG3110_DROS_0063_16

Output Rate 0.63 Hz, Over Sample Ratio 16.

1
28
MAG3110_DROS_0031_32

Output Rate 0.31 Hz, Over Sample Ratio 32.

1
29
MAG3110_DROS_0016_64

Output Rate 0.16 Hz, Over Sample Ratio 64.

1
30
MAG3110_DROS_0008_128

Output Rate 0.08 Hz, Over Sample Ratio 128.

1
31
MAG3110_DROS_DEFAULT

Default Setting for testing.

1
MAG3110_DROS_0125_128
enum @132
MAG3110_OK
all good
MAG3110_ERROR_I2C
I2C communication failed.
MAG3110_ERROR_DEV
Device MAG3110 not found.
MAG3110_ERROR_CNF
Device configuration failed.
int mag3110_init(mag3110_t * dev, const mag3110_params_t * params)

Initialise the MAG3110 magnetometer driver.

Parameters

dev:device descriptor of magnetometer to initialize
params:configuration parameters

Return values

  • 0 on success
  • -1 if I2C communication failed
  • -2 if magnetometer test failed
  • -3 if magnetometer configuration failed
int mag3110_set_user_offset(const mag3110_t * dev, int16_t x, int16_t y, int16_t z)

Set user offset correction.

Offset correction register will be erased after accelerometer reset.

Parameters

dev:device descriptor of magnetometer
x:offset offset correction value for x-axis
y:offset offset correction value for y-axis
z:offset offset correction value for z-axis

Return values

  • 0 on success
  • -1 on error
int mag3110_set_active(const mag3110_t * dev)

Set active mode, this enables periodic measurements.

Parameters

dev:device descriptor of magnetometer

Return values

  • 0 on success
  • -1 on error
int mag3110_set_standby(const mag3110_t * dev)

Set standby mode.

Parameters

dev:device descriptor of magnetometer

Return values

  • 0 on success
  • -1 on error
int mag3110_is_ready(const mag3110_t * dev)

Check for new set of measurement data.

Parameters

dev:device descriptor of magnetometer

Return values

  • >0 if x-, y- and z-axis new sample is ready
  • 0 if measurement is in progress
  • -1 on error
int mag3110_read(const mag3110_t * dev, mag3110_data_t * data)

Read magnetometer’s data.

To get the actual values for the magnetic field in , one have to divide the returned values from the magnetometer by 10.

Parameters

dev:device descriptor of accelerometer
data:the current magnetic field strength

Return values

  • 0 on success
  • -1 on error
int mag3110_read_dtemp(const mag3110_t * dev, int8_t * dtemp)

Read die temperature.

Parameters

dev:device descriptor of magnetometer
dtemp:die temperature

Return values

  • 0 on success
  • -1 on error
MAG3110_I2C_ADDRESS

Magnetometer Default Address.

1
0x0E
struct mag3110_params_t

Configuration parameters.

i2c.h::i2c_t i2c

I2C bus the device is connected to.

uint8_t addr

I2C bus address of the device.

uint8_t type

device type

uint8_t dros

sampling rate to use

int16_t offset()

data offset in X, Y, and Z direction

struct mag3110_t

Device descriptor for MAG3110 magnetometer.

mag3110_params_t params

device configuration parameters

struct mag3110_data_t

Data type for the result data.

int16_t x

acceleration in X direction

int16_t y

acceleration in Y direction

int16_t z

acceleration in Z direction