Sistemi_digitali_integrati / Mbed 2 deprecated Sensor

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
ymerdushku
Date:
Thu Dec 01 10:03:37 2016 +0000
Child:
1:68e3916ad434
Commit message:
a

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	Thu Dec 01 10:03:37 2016 +0000
@@ -0,0 +1,35 @@
+#include "mbed.h"
+#include <I2C.h>
+
+#define LSM6DS0_ADDRESS_WRITE (0xD4) // Configuration Register_write
+#define LSM6DS0_ADDRESS_READ (0xD5)
+
+I2C i2c(I2C_SDA,I2C_SCL);
+Serial pc(SERIAL_TX, SERIAL_RX);
+
+int main() {
+
+}
+
+int setREG_I2C(char REG_ADDR_DATA[2]){ //argument to pass : address register and data to write in
+i2c.start(); //send start bit
+if ((i2c.write(LSM6DS0_ADDRESS_WRITE,REG_ADDR_DATA,2,0))!=0){ //ADDR+SUB+DATA+STOP, return 0 if ack
+        pc.printf("Error, not ack\n");
+        return 0;       
+    } else return 1;
+}
+
+
+char readREG_I2C(char REG_ADDR[1]){ //argument to pass : address register to read
+char data_read[1];
+i2c.start(); //send start bit
+if ((i2c.write(LSM6DS0_ADDRESS_WRITE,REG_ADDR,1,1))==0){ //ADDR+SUB, return 0 if ack
+    if((i2c.read(LSM6DS0_ADDRESS_READ,data_read,1,0))==0){} //ADDR+data+STOP, return 0 if ack
+            else{
+            pc.printf("Error, not ack\n");
+            }
+    } else{
+        pc.printf("Error, not ack\n");
+        }
+    return data_read[0];
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Dec 01 10:03:37 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/d75b3fe1f5cb
\ No newline at end of file