Other Parts Discussed in Thread: ENERGIA
Tool/software: Code Composer Studio
Hello ,
I have been using TIVA +adxl345 using energia .I was not able get the value on the serial monitor . If any one worked please mention any changes need to made in the code
#include<Wire.h>
#define device (0x53)
//#define POWER_CTL Ox2D
byte buff[6];
char POWER_CTL = 0x2D; //Power Control Register
char DATA_FORMAT = 0x31;
char DATAX0 = 0x32; //X-Axis Data 0
char DATAX1 = 0x33; //X-Axis Data 1
char DATAY0 = 0x34; //Y-Axis Data 0
char DATAY1 = 0x35; //Y-Axis Data 1
char DATAZ0 = 0x36; //Z-Axis Data 0
char DATAZ1 = 0x37; //Z-Axis Data 1
void setup()
{
// put your setup code here, to run once:
Wire.begin();
Serial.begin(9600);
writeTo(DATA_FORMAT,0x01);
writeTo(POWER_CTL,0x08);
}
void loop()
{
// put your main code here, to run repeatedly:
readaccl();
delay(500);
}
void readaccl()
{
uint8_t bytetoread=6;
readfrom( DATA_FORMAT, bytetoread , buff);
int x=((int ) buff[1] <<8)| buff[0];
int y=((int ) buff[3] <<8)| buff[2];
int z=((int ) buff[5] <<8)| buff[4];
Serial.print("x :");
Serial.print(x);
Serial.print("y :");
Serial.print(y);
Serial.print("z :");
Serial.print(z);
}
void writeTo(byte addr,byte value)
{
Wire.beginTransmission(device);
Wire.write(addr);
Wire.write(value);
Wire.endTransmission();
}
void readfrom(byte addr,int num,byte buff[])
{
Wire.beginTransmission(device);
Wire.write(addr);
Wire.endTransmission();
Wire.beginTransmission(device);
Wire.requestFrom(device,num);
int i=0;
while(Wire.available())
{
buff[i]=Wire.read();
i++;
}
// Wire.endTransmission();
}