Rleg  2
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Functions
mag_functions.c File Reference
#include "imu_functions.h"
Include dependency graph for mag_functions.c:

Go to the source code of this file.

Functions

int mag_write_reg (int i2c_dev, uint8_t reg, uint8_t data)
 Rev 0 - 11/11/2012 RLEG project - 2012. 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...
 

Function Documentation

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: