Subversion Repositories FlightCtrl

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1993 - 1
#include <Wire.h>
2
#include <bma180.h>
3
#define DEBUGOFF
4
 
5
BMA180 bma180 = BMA180(BMA180_ADDRESS_SDO_LOW);
6
 
7
 
8
volatile byte newData=0;
9
volatile unsigned int countISR=0;
10
unsigned int served=0;
11
 
12
void BMAISR(void)
13
{
14
   countISR++;
15
   //bma180.readAccel();
16
   newData=1;
17
}
18
 
19
void setup()
20
{
21
  Wire.begin();
22
  Serial.begin(115200);
23
  bma180.SoftReset();
24
  bma180.enableWrite();
25
  int sversion;
26
  int id;
27
  bma180.getIDs(&id,&sversion);
28
  Serial.print("Id = ");
29
  Serial.print(id,DEC);
30
  Serial.print(" v.");
31
  Serial.println(sversion,HEX);
32
  bma180.SetFilter(bma180.F10HZ);
33
  bma180.setGSensitivty(bma180.G15);
34
  attachInterrupt(0, BMAISR, RISING);
35
  bma180.SetSMPSkip();
36
  bma180.SetISRMode();
37
  bma180.disableWrite();
38
  delay(2000);
39
}
40
 
41
void loop()
42
{
43
  if (newData)
44
  {
45
      newData=0;
46
      bma180.readAccel();
47
      Serial.print("[");
48
      Serial.print(bma180.x,DEC);
49
      Serial.print(" ");
50
      Serial.print(bma180.y,DEC);
51
      Serial.print(" ");
52
      Serial.print(bma180.z,DEC);
53
      Serial.println("]");
54
  }
55
 #ifdef DEBUGON
56
  if (millis() > tAlive)
57
  {
58
     bma180.readAccel();
59
      Serial.print("ISR's=");
60
      Serial.print(countISR);
61
      Serial.print(" served=");
62
      Serial.println(served);
63
      Serial.print("t=");
64
      Serial.print(bma180.temp);
65
      Serial.print("[");
66
      Serial.print(bma180.x,DEC);
67
      Serial.print(" ");
68
      Serial.print(bma180.y,DEC);
69
      Serial.print(" ");
70
      Serial.print(bma180.z,DEC);
71
      Serial.println("]");
72
 
73
     tAlive=millis()+5000;
74
     Serial.print("filter reg=");
75
     Serial.println(bma180.getRegValue(0x20),BIN);
76
     Serial.print("status_reg1=");
77
     Serial.println(bma180.getRegValue(0x09),BIN);
78
     Serial.print("status_reg2=");
79
     Serial.println(bma180.getRegValue(0x0A),BIN);
80
     Serial.print("status_reg3=");
81
     Serial.println(bma180.getRegValue(0x0B),BIN);
82
     Serial.print("status_reg4=");
83
     Serial.println(bma180.getRegValue(0x0C),BIN);
84
     Serial.print("ctrl_reg0=");
85
     Serial.println(bma180.getRegValue(0x0d),BIN);
86
     Serial.print("ctrl_reg1=");
87
     Serial.println(bma180.getRegValue(0x0e),BIN);
88
     Serial.print("ctrl_reg2=");
89
     Serial.println(bma180.getRegValue(0x0f),BIN);
90
     Serial.print("ctrl_reg3=");
91
     Serial.println(bma180.getRegValue(0x21),BIN);
92
     Serial.print("ctrl_reg4=");
93
     Serial.println(bma180.getRegValue(0x22),BIN);
94
 }
95
 #endif
96
}
97
 
98
 
99