Lysenko Mami
/
IMU3000
Code for communicating with IMU3000 in I2C
main.cpp
- Committer:
- godziram
- Date:
- 2012-10-29
- Revision:
- 0:2ede7cf4f8fa
File content as of revision 0:2ede7cf4f8fa:
#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); }