codice
Dependencies: X_NUCLEO_IKS01A1 mbed
Revision 2:20c97410676b, committed 2016-12-04
- Comitter:
- prolucus
- Date:
- Sun Dec 04 09:29:08 2016 +0000
- Parent:
- 1:c3bb15cf5b08
- Commit message:
- Aggiunte alcune annotazioni
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r c3bb15cf5b08 -r 20c97410676b main.cpp --- a/main.cpp Thu Dec 01 17:54:29 2016 +0000 +++ b/main.cpp Sun Dec 04 09:29:08 2016 +0000 @@ -1,4 +1,18 @@ #include "mbed.h" + +//ANNOTATIONS +// +//accelerometer: LSM6DS0 +// +// SDO/SA0 pin is connected to voltage supply -> device address is 1101011 +// +// CTRL_REG8: +// IF_ADD_INC default value: 1 -> Register address automatically increased +// during a multiple byte access with a serial +// interface (I2C) +// BLE default value: 0 -> Big Endian (LSB @ lower address) +// + #define ACC_ADD_W 0b11010110 #define ACC_ADD_R 0b11010111 #define X_OUT_1 0x28 @@ -11,22 +25,31 @@ #define WHO_AM_I 0x0F #define REFERENCE_G 0x0B + I2C myi2c(D14, D15); Serial pc (SERIAL_TX, SERIAL_RX); + //void testRead(); void testWrite(); + int read_reg(int reg_add); + void setup(void); + int merge_int(int val_msb, int val_lsb); + void write_reg(int reg_add, int data_in); + + int main () { - setup(); //testRead(); testWrite(); int out[2]; - while (1) - { //testWrite(); + + while(true) + { + //testWrite(); out[1]=read_reg(X_OUT_1); out[0]=read_reg(X_OUT_2); pc.printf("X: %d \n\r", merge_int(out[0], out[1])); @@ -38,13 +61,11 @@ pc.printf("Z: %d%d \n\r", out[1], out[0]); wait(1.0); } - - } + int read_reg(int reg_add) - { int status=0; char dato; @@ -64,6 +85,8 @@ return dato; //ritorno il dato } + + void setup(void) { pc.printf("Starting up the machine...\n\r"); @@ -71,12 +94,16 @@ return; } + + int merge_int(int val_msb, int val_lsb) { int to_return = val_lsb + val_msb<<8; return to_return; } + + /*void testRead() { int out[2]; @@ -84,6 +111,8 @@ pc.printf("WHO_AM_I: %d \n\r", out[1]); }*/ + + void write_reg(int reg_add, int data_in) { int status=0; @@ -102,6 +131,7 @@ } + /*void testWrite() {