I2C communication Problem

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I'm trying to interface my PSoC4 BLE to ADXL345.

   

I've set up the wiring as required, following sparkfun's hookup guide.

   

I'm using the following code to read registers

   

uint8 Accelerometer_RegRead(uint8 reg, uint8 *value)
{
    uint8 ackStatus = COMM_FAIL;
    ackStatus = I2C_I2CMasterSendStart(ACCELEROMETER_ADDR, ACC_WRITE);
    UART_UartPutChar(ackStatus);
    if(ackStatus == I2C_I2C_MSTR_NO_ERROR)
    {
        ackStatus = I2C_I2CMasterWriteByte(reg);
        ackStatus = I2C_I2CMasterSendRestart(ACCELEROMETER_ADDR, ACC_READ);
        *value = I2C_I2CMasterReadByte(I2C_I2C_NAK_DATA);
    }
    ackStatus = I2C_I2CMasterSendStop();
    UART_UartPutChar(ackStatus);
    return(ackStatus);
}

   

The first ackStatus gives 0x02 ie. I2C_I2C_MSTR_ERR_LB_NAK (Last Byte Naked) [No idea how to tackle this, any help appreciated]

   

and the second one gives 0x00 ie. no error

   

 

   

I tried this code instead too (Replacing the ones above)-

   

I2C_I2CMasterSendStart(ACCELEROMETER_ADDR, I2C_I2C_WRITE_XFER_MODE);

   

I2C_I2CMasterSendRestart(ACCELEROMETER_ADDR, I2C_I2C_READ_XFER_MODE);

   

Still the o/p was same as above

   

 

   

This happens in the cycle where I'm supposed to read the DevID register to verify integrity of data in device, so I can't say anything about the working of the Accelerometer itself.

   

How can I check that and is there anything I can do further

   

 

   

Regards,

   

Viraj

   

EDIT:- Spellings

0 Likes
1 Solution
Anonymous
Not applicable

Never mind I solved it. The Alternate addresses & the normal addresses of the ADXL345 and got mixed with the alternate and normal Read and Write addresses. I checked it after you pointed it out and exchanged 0x1D with 0x53.

   

Now I've sorted it out and getting the reading in 16 unsigned bits

   

Thanks for the help Bob,

   

Regards,

   

Viraj

View solution in original post

0 Likes
5 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

What value has the ACCELEROMETER_ADDR and what is the ADXL345's pin 12 tied to?

   

What is the value of your uint8 reg?

   

Which board are you using and which pins are you using for I2C?

   

Move the first UART_UartPutChar(ackStatus) out of the I2C transaction, this might take a reasonable time.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

ACCLEROMETER_ADDR is 0x1D, and I'm using the ADXL345 Breakout module, so there's no pin 12.

   

This is the only Device that's communicating on I2C with the PSoC so I'm assuming no Alternate addresses are required.

   

I'm giving uint8 reg 0x00 as I want to verify the datasheet and actual value of the DevID (It's supposed to be 0xE5 but coming out 0x00 because the I2C communication has some problem)

   

I'm using CY8KIT-042-BLE kit, and for SCL - P0[1]::SDA - P0[0]

   

I've run This code too-

   

uint8 Accelerometer_RegRead(uint8 reg, uint8 *value)
{
    uint8 ackStatus1 = COMM_FAIL;
    uint8 ackStatus2 = COMM_FAIL;
    ackStatus1 = I2C_I2CMasterSendStart(ACCELEROMETER_ADDR, I2C_I2C_WRITE_XFER_MODE);
    if(ackStatus1 == I2C_I2C_MSTR_NO_ERROR)
    {
        ackStatus1 = I2C_I2CMasterWriteByte(reg);
        ackStatus1 = I2C_I2CMasterSendRestart(ACCELEROMETER_ADDR, I2C_I2C_READ_XFER_MODE);
        *value = I2C_I2CMasterReadByte(I2C_I2C_NAK_DATA);
    }
    ackStatus2 = I2C_I2CMasterSendStop();
    UART_UartPutChar(ackStatus1);
    UART_UartPutChar(ackStatus2);
    return(ackStatus1);
}

   

After all I2C transactions I'm taking the values on UART but the result is still same.

   

 

   

I've attached the archived project if required

   

Regards,

   

Viraj

0 Likes
Anonymous
Not applicable

Never mind I solved it. The Alternate addresses & the normal addresses of the ADXL345 and got mixed with the alternate and normal Read and Write addresses. I checked it after you pointed it out and exchanged 0x1D with 0x53.

   

Now I've sorted it out and getting the reading in 16 unsigned bits

   

Thanks for the help Bob,

   

Regards,

   

Viraj

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You are always welcome, Viraj!

   

Nice dog! We've got a maremna mix

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thanks, It's a friend's dog.

   

 

   

Viraj

0 Likes