Rleg  2
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Macros | Functions
imu_functions.h File Reference

Rev 0 - 06/11/2012 RLEG project - 2012. More...

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include "imu_regs.h"
Include dependency graph for imu_functions.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ASCII_0   0x30
 
#define SUCCESS   1
 
#define FAILURE   -1
 
#define ADD_ADXL345   0x53
 
#define ADD_ITG3200   0x68
 
#define ADD_HMC5883   0x1E
 

Functions

int acc_write_reg (int i2c_dev, uint8_t reg, uint8_t data)
 WRITE TO REGISTER. More...
 
uint8_t * acc_read_reg (int i2c_dev, uint8_t reg, uint8_t count)
 READ COUNT 8-BIT REGISTER IN SEQUENCE More...
 
int acc_init (int i2c_dev, uint8_t full_res, uint16_t rate, uint8_t range)
 INITIALIZE ACCELEROMETER. More...
 
int acc_read_all_data (int i2c_dev, short int *data)
 READ ALL DATA AT ONCE (X, Y and Z) More...
 
short int acc_read_data (int i2c_dev, int axis)
 READ DATA (X, Y or Z) More...
 
char * conv_byte_hex_bin (uint8_t *hvalue)
 
int acc_read_all_reg (int i2c_dev)
 Read all accelerometer data and print in stdio. More...
 
int gyr_write_reg (int i2c_dev, uint8_t reg, uint8_t data)
 WRITE TO REGISTER. More...
 
uint8_t * gyr_read_reg (int i2c_dev, uint8_t reg, uint8_t count)
 READ COUNT 8-BIT REGISTER IN SEQUENCE. More...
 
int gyr_init (int i2c_dev, float rate, short int lpf_bw, char clk_source, char *act)
 INITIALIZE GYROMETER. More...
 
int gyr_read_all_data (int i2c_dev, short int *data)
 READ ALL DATA AT ONCE (X, Y, Z and T) More...
 
short int gyr_read_data (int i2c_dev, int type)
 READ DATA (X, Y, Z or T) More...
 
int mag_write_reg (int i2c_dev, uint8_t reg, uint8_t data)
 WRITE TO REGISTER. More...
 
uint8_t * mag_read_reg (int i2c_dev, uint8_t reg, uint8_t count)
 READ COUNT 8-BIT REGISTER IN SEQUENCE. More...
 
int mag_init (int i2c_dev, uint8_t rate, uint8_t range, uint8_t samples_avg, uint8_t meas_mode, uint8_t op_mode)
 INITIALIZE MAGNETOMETER. More...
 
int mag_read_all_data (int i2c_dev, short int *data)
 READ ALL DATA AT ONCE (X, Y and Z) More...
 
short int mag_read_data (int i2c_dev, int axis)
 READ DATA (X, Y or Z) More...
 

Detailed Description

Rev 0 - 06/11/2012 RLEG project - 2012.

library of the I2C communication between Gumstix Overo Fire and 3 different devices: ADXL345, ITG3200 and HMC5883

Author
Caio Gustavo Mesquita Ângelo
Date
2012-2013

Definition in file imu_functions.h.

Macro Definition Documentation

#define ADD_ADXL345   0x53

Definition at line 36 of file imu_functions.h.

Referenced by devices_init(), and read_all_data().

#define ADD_HMC5883   0x1E

Definition at line 38 of file imu_functions.h.

Referenced by devices_init(), and read_all_data().

#define ADD_ITG3200   0x68

Definition at line 37 of file imu_functions.h.

Referenced by devices_init(), and read_all_data().

#define ASCII_0   0x30

Definition at line 27 of file imu_functions.h.

Referenced by conv_byte_hex_bin().

#define FAILURE   -1

Definition at line 30 of file imu_functions.h.

#define SUCCESS   1

Definition at line 29 of file imu_functions.h.

Function Documentation

char* conv_byte_hex_bin ( uint8_t *  hvalue)

Definition at line 184 of file acc_functions.c.

References ASCII_0, and bits.

Referenced by acc_read_all_reg().

185 {
186  char bits[9];
187  int i;
188  for( i=0; i<8; i++)
189  {
190  bits[i]=((*hvalue)<<i)>>7+ASCII_0;
191  }
192  bits[8]='\0';
193  return bits;
194 }
#define ASCII_0
Definition: imu_functions.h:27
static uint8_t bits
Definition: spi_functions.c:18

Here is the caller graph for this function:

int mag_init ( int  i2c_dev,
uint8_t  rate,
uint8_t  range,
uint8_t  samples_avg,
uint8_t  meas_mode,
uint8_t  op_mode 
)

INITIALIZE MAGNETOMETER.

Definition at line 53 of file mag_functions.c.

References MAG_CONFIG_A, MAG_CONFIG_B, MAG_MODE, and mag_write_reg().

Referenced by devices_init().

54 {
55  uint8_t data=0;
56 
57  switch(rate){
58  case 15:
59  data=0x10;
60  break;
61  case 0:
62  data=0x00;
63  break;
64  case 1:
65  data=0x04;
66  break;
67  case 3:
68  data=0x08;
69  break;
70  case 7:
71  data=0x0C;
72  break;
73  case 30:
74  data=0x14;
75  break;
76  case 75:
77  data=0x18;
78  break;
79  default:
80  perror("Wrong rate value");
81  break;
82  }
83 
84  switch(samples_avg){
85  case 8:
86  data=data|0x60;
87  break;
88  case 1:
89  break;
90  case 2:
91  data=data|0x20;
92  break;
93  case 4:
94  data=data|0x40;
95  break;
96  default:
97  perror("Wrong samples_avg value");
98  break;
99  }
100 
101  data+=meas_mode;
102 
103  if(mag_write_reg(i2c_dev, MAG_CONFIG_A, data)<0){
104  perror("Write in Configuration register A unsuccesful");
105  return -1;
106  }
107 
108  if(mag_write_reg(i2c_dev, MAG_CONFIG_B, range<<5)<0){
109  perror("Write in configuration register B unsuccesful");
110  return -1;
111  }
112 
113  if(mag_write_reg(i2c_dev, MAG_MODE, op_mode)<0){
114  perror("Write in mode register unsuccesful");
115  return -1;
116  }
117 
118  return 1;
119 }
#define MAG_CONFIG_A
Definition: imu_regs.h:64
int mag_write_reg(int i2c_dev, uint8_t reg, uint8_t data)
Rev 0 - 11/11/2012 RLEG project - 2012.
Definition: mag_functions.c:10
#define MAG_MODE
Definition: imu_regs.h:66
#define MAG_CONFIG_B
Definition: imu_regs.h:65

Here is the call graph for this function:

Here is the caller graph for this function: