Contiki-Inga 3.x
Data Structures | Macros | Functions
ST L3G4200D 3-axis Gyroscope interface

Details about sensors functionality can be found in corresponding datasheet. More...

Data Structures

struct  angle_data_t
 Angle data type. More...
 

Macros

#define l3g4200d_raw_to_dps(raw)   (int16_t) (((int32_t) raw * l3g4200d_dps_scale) / 4000)
 Convert raw values to dps.
 

Functions

int8_t l3g4200d_available (void)
 Checks if l3g4200d is avialable. More...
 
int8_t l3g4200d_init (void)
 Inits the gyroscope. More...
 
int8_t l3g4200d_deinit (void)
 Deinit the gyroscope. More...
 
uint8_t l3g4200d_set_dps (uint8_t set)
 Sets the sensitivity value [dps]. More...
 
uint8_t l3g4200d_set_data_rate (uint8_t set)
 Sets the data rate [Hz]. More...
 
void l3g4200d_set_fifomode (uint8_t set)
 Sets the fifo mode. More...
 
void l3g4200d_fifo_enable (void)
 Enables fifo mode.
 
int8_t l3g4200d_fifo_overrun (void)
 Checks for fifo overrun. More...
 
angle_data_t l3g4200d_get_angle (void)
 Reads data for x,y and z angle. More...
 
int8_t l3g4200d_get_angle_fifo (angle_data_t *ret)
 Reads angle values from fifo. More...
 
int16_t l3g4200d_get_x_angle (void)
 Reads x angle value. More...
 
int16_t l3g4200d_get_y_angle (void)
 Reads y angle value. More...
 
int16_t l3g4200d_get_z_angle (void)
 Reads z angle value. More...
 
int8_t l3g4200d_get_temp (void)
 Reads temperature value. More...
 
uint8_t l3g4200d_read8bit (uint8_t addr)
 Reads 8 bit register from gyroscopes. More...
 
uint16_t l3g4200d_read16bit (uint8_t addr)
 Reads 2x8 bit register from gyroscopes. More...
 
void l3g4200d_write8bit (uint8_t addr, uint8_t data)
 Writes 8 bit to gyroscope register. More...
 

Register addresses.

Naming convention of the datasheet with prefix L3G4200D_ is used.

#define L3G4200D_WHO_AM_I_REG   0x0F
 Device identification register.
 
#define L3G4200D_CTRL_REG1   0x20
 Control register 1.
 
#define L3G4200D_CTRL_REG2   0x21
 Control register 2.
 
#define L3G4200D_CTRL_REG3   0x22
 Control register 3.
 
#define L3G4200D_CTRL_REG4   0x23
 Control register 4.
 
#define L3G4200D_CTRL_REG5   0x24
 Control register 5.
 
#define L3G4200D_REFERENCE   0x25
 Reference value for Interrupt generation.
 
#define L3G4200D_OUT_TEMP   0x26
 Temperature data.
 
#define L3G4200D_STATUS_REG   0x27
 Status register.
 
#define L3G4200D_OUT_X_L   0x28
 X-axis angular rate data. (low)
 
#define L3G4200D_OUT_X_H   0x29
 X-axis angular rate data. (high)
 
#define L3G4200D_OUT_Y_L   0x2A
 Y-axis angular rate data. (low)
 
#define L3G4200D_OUT_Y_H   0x2B
 Y-axis angular rate data. (high)
 
#define L3G4200D_OUT_Z_L   0x2C
 Z-axis angular rate data. (low)
 
#define L3G4200D_OUT_Z_H   0x2D
 Z-axis angular rate data. (high)
 
#define L3G4200D_FIFO_CTRL_REG   0x2E
 Fifo control register.
 
#define L3G4200D_FIFO_SRC_REG   0x2F
 Fifo source register.
 

Bit addresses for CTRL_REG1

#define L3G4200D_DR1   7
 Output Data Rate selection (higher)
 
#define L3G4200D_DR0   6
 Output Data Rate selection (lower)
 
#define L3G4200D_BW1   5
 Bandwidth selection (higher)
 
