Hey, thanks for your image, help me a lot!, a i write this (still no work) with your image and @jremington register autoincrement help:
#include <stdio.h>
#include "system.h"
#include "i2c_opencores.h"
int _buff[6];
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 readAccel() {
//Read the data
I2C_start(I2C_OPENCORES_0_BASE, 0x53, 0); //Write mode
I2C_write(I2C_OPENCORES_0_BASE, 0x80 | 0x32 | 0x40, 0);
I2C_write(I2C_OPENCORES_0_BASE, 0x53 | 0x80, 1); //1 = Expect ACK
I2C_start(I2C_OPENCORES_0_BASE, 0x53, 0); //Write mode
I2C_write(I2C_OPENCORES_0_BASE, 0x80 | 0x32 | 0x40, 1); //1 = Expect ACK
I2C_start(I2C_OPENCORES_0_BASE, 0x53, 1); //Read mode
int i = 0;
for(i = 0; i < 6; i++)
_buff[i] = I2C_read(I2C_OPENCORES_0_BASE, 0);//i == 5 ? 1 : 0); //If is the last, expect ACK
//Read the values from the registers and convert to int (Each axis have 10 bits, in 2 Bytes LSB)
//int x = (((int)_buff[1]) << 8) | (int)_buff[0];
//int y = (((int)_buff[3]) << 8) | (int)_buff[2];
//int z = (((int)_buff[5]) << 8) | (int)_buff[4];
//printf("x: %d", x);
//printf(" y: %d", y);
//printf(" z: %d\n", z);
int j;
for(j = 0; j < 6; j++)
printf("_buff[%d] = %d", j, _buff[j]);
}
int main() {
printf("ADXL345: Initializing...\n");
I2C_init(I2C_OPENCORES_0_BASE, ALT_CPU_FREQ, 100000);
I2C_init(I2C_OPENCORES_0_BASE, ALT_CPU_FREQ, 100000);
//Put the ADXL345 in +- 4G
I2C_start(I2C_OPENCORES_0_BASE, 0x53, 0); //Write mode
I2C_write(I2C_OPENCORES_0_BASE, 0x31, 0);
I2C_write(I2C_OPENCORES_0_BASE, 0x01, 1); //1 = Expect ACK
//Put the ADXL345 in Measurement mode
I2C_start(I2C_OPENCORES_0_BASE, 0x53, 0); //Write mode
I2C_write(I2C_OPENCORES_0_BASE, 0x2D, 0);
I2C_write(I2C_OPENCORES_0_BASE, 0x08, 1); //1 = Expect ACK
while(1) {
readAccel(); //Read accel (x, y, z)
usleep(1000000);
}
return 0;
}
sorry if its bad post non-arduino code on the forum, but im realy on blank here. I do some debug print and the read from the registers are zero and im in the point of ask, was its bad???? This is bare-bones code, i delete all variables to hard-coded hex numbers to avoid some data type error, but all is the same.... if any have some idea, i would apreciate it. Thanks and greatings!