Checking 6-axis sensor of accelerometer(z-axis)

Dependencies:   mbed

Revision:
0:441039f94b75
diff -r 000000000000 -r 441039f94b75 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Dec 29 05:29:52 2020 +0000
@@ -0,0 +1,35 @@
+#include "mbed.h"
+Serial pc(USBTX, USBRX);
+I2C i2c(PB_7,PB_6);
+DigitalOut conv(A3);
+
+const int addr_accel_gyro = 0xD0;
+char cmd[2];
+char data[1];
+char xh[1];
+char xl[1];
+
+int main()
+{
+    conv = 1;
+    i2c.frequency(100000);
+    cmd[0]=0x6B;
+    cmd[1]=0x00;
+    i2c.write(addr_accel_gyro,cmd,2);
+    cmd[0] = 0x37;
+    cmd[1] = 0x02;
+    i2c.write(addr_accel_gyro,cmd,2);
+    while(1) {
+        data[0] = 0x3F;
+        i2c.write(addr_accel_gyro,data,1);
+        i2c.read(addr_accel_gyro|0x01,xh,1);
+        data[0] = 0x40;
+        i2c.write(addr_accel_gyro,data,1);
+        i2c.read(addr_accel_gyro|0x01,xl,1);
+        //pc.printf("xh = 0x%02X,xl = 0x%02X\r\n",xh[0],xl[0]);
+        double  acc_ax = short((xh[0]<<8) | (xl[0]));
+        double AX = (acc_ax)*2/32764*9.81;
+        pc.printf("AZ = %f\r\n",AX);
+        wait(0.5);
+    }
+}
\ No newline at end of file