codice
Dependencies: X_NUCLEO_IKS01A1 mbed
main.cpp
- Committer:
- russof
- Date:
- 2016-11-24
- Revision:
- 0:44863862864b
- Child:
- 1:c3bb15cf5b08
File content as of revision 0:44863862864b:
#include "mbed.h" #include "I2C.h" #include "Serial.h" #include "x_nucleo_iks01a1.h" #define OUT_X_XL (0x28) #define CTRL_REG6_XL (0x20) #define XL_ADDR (0b1101010) //port D15 SCL clock //port D14 SDA data Serial pc_comm(SERIAL_TX, SERIAL_RX); I2C xel_bus(I2C_SDA, I2C_SCL); char xel_outx[2], xel_outy[2], xel_outz[2]; void setupRoutine(); void writeRoutine(); int readRoutine(); int main() { setupRoutine(); while(1) { pc_comm.printf("I'm working!!!\n"); if( !readRoutine() ) pc_comm.printf("Data read failed\n"); else pc_comm.printf("%d %d\n",xel_outx[0],xel_outx[1]); wait(1.0); //xel_bus.read(0x2A,xel_outx,2); //xel_bus.read(0x28,xel_outx,2); } } void setupRoutine() { //pc_comm = new Serial(D1,D0,9600); //xel_bus = new I2C(D15, D14); xel_bus.frequency(10); xel_Routine(); //CTRL_REG6_XL = 0x20; //write to register to enable accelerometer //fondo scala ±2g, ODR= 10Hz ----> BW=408Hz, Filtro AA= 408Hz //CTRL_REG1_G = 0x10; //write to register to enable the accelerometer and gyroscope } void xel_Routine() { char config[2]; config[0] = CTRL_REG6_XL; config[1] = 0x00; xel_bus.write(XL_ADDR, config, 1); // write to register to enable accelerometer config[1] = 0x20; xel_bus.write(XL_ADDR, config, 2); // fondo scala ±2g, ODR= 10Hz ----> BW=408Hz, Filtro AA= 408Hz } int readRoutine() { int result; //xel_bus.start(); xel_bus.write(XL_ADDR, OUT_X_XL, 1, 1); result = xel_bus.read(XL_ADDR, xel_outx, 2, 0); xel_bus.stop(); }