#define L3G4200D_BW0   4
 Bandwidth selection (lower)
 
#define L3G4200D_PD   3
 Power down mode enable.
 
#define L3G4200D_ZEN   2
 Z axis enable.
 
#define L3G4200D_YEN   1
 Y axis enable.
 
#define L3G4200D_XEN   0
 X axis enable.
 

Bit addresses for CTRL_REG2.

#define L3G4200D_HPM1   5
 High Pass filter Mode Selection (higher)
 
#define L3G4200D_HPM0   4
 High Pass filter Mode Selection (lower)
 
#define L3G4200D_HPCF3   3
 High Pass filter Cutt Off frequency selection (highest)
 
#define L3G4200D_HPCF2   2
 High Pass filter Cutt Off frequency selection.
 
#define L3G4200D_HPCF1   1
 High Pass filter Cutt Off frequency selection.
 
#define L3G4200D_HPCF0   0
 High Pass filter Cutt Off frequency selection (lowest)
 

Bit addresses for CTRL_REG3.

#define L3G4200D_I1_INT1   7
 Interrupt enable on INT1 pin.
 
#define L3G4200D_I1_BOOT   6
 Boot status available on INT1.
 
#define L3G4200D_H_LACTIVE   5
 Interrupt active configuration on INT1.
 
#define L3G4200D_PP_OD   4
 Push-Pull / Open drain.
 
#define L3G4200D_I2_DRDY   3
 Data Ready on DRDY/INT2.
 
#define L3G4200D_I2_WTM   2
 FIFO Watermark interrupt on DRDY/INT2.
 
#define L3G4200D_I2_ORUN   1
 FIFO Overrun interrupt on DRDY/INT2.
 
#define L3G4200D_I2_EMPTY   0
 FIFO Empty interrupt on DRDY/INT2.
 

Bit addresses for CTRL_REG4.

#define L3G4200D_BDU   7
 Block Data Update.
 
#define L3G4200D_BLE   6
 Big/Little Endian Data Selection.
 
#define L3G4200D_FS1   5
 Full Scale Selection (higher)
 
#define L3G4200D_FS0   4
 Full Scale Selection (lower)
 
#define L3G4200D_ST1   2
 Self Test Enable (higher)
 
#define L3G4200D_ST0   1
 Self Test Enable (lower)
 
#define L3G4200D_SIM   0
 SPI Serial Interface mode selection.
 

Bit addresses for CTRL_REG5.

#define L3G4200D_BOOT   7
 Reboot memory content.
 
#define L3G4200D_FIFO_EN   6
 FIFO enable.
 
#define L3G4200D_HPEN   4
 High Pass filter Enable.
 
#define L3G4200D_INT1_SEL1   3
 INT1 selection configuration (higher)
 
#define L3G4200D_INT1_SEL0   2
 INT1 selection configuration (lower)
 
#define L3G4200D_OUT_SEL1   1
 Out selection configuration (higher)
 
#define L3G4200D_OUT_SEL0   0
 Out selection configuration (lower)
 

Bit addresses for STATUS_REG.

#define L3G4200D_ZYXOR   7
 X, Y, Z-axis data overrun.
 
#define L3G4200D_ZOR   6
 Z axis data overrun.
 
#define L3G4200D_YOR   5
 Y axis data overrun.
 
#define L3G4200D_XOR   4
 X axis data overrun.
 
#define L3G4200D_ZYXDA   3
 X, Y, Z-axis new data available.
 
#define L3G4200D_ZDA   2
 Z axis new data available.
 
#define L3G4200D_YDA   1
 Y axis new data available.
 
#define L3G4200D_XDA   0
 X axis new data available.
 

Bit addresses for FIFO_CTRL_REG.

#define L3G4200D_FM2   7
 FIFO mode selection.
 
#define L3G4200D_FM1   6
 FIFO mode selection.
 
#define L3G4200D_FM0   5
 FIFO mode selection.
 
#define L3G4200D_WTM4   4
 FIFO threshold. Watermark level setting (highest)
 
#define L3G4200D_WTM3   3
 FIFO threshold. Watermark level setting.
 
