Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 16:1121b66ef27b
- Parent:
- 14:762baad15486
- Child:
- 18:7066655957b3
diff -r 762baad15486 -r 1121b66ef27b main.cpp
--- a/main.cpp Sun Jan 11 04:34:14 2015 +0000
+++ b/main.cpp Sun Jan 11 06:15:22 2015 +0000
@@ -8,7 +8,8 @@
#define ADXL_PWRCTL_MEASURE (0x01 << 3)
//Gyroscope
-#define ITG3200_ADDRESS (0xD0 >> 1)
+#define ITG3200_ADDRESS_W (0xD0)
+#define ITG3200_ADDRESS_R (0xD1)
#define ITG3200_REGISTER_XMSB (0x1D)
#define ITG3200_REGISTER_DLPF_FS (0x16)
#define ITG3200_FULLSCALE (0x03 << 3)
@@ -24,13 +25,14 @@
void init_adxl345();
void read_adxl345();
-//void init_itg3200();
+void init_itg3200();
+void read_itg3200();
//void init_hmc5843();
Serial pc(USBTX, USBRX); //tx, rx
int accelerometer_data[3];
-//int gyro_data[3];
+int gyro_data[3];
//int magnetometer_data[3];
PwmOut led(LED1);
@@ -41,7 +43,7 @@
init_adxl345();
//init_hmc5843();
- //init_itg3200();
+ init_itg3200();
//pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down.\n");
@@ -57,7 +59,8 @@
led = brightness;
}
*/
- read_adxl345();
+ //read_adxl345();
+ read_itg3200();
}
}
@@ -91,27 +94,34 @@
pc.printf("ACCEL: %i\t%i\t%i", accelerometer_data[0], accelerometer_data[1], accelerometer_data[2]);
}
-/*
+
void init_itg3200() {
- byte data = 0;
+ char data[2];
+ data[0] = ITG3200_REGISTER_DLPF_FS;
+ data[1] = ITG3200_FULLSCALE | ITG3200_42HZ;
- i2c_write(ITG3200_ADDRESS, ITG3200_REGISTER_DLPF_FS, ITG3200_FULLSCALE | ITG3200_42HZ);
+ i2c.write(ITG3200_ADDRESS_W, data,2);
- i2c_read(ITG3200_ADDRESS, ITG3200_REGISTER_DLPF_FS, 1, &data);
+ i2c.read(ITG3200_ADDRESS_R, data, 1);
- Serial.println((unsigned int)data);
+ pc.printf("%i\n",(unsigned int)data);
}
void read_itg3200() {
- bytes bytes[6];
+ char bytes[6];
memset(bytes,0,6);
+ bytes[0] = ITG3200_REGISTER_XMSB;
- i2c_read(ITG3200_ADDRESS, ITG3200_REGISTER_XMSB, 6, bytes);
+ i2c.write(ITG3200_ADDRESS_W, bytes, 1);
+ i2c.read(ITG3200_ADDRESS_R, bytes, 6);
+
for (int i=0;i<3;++i) {
gyro_data[i] = (int)bytes[2*i + 1] + (((int)bytes[2*i]) << 8);
}
+
+ pc.printf("GYRO: %i\t%i\t%i", gyro_data[0], gyro_data[1], gyro_data[2]);
}
-
+/*
void init_hmc5843() {
bytes data = 0;