LPS25H. Problems reading output data

Hi,
I´m trying to read this sensor´s output data in a TI environment but it´s giving me some problems. I tried to do exactly like arduino´s library LPS25H.cpp does.

        //CTRL_REG1
        txBuf[0] = 0x20;
        txBuf[1] = 0xB0  ; // 0b10110000    High performance and 12.5Hz output data rate config
        i2cTrans.writeCount = 2;
        i2cTrans.writeBuf = txBuf;
        i2cTrans.readCount = 0;
        i2cTrans.readBuf = NULL;
        i2cTrans.slaveAddress = 0x5D;

        do{

        error=I2C_transfer(handle, &i2cTrans);

        }while(!error);
        error=0;

.
.
.
.

////////Lecturas////////////////////


    txBuf[0]=0x28;
    i2cTrans.writeCount = 1;
    i2cTrans.writeBuf = txBuf;
    i2cTrans.readCount = 3;
    i2cTrans.readBuf = rxBuf;
    i2cTrans.slaveAddress = 0x5D;

    do
    {
        error = I2C_transfer(handle, &i2cTrans);
    }while(!error);
    error=0;

    barom=(rxBuf[2] << 16 | (uint16_t)rxBuf[1]<<8 | rxBuf[0]);
    barom=barom/4096;

 
    I2C_close(handle);

But the values of the rxBuff are all the same and the average values are so different every time I play the programme.

Hello.

I edited your post to format your code better; you can see the changes by clicking on the pencil icon in the upper right corner of the post.

Can you explain more about your setup and your results? Are you using our LPS25H carrier board? What microcontroller and what I2C library or code are you using? (Where are the i2cTrans object and the I2C_ functions defined?) What value do you see in rxBuf when the values are all the same, and what do you mean by average values?

You should make sure you are using the correct casts to combine the rxBuf bytes. Our library does this:

return (int32_t)(int8_t)ph << 16 | (uint16_t)pl << 8 | pxl;

so you might need to do this in your code:

barom=((int32_t)(int8_t)rxBuf[2] << 16 | (uint16_t)rxBuf[1]<<8 | rxBuf[0]);

Kevin

I´m using a TI-RTOS Launchpad 2650 and I´m editing it with code composer studio. The objective is to read the values from the Altimu v10(gyro,acelom,magnetom and barom). I´ve made all readings correctly except from the barometre´s ones.

The problem is that when I read the values on the rxBuf, those three values always are the same, for example rxBuf[0]=47 rxBuf[1]=47 rxBuf[2]=47.

I get this values debugging it step by step and if I run the programme again those values are identical but with another value.

I just noticed you aren’t setting the most significant bit of the register address. As the datasheet says:

In order to read multiple bytes incrementing the register address, it is necessary to assert
the most significant bit of the sub-address field. In other words, SUB(7) must be equal to 1
while SUB(6-0) represents the address of the first register to be read.

Could you try using 0xA8 instead of 0x28 for the value of txBuf[0] in your read code?

Kevin

Thanks, it finally worked. I didn´t realize of the SUB(7) value