#define L3G4200D_WTM2   2
 FIFO threshold. Watermark level setting.
 
#define L3G4200D_WTM1   1
 FIFO threshold. Watermark level setting.
 
#define L3G4200D_WTM0   0
 FIFO threshold. Watermark level setting (lowest)
 

Bit addresses for FIFO_SRC_REG.

#define L3G4200D_WTM   7
 Watermark status.
 
#define L3G4200D_OVRN   6
 Overrun bit status.
 
#define L3G4200D_EMPTY   5
 FIFO empty bit.
 
#define L3G4200D_FSS4   4
 FIFO stored data level (highest)
 
#define L3G4200D_FSS3   3
 FIFO stored data level.
 
#define L3G4200D_FSS2   2
 FIFO stored data level.
 
#define L3G4200D_FSS1   1
 FIFO stored data level.
 
#define L3G4200D_FSS0   0
 FIFO stored data level (lowest)
 

Resolution Settings.

#define L3G4200D_250DPS   (0x00 << L3G4200D_FS0)
 
#define L3G4200D_500DPS   (0x01 << L3G4200D_FS0)
 
#define L3G4200D_2000DPS   (0x02 << L3G4200D_FS0)
 

Data rate Settings.

#define L3G4200D_ODR_100HZ   (0x0 << L3G4200D_DR0)
 ODR: 100Hz.
 
#define L3G4200D_ODR_200HZ   (0x1 << L3G4200D_DR0)
 ODR: 200Hz.
 
#define L3G4200D_ODR_400HZ   (0x2 << L3G4200D_DR0)
 ODR: 400Hz.
 
#define L3G4200D_ODR_800HZ   (0x3 << L3G4200D_DR0)
 ODR: 800Hz.
 

Mode Settings.

#define L3G4200D_BYPASS   (0x00 << L3G4200D_FM0)
 
#define L3G4200D_FIFO   (0x01 << L3G4200D_FM0)
 
#define L3G4200D_STREAM   (0x02 << L3G4200D_FM0)
 
#define L3G4200D_STREAM_TO_FIFO   (0x03 << L3G4200D_FM0)
 
#define L3G4200D_BYPASS_TO_STREAM   (0x04 << L3G4200D_FM0)
 

Detailed Description

Details about sensors functionality can be found in corresponding datasheet.

Registers and bit positions are named according to their datasheet names.

Function Documentation

int8_t l3g4200d_available ( void  )

Checks if l3g4200d is avialable.

Return values
1is available
0not available

Definition at line 57 of file l3g4200d.c.

References l3g4200d_read8bit(), and L3G4200D_WHO_AM_I_REG.

Referenced by l3g4200d_init().

int8_t l3g4200d_deinit ( void  )

Deinit the gyroscope.

Definition at line 89 of file l3g4200d.c.

References L3G4200D_CTRL_REG1, and l3g4200d_write8bit().

int8_t l3g4200d_fifo_overrun ( void  )

Checks for fifo overrun.

Returns
0 = no overrun, else overrun

Definition at line 144 of file l3g4200d.c.

References L3G4200D_FIFO_SRC_REG, L3G4200D_OVRN, and l3g4200d_read8bit().

angle_data_t l3g4200d_get_angle ( void  )

Reads data for x,y and z angle.

Note
If all channels are required, this function is faster than reading values with l3g4200d_get_x/y/z_angle, because only a single readout is performed!

Definition at line 150 of file l3g4200d.c.

References i2c_stop(), i2c_write(), and L3G4200D_OUT_X_L.

Referenced by l3g4200d_get_angle_fifo().

int8_t l3g4200d_get_angle_fifo ( angle_data_t ret)

Reads angle values from fifo.

Note
This will only work if fifo/stream mode is enabled.
Parameters
retOutput data is written to this address
Returns
Number of data sets read (max. L3G4200D_FIFO_SIZE)

Definition at line 171 of file l3g4200d.c.

References L3G4200D_FIFO_SRC_REG, l3g4200d_get_angle(), and l3g4200d_read8bit().

int8_t l3g4200d_get_temp ( void  )

Reads temperature value.

Returns
1 degree/digit

