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.
Revision 24:e8fd339db02e, committed 2015-01-12
- Comitter:
- mlimbird
- Date:
- Mon Jan 12 13:47:19 2015 +0000
- Parent:
- 23:0baaa24e04d8
- Commit message:
- Just making sure everything is up to date.
Changed in this revision
9DOF.h | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/9DOF.h Sun Jan 11 19:54:10 2015 +0000 +++ b/9DOF.h Mon Jan 12 13:47:19 2015 +0000 @@ -32,6 +32,7 @@ void read_itg3200(I2C i2c, int *data); void init_hmc5883(I2C i2c); void read_hmc5883(I2C i2c, int *data); +void twosComp2int(int *data, int size); //This function initializes the Digital Accelerometer ADXL345 void init_adxl345(I2C i2c) { @@ -56,6 +57,7 @@ for (int i=0;i<3;++i) { data[i] = (int)bytes[2*i] + (((int)bytes[2*i + 1]) << 8); } + twosComp2int(data, 3); } @@ -81,6 +83,7 @@ for (int i=0;i<3;++i) { data[i] = (int)bytes[2*i + 1] + (((int)bytes[2*i]) << 8); } + twosComp2int(data, 3); } void init_hmc5883(I2C i2c) { @@ -89,7 +92,9 @@ data[1] = HMC5883_MEASMODE_CONT; i2c.write(HMC5883_ADDRESS_W, data, 2); - i2c.read(HMC5883_ADDRESS_R, data, 1); + + i2c.write(HMC5883_ADDRESS_W, data, 1); + i2c.read(HMC5883_ADDRESS_R, data, 2); } void read_hmc5883(I2C i2c, int *data) { @@ -103,6 +108,14 @@ for (int i=0;i<3;++i) { data[i] = (int)bytes[2*i + 1] + (((int)bytes[2*i]) << 8); } + twosComp2int(data, 3); +} + +void twosComp2int(int *data, int size) { + for(int i = 0; i < size; i++){ + if(data[i] >= 32768) + data[i] = -(data[i] - 32768 + 1); + } } #endif \ No newline at end of file
--- a/main.cpp Sun Jan 11 19:54:10 2015 +0000 +++ b/main.cpp Mon Jan 12 13:47:19 2015 +0000 @@ -22,10 +22,10 @@ while(1) { //read from each IC read_adxl345(i2c, accelerometer_data); - pc.printf("ACCEL: %i\t%i\t%i", accelerometer_data[0], accelerometer_data[1], accelerometer_data[2]); + pc.printf("ACCEL: %i\t%i\t%i\n", accelerometer_data[0], accelerometer_data[1], accelerometer_data[2]); read_itg3200(i2c, gyro_data); - pc.printf("GYRO: %i\t%i\t%i", gyro_data[0], gyro_data[1], gyro_data[2]); + pc.printf("GYRO: %i\t%i\t%i\n", gyro_data[0], gyro_data[1], gyro_data[2]); read_hmc5883(i2c, magnetometer_data); - pc.printf("Magnet: %i\t%i\t%i", magnetometer_data[0], magnetometer_data[1], magnetometer_data[2]); + pc.printf("Magnet: %i\t%i\t%i\n", magnetometer_data[0], magnetometer_data[1], magnetometer_data[2]); } } \ No newline at end of file