Loading...
Searching...
No Matches
MAG3110 3-Axis Digital Magnetometer

Driver for the Freescale MAG3110 magnetometer. More...

Detailed Description

Driver for the Freescale MAG3110 magnetometer.

After initialization and set active 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.

Modules

 MAG3110 Magnetometer driver compile configuration
 

Files

file  mag3110.h
 Interface definition for the MAG3110 magnetometer driver.
 
file  mag3110_params.h
 Default configuration for MAG3110 devices.
 
file  mag3110_reg.h
 Register definition for the MAG3110 magnetometer driver.
 

Data Structures

struct  mag3110_params_t
 Configuration parameters. More...
 
struct  mag3110_t
 Device descriptor for MAG3110 magnetometer. More...
 
struct  mag3110_data_t
 Data type for the result data. More...
 

Enumerations

enum  { MAG3110_OK , MAG3110_ERROR_I2C , MAG3110_ERROR_DEV , MAG3110_ERROR_CNF }
 Named return values. More...
 

Functions

int mag3110_init (mag3110_t *dev, const mag3110_params_t *params)
 Initialise the MAG3110 magnetometer driver.
 
int mag3110_set_user_offset (const mag3110_t *dev, int16_t x, int16_t y, int16_t z)
 Set user offset correction.
 
int mag3110_set_active (const mag3110_t *dev)
 Set active mode, this enables periodic measurements.
 
int mag3110_set_standby (const mag3110_t *dev)
 Set standby mode.
 
int mag3110_is_ready (const mag3110_t *dev)
 Check for new set of measurement data.
 
int mag3110_read (const mag3110_t *dev, mag3110_data_t *data)
 Read magnetometer's data.
 
int mag3110_read_dtemp (const mag3110_t *dev, int8_t *dtemp)
 Read die temperature.
 

Output data rate macros

#define MAG3110_DROS_8000_16   0
 Output Rate 80 Hz, Over Sample Ratio 16.
 
#define MAG3110_DROS_4000_32   1
 Output Rate 40 Hz, Over Sample Ratio 32.
 
#define MAG3110_DROS_2000_64   2
 Output Rate 20 Hz, Over Sample Ratio 64.
 
#define MAG3110_DROS_1000_128   3
 Output Rate 10 Hz, Over Sample Ratio 128.
 
#define MAG3110_DROS_4000_16   4
 Output Rate 40 Hz, Over Sample Ratio 16.
 
#define MAG3110_DROS_2000_32   5
 Output Rate 20 Hz, Over Sample Ratio 32.
 
#define MAG3110_DROS_1000_64   6
 Output Rate 10 Hz, Over Sample Ratio 64.
 
#define MAG3110_DROS_0500_128   7
 Output Rate 5 Hz, Over Sample Ratio 128.
 
#define MAG3110_DROS_2000_16   8
 Output Rate 20 Hz, Over Sample Ratio 16.
 
#define MAG3110_DROS_1000_32   9
 Output Rate 10 Hz, Over Sample Ratio 32.
 
#define MAG3110_DROS_0500_64   10
 Output Rate 5 Hz, Over Sample Ratio 64.
 
#define MAG3110_DROS_0250_128   11
 Output Rate 2.5 Hz, Over Sample Ratio 128.
 
#define MAG3110_DROS_1000_16   12
 Output Rate 10 Hz, Over Sample Ratio 16.
 
#define MAG3110_DROS_0500_32   13
 Output Rate 5 Hz, Over Sample Ratio 32.
 
#define MAG3110_DROS_0250_64   14
 Output Rate 2.5 Hz, Over Sample Ratio 64.
 
#define MAG3110_DROS_0125_128   15
 Output Rate 1.25 Hz, Over Sample Ratio 128.
 
#define MAG3110_DROS_0500_16   16
 Output Rate 5 Hz, Over Sample Ratio 16.
 
#define MAG3110_DROS_0250_32   17
 Output Rate 2.5 Hz, Over Sample Ratio 32.
 
#define MAG3110_DROS_0125_64   18
 Output Rate 1.25 Hz, Over Sample Ratio 64.
 
#define MAG3110_DROS_0063_128   19
 Output Rate 0.63 Hz, Over Sample Ratio 128.
 
#define MAG3110_DROS_0250_16   20
 Output Rate 2.5 Hz, Over Sample Ratio 16.
 
#define MAG3110_DROS_0125_32   21
 Output Rate 1.25 Hz, Over Sample Ratio 32.
 
#define MAG3110_DROS_0063_64   22
 Output Rate 0.63 Hz, Over Sample Ratio 64.
 
#define MAG3110_DROS_0031_128   23
 Output Rate 0.31 Hz, Over Sample Ratio 128.
 
#define MAG3110_DROS_0125_16   24
 Output Rate 1.25 Hz, Over Sample Ratio 16.
 
#define MAG3110_DROS_0063_32   25
 Output Rate 0.63 Hz, Over Sample Ratio 32.
 
