Loading...
Searching...
No Matches
LSM303DLHC 3D accelerometer/magnetometer

Device driver for the LSM303DLHC 3D accelerometer/magnetometer. More...

Detailed Description

Device driver for the LSM303DLHC 3D accelerometer/magnetometer.

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

Files

file  lsm303dlhc.h
 Device driver interface for the LSM303DLHC 3D accelerometer/magnetometer.
 
file  lsm303dlhc-internal.h
 Definitions for the LSM303DLHC 3D accelerometer/magnetometer.
 
file  lsm303dlhc_params.h
 Default configuration for LSM303DLHC devices.
 

Data Structures

struct  lsm303dlhc_3d_data_t
 3d data container More...
 
struct  lsm303dlhc_params_t
 Data structure holding all the information needed for initialization. More...
 
struct  lsm303dlhc_t
 Device descriptor for LSM303DLHC sensors. More...
 

Enumerations

enum  lsm303dlhc_acc_sample_rate_t {
  LSM303DLHC_ACC_SAMPLE_RATE_1HZ = 0x10 , LSM303DLHC_ACC_SAMPLE_RATE_10HZ = 0x20 , LSM303DLHC_ACC_SAMPLE_RATE_25HZ = 0x30 , LSM303DLHC_ACC_SAMPLE_RATE_50HZ = 0x40 ,
  LSM303DLHC_ACC_SAMPLE_RATE_100HZ = 0x50 , LSM303DLHC_ACC_SAMPLE_RATE_200HZ = 0x60 , LSM303DLHC_ACC_SAMPLE_RATE_400HZ = 0x70 , LSM303DLHC_ACC_SAMPLE_RATE_1620HZ = 0x80 ,
  LSM303DLHC_ACC_SAMPLE_RATE_N1344HZ_L5376HZ = 0x90
}
 Possible accelerometer sample rates. More...
 
enum  lsm303dlhc_acc_scale_t { LSM303DLHC_ACC_SCALE_2G = 0x00 , LSM303DLHC_ACC_SCALE_4G = 0x10 , LSM303DLHC_ACC_SCALE_8G = 0x20 , LSM303DLHC_ACC_SCALE_16G = 0x30 }
 Possible accelerometer scales. More...
 
enum  lsm303dlhc_mag_sample_rate_t {
  LSM303DLHC_MAG_SAMPLE_RATE_0_75HZ = 0x00 , LSM303DLHC_MAG_SAMPLE_RATE_1_5HZ = 0x04 , LSM303DLHC_MAG_SAMPLE_RATE_3HZ = 0x08 , LSM303DLHC_MAG_SAMPLE_RATE_7_5HZ = 0x0c ,
  LSM303DLHC_MAG_SAMPLE_RATE_15HZ = 0x10 , LSM303DLHC_MAG_SAMPLE_RATE_30HZ = 0x14 , LSM303DLHC_MAG_SAMPLE_RATE_75HZ = 0x18 , LSM303DLHC_MAG_SAMPLE_RATE_220HZ = 0x1c
}
 Possible magnetometer sample rates. More...
 
enum  lsm303dlhc_mag_gain_t {
  LSM303DLHC_MAG_GAIN_1100_980_GAUSS = 0x20 , LSM303DLHC_MAG_GAIN_855_760_GAUSS = 0x40 , LSM303DLHC_MAG_GAIN_670_600_GAUSS = 0x60 , LSM303DLHC_MAG_GAIN_450_400_GAUSS = 0x80 ,
  LSM303DLHC_MAG_GAIN_400_355_GAUSS = 0xa0 , LSM303DLHC_MAG_GAIN_330_295_GAUSS = 0xc0 , LSM303DLHC_MAG_GAIN_230_205_GAUSS = 0xe0
}
 Possible magnetometer gain values. More...
 

Functions

int lsm303dlhc_init (lsm303dlhc_t *dev, const lsm303dlhc_params_t *params)
 Initialize a new LSM303DLHC device.
 
int lsm303dlhc_read_acc (const lsm303dlhc_t *dev, lsm303dlhc_3d_data_t *data)
 Read a accelerometer value from the sensor.
 
int lsm303dlhc_read_mag (const lsm303dlhc_t *dev, lsm303dlhc_3d_data_t *data)
 Read a magnetometer value from the sensor.
 
int lsm303dlhc_read_temp (const lsm303dlhc_t *dev, int16_t *value)
 Read a temperature value from the sensor.
 
int lsm303dlhc_enable (const lsm303dlhc_t *dev)
 Enable the given sensor.
 
int lsm303dlhc_disable (const lsm303dlhc_t *dev)
 Disable the given sensor.
 

The sensors default I2C address

#define LSM303DLHC_ACC_DEFAULT_ADDRESS   (0x19)
 
#define LSM303DLHC_MAG_DEFAULT_ADDRESS   (0x1e)
 

Macro Definition Documentation

◆ LSM303DLHC_ACC_DEFAULT_ADDRESS

#define LSM303DLHC_ACC_DEFAULT_ADDRESS   (0x19)

Definition at line 39 of file lsm303dlhc.h.

◆ LSM303DLHC_MAG_DEFAULT_ADDRESS

#define LSM303DLHC_MAG_DEFAULT_ADDRESS   (0x1e)

Definition at line 40 of file lsm303dlhc.h.

Enumeration Type Documentation

◆ lsm303dlhc_acc_sample_rate_t

Possible accelerometer sample rates.

Enumerator
LSM303DLHC_ACC_SAMPLE_RATE_1HZ 

1Hz sample rate

LSM303DLHC_ACC_SAMPLE_RATE_10HZ 

10Hz sample rate

LSM303DLHC_ACC_SAMPLE_RATE_25HZ 

