Contiki 3.x
Functions
lis3dh.c File Reference

    Implementation of LIS3DH SPI driver used in the Mulle platform.
More...

#include "lis3dh.h"
#include <stdint.h>
#include <stdio.h>

Go to the source code of this file.

Functions

void lis3dh_set_bits (const lis3dh_reg_addr_t addr, const uint8_t mask)
 Set bits of an 8-bit register on the LIS3DH.
 
void lis3dh_clear_bits (const lis3dh_reg_addr_t addr, const uint8_t mask)
 Clear bits of an 8-bit register on the LIS3DH.
 
void lis3dh_write_bits (const lis3dh_reg_addr_t addr, const uint8_t mask, const uint8_t values)
 Write (both set and clear) bits of an 8-bit register on the LIS3DH. More...
 
int16_t lis3dh_read_xaxis ()
 Get one X-axis reading from the accelerometer. More...
 
int16_t lis3dh_read_yaxis ()
 Get one Y-axis reading from the accelerometer. More...
 
int16_t lis3dh_read_zaxis ()
 Get one Z-axis reading from the accelerometer. More...
 
void lis3dh_read_xyz (int16_t *buffer)
 Read all three axes in a single transaction. More...
 
int16_t lis3dh_read_aux_adc1 ()
 Get one reading from the first channel of the auxiliary ADC. More...
 
int16_t lis3dh_read_aux_adc2 ()
 Get one reading from the second channel of the auxiliary ADC. More...
 
int16_t lis3dh_read_aux_adc3 ()
 Get one reading from the third channel of the auxiliary ADC. More...
 
void lis3dh_set_aux_adc (const uint8_t enable, const uint8_t temperature)
 Turn on/off power to the auxiliary ADC in LIS3DH. More...
 
void lis3dh_set_axes (const uint8_t axes)
 Enable/disable accelerometer axes. More...
 
void lis3dh_set_fifo_mode (const lis3dh_fifo_mode_t mode)
 Set the FIFO mode. More...
 
void lis3dh_set_fifo (const uint8_t enable)
 Enable/disable the FIFO. More...
 
void lis3dh_set_odr (const lis3dh_odr_t odr)
 Set the output data rate of the sensor. More...
 
void lis3dh_set_scale (const lis3dh_scale_t scale)
 Set the full scale range of the sensor. More...
 
void lis3dh_init ()
 Initialize a LIS3DH accelerometer. More...
 

Detailed Description

    Implementation of LIS3DH SPI driver used in the Mulle platform.
Author
Joakim Gebart joaki.nosp@m.m.ge.nosp@m.bart@.nosp@m.eist.nosp@m.ec.se

Definition in file lis3dh.c.

Function Documentation

void lis3dh_init ( )

Initialize a LIS3DH accelerometer.

Todo:
Signal errors when initializing the LIS3DH hardware.

Definition at line 261 of file lis3dh.c.

References lis3dh_arch_init(), lis3dh_read_byte(), LIS3DH_WHO_AM_I_RESPONSE, and lis3dh_write_byte().

int16_t lis3dh_read_aux_adc1 ( )

Get one reading from the first channel of the auxiliary ADC.

Returns
The current ADC reading.

Definition at line 134 of file lis3dh.c.

References lis3dh_read_int16().

int16_t lis3dh_read_aux_adc2 ( )

Get one reading from the second channel of the auxiliary ADC.

Returns
The current ADC reading.

Definition at line 144 of file lis3dh.c.

References lis3dh_read_int16().

int16_t lis3dh_read_aux_adc3 ( )

Get one reading from the third channel of the auxiliary ADC.

Note
The internal temperature sensor is connected to the third channel on the auxiliary ADC when the TEMP_EN bit of TEMP_CFG_REG is set.
Returns
The current ADC reading.

Definition at line 157 of file lis3dh.c.

References lis3dh_read_int16().

int16_t lis3dh_read_xaxis ( )

Get one X-axis reading from the accelerometer.

