Only for Future hands-on

Dependencies:   LSM6DS0 mbed

Committer:
Future_FThierry
Date:
Thu Dec 11 00:25:34 2014 +0000
Revision:
0:24c9d0b3277e
Child:
1:4eaf2ea6eb62

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Future_FThierry 0:24c9d0b3277e 1 #include "mbed.h"
Future_FThierry 0:24c9d0b3277e 2 #include <LSM6DS0.h>
Future_FThierry 0:24c9d0b3277e 3
Future_FThierry 0:24c9d0b3277e 4 I2C i2c(I2C_SDA, I2C_SCL);
Future_FThierry 0:24c9d0b3277e 5
Future_FThierry 0:24c9d0b3277e 6 DigitalOut myled(LED1);
Future_FThierry 0:24c9d0b3277e 7
Future_FThierry 0:24c9d0b3277e 8 Serial pc(SERIAL_TX, SERIAL_RX);
Future_FThierry 0:24c9d0b3277e 9
Future_FThierry 0:24c9d0b3277e 10 int main()
Future_FThierry 0:24c9d0b3277e 11 {
Future_FThierry 0:24c9d0b3277e 12 char data_write[6];
Future_FThierry 0:24c9d0b3277e 13 char data_read[6];
Future_FThierry 0:24c9d0b3277e 14 short X_Acc;
Future_FThierry 0:24c9d0b3277e 15
Future_FThierry 0:24c9d0b3277e 16 data_write[0] = LSM6DS0_WHO_AM_I;
Future_FThierry 0:24c9d0b3277e 17 i2c.write(LSM6DS0_ADDR, data_write, 1, 1); // no stop
Future_FThierry 0:24c9d0b3277e 18 i2c.read(LSM6DS0_ADDR, data_read, 2, 0);
Future_FThierry 0:24c9d0b3277e 19
Future_FThierry 0:24c9d0b3277e 20 pc.printf("who am I= %2x%c%c",data_read[0],0x0D,0X0A);
Future_FThierry 0:24c9d0b3277e 21
Future_FThierry 0:24c9d0b3277e 22 data_write[0]=LSM6DS0_CTRL_REG6_XL;
Future_FThierry 0:24c9d0b3277e 23 data_write[1]=0x20; // Set output Data Rate to 10Hz, exiting sleep mode
Future_FThierry 0:24c9d0b3277e 24
Future_FThierry 0:24c9d0b3277e 25 i2c.write(LSM6DS0_ADDR, data_write,2,0);
Future_FThierry 0:24c9d0b3277e 26
Future_FThierry 0:24c9d0b3277e 27 data_write[0]=LSM6DS0_CTRL_REG5_XL;
Future_FThierry 0:24c9d0b3277e 28 data_write[1]=0x08; //Enable X-Axis Accelerometer
Future_FThierry 0:24c9d0b3277e 29
Future_FThierry 0:24c9d0b3277e 30 i2c.write(LSM6DS0_ADDR, data_write,2,0);
Future_FThierry 0:24c9d0b3277e 31
Future_FThierry 0:24c9d0b3277e 32 while(1)
Future_FThierry 0:24c9d0b3277e 33 {
Future_FThierry 0:24c9d0b3277e 34 data_write[0]=LSM6DS0_OUT_X_XL;
Future_FThierry 0:24c9d0b3277e 35 i2c.write(LSM6DS0_ADDR, data_write, 1, 1); // no stop
Future_FThierry 0:24c9d0b3277e 36 i2c.read(LSM6DS0_ADDR, data_read,2,0);
Future_FThierry 0:24c9d0b3277e 37
Future_FThierry 0:24c9d0b3277e 38 X_Acc= (short)(((unsigned char)data_read[1]) << 8 | ((unsigned char)data_read[0]));
Future_FThierry 0:24c9d0b3277e 39
Future_FThierry 0:24c9d0b3277e 40 pc.printf("X_Acc= %d \n",X_Acc);
Future_FThierry 0:24c9d0b3277e 41 wait(1);
Future_FThierry 0:24c9d0b3277e 42 }
Future_FThierry 0:24c9d0b3277e 43
Future_FThierry 0:24c9d0b3277e 44 }