25Hz sample rate

LSM303DLHC_ACC_SAMPLE_RATE_50HZ 

50Hz sample rate

LSM303DLHC_ACC_SAMPLE_RATE_100HZ 

100Hz sample rate

LSM303DLHC_ACC_SAMPLE_RATE_200HZ 

200Hz sample rate

LSM303DLHC_ACC_SAMPLE_RATE_400HZ 

400Hz sample rate

LSM303DLHC_ACC_SAMPLE_RATE_1620HZ 

1620Hz sample rate

LSM303DLHC_ACC_SAMPLE_RATE_N1344HZ_L5376HZ 

1344Hz normal mode, 5376Hz low power mode

Definition at line 46 of file lsm303dlhc.h.

◆ lsm303dlhc_acc_scale_t

Possible accelerometer scales.

Enumerator
LSM303DLHC_ACC_SCALE_2G 

+- 2g range

LSM303DLHC_ACC_SCALE_4G 

+- 4g range

LSM303DLHC_ACC_SCALE_8G 

+- 8g range

LSM303DLHC_ACC_SCALE_16G 

+-16g range

Definition at line 62 of file lsm303dlhc.h.

◆ lsm303dlhc_mag_gain_t

Possible magnetometer gain values.

Enumerator
LSM303DLHC_MAG_GAIN_1100_980_GAUSS 

1100Gauss XYZ 980Gauss Z

LSM303DLHC_MAG_GAIN_855_760_GAUSS 

855Gauss XYZ 760Gauss Z

LSM303DLHC_MAG_GAIN_670_600_GAUSS 

670Gauss XYZ 600Gauss Z

LSM303DLHC_MAG_GAIN_450_400_GAUSS 

450Gauss XYZ 400Gauss Z

LSM303DLHC_MAG_GAIN_400_355_GAUSS 

400Gauss XYZ 355Gauss Z

LSM303DLHC_MAG_GAIN_330_295_GAUSS 

330Gauss XYZ 295Gauss Z

LSM303DLHC_MAG_GAIN_230_205_GAUSS 

230Gauss XYZ 205Gauss Z

Definition at line 86 of file lsm303dlhc.h.

◆ lsm303dlhc_mag_sample_rate_t

Possible magnetometer sample rates.

Enumerator
LSM303DLHC_MAG_SAMPLE_RATE_0_75HZ 

0.75Hz sample rate

LSM303DLHC_MAG_SAMPLE_RATE_1_5HZ 

1.5 Hz sample rate

LSM303DLHC_MAG_SAMPLE_RATE_3HZ 

3 Hz sample rate

LSM303DLHC_MAG_SAMPLE_RATE_7_5HZ 

7.5 Hz sample rate

LSM303DLHC_MAG_SAMPLE_RATE_15HZ 

15 Hz sample rate

LSM303DLHC_MAG_SAMPLE_RATE_30HZ 

30 Hz sample rate

LSM303DLHC_MAG_SAMPLE_RATE_75HZ 

75 Hz sample rate

LSM303DLHC_MAG_SAMPLE_RATE_220HZ 

220 Hz sample rate

Definition at line 72 of file lsm303dlhc.h.

Function Documentation

◆ lsm303dlhc_disable()

int lsm303dlhc_disable ( const lsm303dlhc_t dev)

Disable the given sensor.

Parameters
[in]devdevice descriptor of an LSM303DLHC device
Returns
0 on success
-1 on error

◆ lsm303dlhc_enable()

int lsm303dlhc_enable ( const lsm303dlhc_t dev)

Enable the given sensor.

Parameters
[in]devdevice descriptor of an LSM303DLHC device
Returns
0 on success
-1 on error

◆ lsm303dlhc_init()

int lsm303dlhc_init ( lsm303dlhc_t dev,
const lsm303dlhc_params_t params 
)

Initialize a new LSM303DLHC device.

Parameters
[in]devdevice descriptor of an LSM303DLHC device
[in]paramsinitialization parameters
Returns
0 on success
-1 on error

◆ lsm303dlhc_read_acc()

int lsm303dlhc_read_acc ( const lsm303dlhc_t dev,
lsm303dlhc_3d_data_t data 
)

Read a accelerometer value from the sensor.

This function provides raw acceleration data. To get the corresponding values in g please refer to the following table: measurement range | factor -----------------—+------— +- 2g | 1*10^-3 +- 4g | 2*10^-3 +- 8g | 4*10^-3 +-16g | 8*10^-3

Parameters
[in]devdevice descriptor of an LSM303DLHC device
[out]datathe measured accelerometer data
Returns
0 on success
-1 on error

◆ lsm303dlhc_read_mag()

int lsm303dlhc_read_mag ( const lsm303dlhc_t dev,
lsm303dlhc_3d_data_t data 
)

Read a magnetometer value from the sensor.

This function returns raw magnetic data. To get the corresponding values in gauss please refer to the following table: measurement range | factor -----------------—+------— +- 1.3 gauss | 1/1100 +- 1.9 gauss | 1/855 +- 2.5 gauss | 1/670 +- 4.0 gauss | 1/450 +- 4.7 gauss | 1/400 +- 5.6 gauss | 1/330 +- 8.1 gauss | 1/230

Parameters
[in]devdevice descriptor of an LSM303DLHC device
[out]datathe measured magnetometer data
Returns
0 on success
-1 on error

◆ lsm303dlhc_read_temp()

int lsm303dlhc_read_temp ( const lsm303dlhc_t dev,
int16_t *  value 
)

Read a temperature value from the sensor.

Parameters
[in]devdevice descriptor of an LSM303DLHC device
[out]valuethe measured temperature
Returns
0 on success
-1 on error