Returns
The oldest X axis acceleration measurement available.

Definition at line 93 of file lis3dh.c.

References lis3dh_read_int16().

void lis3dh_read_xyz ( int16_t *  buffer)

Read all three axes in a single transaction.

Parameters
bufferPointer to an int16_t[3] buffer.

Definition at line 123 of file lis3dh.c.

References LIS3DH_ACC_DATA_SIZE, and lis3dh_memcpy_from_device().

int16_t lis3dh_read_yaxis ( )

Get one Y-axis reading from the accelerometer.

Returns
The oldest Y axis acceleration measurement available.

Definition at line 103 of file lis3dh.c.

References lis3dh_read_int16().

int16_t lis3dh_read_zaxis ( )

Get one Z-axis reading from the accelerometer.

Returns
The oldest Z axis acceleration measurement available.

Definition at line 113 of file lis3dh.c.

References lis3dh_read_int16().

void lis3dh_set_aux_adc ( const uint8_t  enable,
const uint8_t  temperature 
)

Turn on/off power to the auxiliary ADC in LIS3DH.

Parameters
enablePower state of the auxiliary ADC
temperatureIf not zero, switch the ADC mux so that a temperature reading is available on OUT_3_L, OUT_3_H.
Note
This ADC is only used for the temperature reading and the external ADC pins. The accelerometer ADC is turned on by lis3dh_set_odr().

Definition at line 172 of file lis3dh.c.

References LIS3DH_TEMP_CFG_REG_ADC_PD_MASK, LIS3DH_TEMP_CFG_REG_TEMP_EN_MASK, and lis3dh_write_bits().

void lis3dh_set_axes ( const uint8_t  axes)

Enable/disable accelerometer axes.

Parameters
axesAn OR-ed combination of LIS3DH_AXES_X, LIS3DH_AXES_Y, LIS3DH_AXES_Z.
Note
The macro LIS3DH_AXES_XYZ is a convenience shortcut to enable all axes.

Definition at line 186 of file lis3dh.c.

References lis3dh_write_bits().

void lis3dh_set_fifo ( const uint8_t  enable)

Enable/disable the FIFO.

Parameters
enableIf zero, disable the FIFO, otherwise enables the FIFO.

Definition at line 207 of file lis3dh.c.

References LIS3DH_CTRL_REG5_FIFO_EN_MASK, and lis3dh_write_bits().

void lis3dh_set_fifo_mode ( const lis3dh_fifo_mode_t  mode)

Set the FIFO mode.

Parameters
modeThe chosen FIFO mode.

Definition at line 196 of file lis3dh.c.

References lis3dh_write_bits().

void lis3dh_set_odr ( const lis3dh_odr_t  odr)

Set the output data rate of the sensor.

Parameters
odrChosen output data rate.

Definition at line 218 of file lis3dh.c.

References LIS3DH_CTRL_REG1_ODR_SHIFT, and lis3dh_write_bits().

void lis3dh_set_scale ( const lis3dh_scale_t  scale)

Set the full scale range of the sensor.

Valid values for scale is 2, 4, 8, 16 and represents the full range of the sensor.

Parameters
scaleThe chosen sensitivity scale.

Definition at line 231 of file lis3dh.c.

References lis3dh_write_bits().

void lis3dh_write_bits ( const lis3dh_reg_addr_t  addr,
const uint8_t  mask,
const uint8_t  values 
)

Write (both set and clear) bits of an 8-bit register on the LIS3DH.

Parameters
addrRegister address on the LIS3DH.
maskBitmask for the bits to modify.
valuesThe values to write to the masked bits.

Definition at line 77 of file lis3dh.c.

References lis3dh_read_byte(), and lis3dh_write_byte().

Referenced by lis3dh_set_aux_adc(), lis3dh_set_axes(), lis3dh_set_fifo(), lis3dh_set_fifo_mode(), lis3dh_set_odr(), and lis3dh_set_scale().