Llosa de Viango Tollos – ITG3200.c

Introduction

Features

Getting started

Download


Libraries

  Tollos libraries

  Device libraries

    boards

    microcontrollers

    peripherals


Background

  Sample application

  Troubleshooting

ITG3200.c – gyroscope device I/O for Tollos

These functions provide basic IO for using the ITG3200 3-axis gyroscope device, attached via I2C.

The following connections are assumed:

  • SCL & SDA ... to I2C bus SCL & SDA, with appropriate pullups (channel is selectable)
  • CS ... to VCC (+3.3V) [enable I2C mode]
  • INT ... to a suitable input bit pin
  • AD0 ... to GND or VCC (I2C address 0x68/0x69)
  • CLKIN ... to ground
  • REGOUT & CPOUT ... capacitors to ground
  • RESV-G ... to GND
  • VCC, VLOGIC, & GND ... to suitable power rails, with bypass capacitors

This code assumes only one ITG3200 device will be used on a controller, so some state information can be held (the device channel and address). This simplifies the tollosGyro interface and allows initialization checking.
Functions
 gyroGetXYZIO   read latest x, y, and z angular rates
 gyroInitIO   configure and initialize gyroscope
 gyroRateIO   change update rate of gyroscope
 gyroStopIO   stop and power-down gyroscope
 gyroTemperatureIO   return current gyroscope die temperature

gyroGetXYZIO – read latest x, y, and z angular rates

int gyroGetXYZIO(int *x, int *y, int *z);

x, y, z – receive angular rates [in milli-degrees/sec]

returns 0 if data read, −1 if the device is not initialized, or −2 if there was an error reading the data (or no data ready)

Results are returned scaled to milli-degrees/sec; resolution is 69-70 md/s.

This should normally be called only after a Data Ready interrupt; the interrupt is cleared by calling this.

gyroInitIO – configure and initialize gyroscope

int gyroInitIO(uint channel);

channel – I2C channel on which device is to be found

returns 0 if initialized OK, negative if error

The tollosGyro interface expects:

  • an update rate of at least 25 Hz (but need not be higher than that on initialization, to save power)
  • an interrupt [from pin INT1] when Data Ready is raised.

The caller should set up the interrupt handler before calling this function, or clear Data Ready by calling gyroGetXYZIO.

All three axes of the gyroscope are enabled. Current consumption should be about 6.5mA.

gyroRateIO – change update rate of gyroscope

int gyroRateIO(uint rate);

rate – rate requested [Hz, 1..200]

returns the rate chosen if the rate was changed OK, or −1 if error (rate zero or too high, or a bus error)

The gyroscope will be set to a slowest available rate that is >= the requested rate, to minimize resource usage. The low-pass filter bandwidth is set to match or exceed the rate.

To ensure working with 100kHz I2C, the maximum rate is limited to 200Hz – but note that this may use significant processor bandwidth.

gyroStopIO – stop and power-down gyroscope

int gyroStopIO(void);

returns 0 if gyroscope stopped OK, negative if an error or it was not running.

gyroTemperatureIO – return current gyroscope die temperature

int gyroTemperatureIO(void);

returns the latest temperature reading in milli-degrees Celsius, or GYRO_NOTEMP if no reading is available

Converts the recorded raw temperature saved during the last read.

Tollos and these web pages were written by Mike Cowlishaw; Please send me any corrections, suggestions, etc.
All content © Mike Cowlishaw, 2010–2012, except where marked otherwise. All rights reserved. The pages here are for non-commercial use only (see the separate licence for Tollos source code). Privacy policy: the Speleotrove website records no personal information and sets no ‘cookies’. However, statistics, etc. might be recorded by the web hosting service.

This page was last updated on 2011-12-30 by c2wiki.