Definition at line 203 of file l3g4200d.c.

References L3G4200D_OUT_TEMP, and l3g4200d_read8bit().

int16_t l3g4200d_get_x_angle ( void  )

Reads x angle value.

Returns
x angle value

Definition at line 184 of file l3g4200d.c.

References L3G4200D_OUT_X_L, and l3g4200d_read16bit().

int16_t l3g4200d_get_y_angle ( void  )

Reads y angle value.

Returns
y angle value

Definition at line 190 of file l3g4200d.c.

References L3G4200D_OUT_Y_L, and l3g4200d_read16bit().

int16_t l3g4200d_get_z_angle ( void  )

Reads z angle value.

Returns
z angle value

Definition at line 196 of file l3g4200d.c.

References L3G4200D_OUT_Z_L, and l3g4200d_read16bit().

int8_t l3g4200d_init ( void  )

Inits the gyroscope.

Return values
0if init succeeded
1if init failed

Definition at line 72 of file l3g4200d.c.

References l3g4200d_available(), L3G4200D_CTRL_REG1, L3G4200D_PD, l3g4200d_set_dps(), l3g4200d_write8bit(), L3G4200D_XEN, L3G4200D_YEN, and L3G4200D_ZEN.

uint16_t l3g4200d_read16bit ( uint8_t  addr)

Reads 2x8 bit register from gyroscopes.

Parameters
addraddress to read from (lower byte)
Returns
register content

Definition at line 221 of file l3g4200d.c.

References i2c_stop(), and i2c_write().

Referenced by l3g4200d_get_x_angle(), l3g4200d_get_y_angle(), and l3g4200d_get_z_angle().

uint8_t l3g4200d_read8bit ( uint8_t  addr)

Reads 8 bit register from gyroscopes.

Parameters
addraddress to read from
Returns
register content

Definition at line 209 of file l3g4200d.c.

References i2c_stop(), and i2c_write().

Referenced by l3g4200d_available(), l3g4200d_fifo_overrun(), l3g4200d_get_angle_fifo(), l3g4200d_get_temp(), l3g4200d_set_data_rate(), l3g4200d_set_dps(), and l3g4200d_set_fifomode().

uint8_t l3g4200d_set_data_rate ( uint8_t  set)

Sets the data rate [Hz].

Parameters
setone of L3G4200D_ODR_100HZ, L3G4200D_ODR_200HZ, L3G4200D_ODR_400HZ, L3G4200D_ODR_800HZ
Returns

Definition at line 119 of file l3g4200d.c.

References L3G4200D_CTRL_REG1, l3g4200d_read8bit(), and l3g4200d_write8bit().

uint8_t l3g4200d_set_dps ( uint8_t  set)

Sets the sensitivity value [dps].

Parameters
setOne of L3G4200D_250DPS, L3G4200D_500DPS or L3G4200D_2000DBS

Definition at line 97 of file l3g4200d.c.

References L3G4200D_CTRL_REG4, l3g4200d_read8bit(), and l3g4200d_write8bit().

Referenced by l3g4200d_init().

void l3g4200d_set_fifomode ( uint8_t  set)

Sets the fifo mode.

Note
To use stream or fifo mode, the fifo has to be enabled with l3g4200d_fifo_enable().
Parameters
setOne of L3G4200D_BYPASS, L3G4200D_FIFO, L3G4200D_STREAM, L3G4200D_STREAM_TO_FIFO or L3G4200D_BYPASS_TO_STREAM

Definition at line 131 of file l3g4200d.c.

References L3G4200D_FIFO_CTRL_REG, l3g4200d_read8bit(), and l3g4200d_write8bit().

void l3g4200d_write8bit ( uint8_t  addr,
uint8_t  data 
)

Writes 8 bit to gyroscope register.

Parameters
addraddress to write to
datadata to write

Definition at line 234 of file l3g4200d.c.

References i2c_stop(), and i2c_write().

Referenced by l3g4200d_deinit(), l3g4200d_fifo_enable(), l3g4200d_init(), l3g4200d_set_data_rate(), l3g4200d_set_dps(), and l3g4200d_set_fifomode().