#define MAG3110_DROS_0031_64   26
 Output Rate 0.31 Hz, Over Sample Ratio 64.
 
#define MAG3110_DROS_0016_128   27
 Output Rate 0.16 Hz, Over Sample Ratio 128.
 
#define MAG3110_DROS_0063_16   28
 Output Rate 0.63 Hz, Over Sample Ratio 16.
 
#define MAG3110_DROS_0031_32   29
 Output Rate 0.31 Hz, Over Sample Ratio 32.
 
#define MAG3110_DROS_0016_64   30
 Output Rate 0.16 Hz, Over Sample Ratio 64.
 
#define MAG3110_DROS_0008_128   31
 Output Rate 0.08 Hz, Over Sample Ratio 128.
 
#define MAG3110_DROS_DEFAULT   MAG3110_DROS_0125_128
 Default Setting for testing.
 

Macro Definition Documentation

◆ MAG3110_DROS_0008_128

#define MAG3110_DROS_0008_128   31

Output Rate 0.08 Hz, Over Sample Ratio 128.

Definition at line 108 of file mag3110.h.

◆ MAG3110_DROS_0016_128

#define MAG3110_DROS_0016_128   27

Output Rate 0.16 Hz, Over Sample Ratio 128.

Definition at line 104 of file mag3110.h.

◆ MAG3110_DROS_0016_64

#define MAG3110_DROS_0016_64   30

Output Rate 0.16 Hz, Over Sample Ratio 64.

Definition at line 107 of file mag3110.h.

◆ MAG3110_DROS_0031_128

#define MAG3110_DROS_0031_128   23

Output Rate 0.31 Hz, Over Sample Ratio 128.

Definition at line 100 of file mag3110.h.

◆ MAG3110_DROS_0031_32

#define MAG3110_DROS_0031_32   29

Output Rate 0.31 Hz, Over Sample Ratio 32.

Definition at line 106 of file mag3110.h.

◆ MAG3110_DROS_0031_64

#define MAG3110_DROS_0031_64   26

Output Rate 0.31 Hz, Over Sample Ratio 64.

Definition at line 103 of file mag3110.h.

◆ MAG3110_DROS_0063_128

#define MAG3110_DROS_0063_128   19

Output Rate 0.63 Hz, Over Sample Ratio 128.

Definition at line 96 of file mag3110.h.

◆ MAG3110_DROS_0063_16

#define MAG3110_DROS_0063_16   28

Output Rate 0.63 Hz, Over Sample Ratio 16.

Definition at line 105 of file mag3110.h.

◆ MAG3110_DROS_0063_32

#define MAG3110_DROS_0063_32   25

Output Rate 0.63 Hz, Over Sample Ratio 32.

Definition at line 102 of file mag3110.h.

◆ MAG3110_DROS_0063_64

#define MAG3110_DROS_0063_64   22

Output Rate 0.63 Hz, Over Sample Ratio 64.

Definition at line 99 of file mag3110.h.

◆ MAG3110_DROS_0125_128

#define MAG3110_DROS_0125_128   15

Output Rate 1.25 Hz, Over Sample Ratio 128.

Definition at line 92 of file mag3110.h.

◆ MAG3110_DROS_0125_16

#define MAG3110_DROS_0125_16   24

Output Rate 1.25 Hz, Over Sample Ratio 16.

Definition at line 101 of file mag3110.h.

◆ MAG3110_DROS_0125_32

#define MAG3110_DROS_0125_32   21

Output Rate 1.25 Hz, Over Sample Ratio 32.

Definition at line 98 of file mag3110.h.

◆ MAG3110_DROS_0125_64

#define MAG3110_DROS_0125_64   18

Output Rate 1.25 Hz, Over Sample Ratio 64.

Definition at line 95 of file mag3110.h.

◆ MAG3110_DROS_0250_128

#define MAG3110_DROS_0250_128   11

Output Rate 2.5 Hz, Over Sample Ratio 128.

Definition at line 88 of file mag3110.h.

◆ MAG3110_DROS_0250_16

#define MAG3110_DROS_0250_16   20

Output Rate 2.5 Hz, Over Sample Ratio 16.

Definition at line 97 of file mag3110.h.

◆ MAG3110_DROS_0250_32

#define MAG3110_DROS_0250_32   17

Output Rate 2.5 Hz, Over Sample Ratio 32.

Definition at line 94 of file mag3110.h.

◆ MAG3110_DROS_0250_64

#define MAG3110_DROS_0250_64   14

Output Rate 2.5 Hz, Over Sample Ratio 64.

Definition at line 91 of file mag3110.h.

◆ MAG3110_DROS_0500_128

#define MAG3110_DROS_0500_128   7

Output Rate 5 Hz, Over Sample Ratio 128.

Definition at line 84 of file mag3110.h.

◆ MAG3110_DROS_0500_16

#define MAG3110_DROS_0500_16   16

