Lysenko Mami
/
IMU3000
Code for communicating with IMU3000 in I2C
Revision 0:2ede7cf4f8fa, committed 2012-10-29
- Comitter:
- godziram
- Date:
- Mon Oct 29 18:28:30 2012 +0000
- Commit message:
- IMU3000
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Oct 29 18:28:30 2012 +0000 @@ -0,0 +1,57 @@ +#include "mbed.h" + +I2C i2c(p9, p10); +Serial pc(USBTX, USBRX); + +Ticker tick; //Timer +double interval = 10; //[ms] + +const int adrIMU3000 = 0xD0;//8-bit write + + +void measure(); + +int main() { + + i2c.frequency(400000); //set 400kHz + + pc.baud(115200); + + char PWR_M[2] = {0x3E, 0x80}; + i2c.write(adrIMU3000, PWR_M, 2, true); + char SMPL[2] = {0x15, 0x00}; + i2c.write(adrIMU3000, SMPL, 2, true); + char DLPF[2] = {0x16, 0x18}; + i2c.write(adrIMU3000, DLPF, 2, true); + char INT_C[2] = {0x17, 0x05}; + i2c.write(adrIMU3000, INT_C, 2, true); + char PWR_M2[2] = {0x3E, 0x00}; + i2c.write(adrIMU3000, PWR_M2, 2, true); + + while(true) + measure(); + //tick.attach_us(&measure, interval); + +} + +void measure() +{ + char adrIMU3000_y[1]; + char readIMU3000[8]; + + short int read_x_2byte = 0; + short int read_y_2byte = 0; + short int read_z_2byte = 0; + + adrIMU3000_y[0] = 0x1D; //register GYRO_XOUT_H + + i2c.write(adrIMU3000, adrIMU3000_y , 1); + i2c.read(adrIMU3000, readIMU3000, 8); + + read_x_2byte = ((readIMU3000[0] << 8) + readIMU3000[1]); + read_y_2byte = ((readIMU3000[2] << 8) + readIMU3000[3]); + read_z_2byte = ((readIMU3000[4] << 8) + readIMU3000[5]); + + pc.printf("%d, %d, %d\n", read_x_2byte, read_y_2byte, read_z_2byte); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Oct 29 18:28:30 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e2ed12d17f06 \ No newline at end of file