Hello people,
I am trying to communicate with the ADXL345 accelerometer via I2C with the generated drivers from HalCoGen. It looks that I am currently sending correctly the data to the SDA line, but I cannot receive anything.
The frame for this device for I2C must be as follows:
My first step is to read the device id (should read 0xE5).
- The slave address is 0x53, which interprets to 0xA6 for write, 0xA7 for read.
- The register to get the device id is 0x00.
The screenshot of my logic analyzer currently is:
I assume it looks good for sending.
My problem is that I cannot receive anything.
I tried to keep my code as simple as possible:
i2cInit(); /* Configure address of Slave to talk to */ i2cSetSlaveAdd(i2cREG1, 0x53); /* Set mode as Master */ i2cSetMode(i2cREG1, I2C_MASTER); /* Transmit Start Condition */ i2cSetStart(i2cREG1); /* Tranmit 3 bytes of data in Polling mode */ i2cSend(i2cREG1, 3, TX_Data_Master); i2cSetDirection(i2cREG1, I2C_RECEIVER); i2cSetStart(i2cREG1); i2cReceive(i2cREG1, 1, RX_Data_Master); while(1);
In any case I attach my whole project. I would be grateful for any suggestions.
3632.I2C.zip
Kind regards,
Stelios