Output Rate 5 Hz, Over Sample Ratio 16.

Definition at line 93 of file mag3110.h.

◆ MAG3110_DROS_0500_32

#define MAG3110_DROS_0500_32   13

Output Rate 5 Hz, Over Sample Ratio 32.

Definition at line 90 of file mag3110.h.

◆ MAG3110_DROS_0500_64

#define MAG3110_DROS_0500_64   10

Output Rate 5 Hz, Over Sample Ratio 64.

Definition at line 87 of file mag3110.h.

◆ MAG3110_DROS_1000_128

#define MAG3110_DROS_1000_128   3

Output Rate 10 Hz, Over Sample Ratio 128.

Definition at line 80 of file mag3110.h.

◆ MAG3110_DROS_1000_16

#define MAG3110_DROS_1000_16   12

Output Rate 10 Hz, Over Sample Ratio 16.

Definition at line 89 of file mag3110.h.

◆ MAG3110_DROS_1000_32

#define MAG3110_DROS_1000_32   9

Output Rate 10 Hz, Over Sample Ratio 32.

Definition at line 86 of file mag3110.h.

◆ MAG3110_DROS_1000_64

#define MAG3110_DROS_1000_64   6

Output Rate 10 Hz, Over Sample Ratio 64.

Definition at line 83 of file mag3110.h.

◆ MAG3110_DROS_2000_16

#define MAG3110_DROS_2000_16   8

Output Rate 20 Hz, Over Sample Ratio 16.

Definition at line 85 of file mag3110.h.

◆ MAG3110_DROS_2000_32

#define MAG3110_DROS_2000_32   5

Output Rate 20 Hz, Over Sample Ratio 32.

Definition at line 82 of file mag3110.h.

◆ MAG3110_DROS_2000_64

#define MAG3110_DROS_2000_64   2

Output Rate 20 Hz, Over Sample Ratio 64.

Definition at line 79 of file mag3110.h.

◆ MAG3110_DROS_4000_16

#define MAG3110_DROS_4000_16   4

Output Rate 40 Hz, Over Sample Ratio 16.

Definition at line 81 of file mag3110.h.

◆ MAG3110_DROS_4000_32

#define MAG3110_DROS_4000_32   1

Output Rate 40 Hz, Over Sample Ratio 32.

Definition at line 78 of file mag3110.h.

◆ MAG3110_DROS_8000_16

#define MAG3110_DROS_8000_16   0

Output Rate 80 Hz, Over Sample Ratio 16.

Definition at line 77 of file mag3110.h.

◆ MAG3110_DROS_DEFAULT

#define MAG3110_DROS_DEFAULT   MAG3110_DROS_0125_128

Default Setting for testing.

Definition at line 109 of file mag3110.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Named return values.

Enumerator
MAG3110_OK 

all good

MAG3110_ERROR_I2C 

I2C communication failed.

MAG3110_ERROR_DEV 

Device MAG3110 not found.

MAG3110_ERROR_CNF 

Device configuration failed.

Definition at line 50 of file mag3110.h.

Function Documentation

◆ mag3110_init()

int mag3110_init ( mag3110_t dev,
const mag3110_params_t params 
)

Initialise the MAG3110 magnetometer driver.

Parameters
[out]devdevice descriptor of magnetometer to initialize
[in]paramsconfiguration parameters
Returns
0 on success
-1 if I2C communication failed
-2 if magnetometer test failed
-3 if magnetometer configuration failed

◆ mag3110_is_ready()

int mag3110_is_ready ( const mag3110_t dev)

Check for new set of measurement data.

Parameters
[in]devdevice descriptor of magnetometer
Returns
>0 if x-, y- and z-axis new sample is ready
0 if measurement is in progress
-1 on error

◆ mag3110_read()

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 $\mu T$, one have to divide the returned values from the magnetometer by 10.

Parameters
[in]devdevice descriptor of accelerometer
[out]datathe current magnetic field strength
Returns
0 on success
-1 on error

◆ mag3110_read_dtemp()

int mag3110_read_dtemp ( const mag3110_t dev,
int8_t *  dtemp 
)

Read die temperature.

Parameters
[in]devdevice descriptor of magnetometer
[out]dtempdie temperature
Returns
0 on success
-1 on error

◆ mag3110_set_active()

int mag3110_set_active ( const mag3110_t dev)

Set active mode, this enables periodic measurements.

Parameters
[out]devdevice descriptor of magnetometer
Returns
0 on success
-1 on error

◆ mag3110_set_standby()

int mag3110_set_standby ( const mag3110_t dev)

Set standby mode.

Parameters
[in]devdevice descriptor of magnetometer
Returns
0 on success
-1 on error

◆ mag3110_set_user_offset()

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
[out]devdevice descriptor of magnetometer
[in]xoffset offset correction value for x-axis
[in]yoffset offset correction value for y-axis
[in]zoffset offset correction value for z-axis
Returns
0 on success
-1 on error