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.
main.cpp
- Committer:
- Future_FThierry
- Date:
- 2014-12-11
- Revision:
- 0:24c9d0b3277e
- Child:
- 1:4eaf2ea6eb62
File content as of revision 0:24c9d0b3277e:
#include "mbed.h"
#include <LSM6DS0.h>
I2C i2c(I2C_SDA, I2C_SCL);
DigitalOut myled(LED1);
Serial pc(SERIAL_TX, SERIAL_RX);
int main()
{
char data_write[6];
char data_read[6];
short X_Acc;
data_write[0] = LSM6DS0_WHO_AM_I;
i2c.write(LSM6DS0_ADDR, data_write, 1, 1); // no stop
i2c.read(LSM6DS0_ADDR, data_read, 2, 0);
pc.printf("who am I= %2x%c%c",data_read[0],0x0D,0X0A);
data_write[0]=LSM6DS0_CTRL_REG6_XL;
data_write[1]=0x20; // Set output Data Rate to 10Hz, exiting sleep mode
i2c.write(LSM6DS0_ADDR, data_write,2,0);
data_write[0]=LSM6DS0_CTRL_REG5_XL;
data_write[1]=0x08; //Enable X-Axis Accelerometer
i2c.write(LSM6DS0_ADDR, data_write,2,0);
while(1)
{
data_write[0]=LSM6DS0_OUT_X_XL;
i2c.write(LSM6DS0_ADDR, data_write, 1, 1); // no stop
i2c.read(LSM6DS0_ADDR, data_read,2,0);
X_Acc= (short)(((unsigned char)data_read[1]) << 8 | ((unsigned char)data_read[0]));
pc.printf("X_Acc= %d \n",X_Acc);
wait(1);
}
}