AltIMU 10 V4

Hello,

I am trying to implement this sensor and while I was reading the data sheet for the I2C operation of the LPS25H sensor on board, it mentions

" If the SA0 pad is connected to voltage supply, LSb is ‘1’ (address 1011101b), otherwise if the SA0 pad is connected to ground, the LSb value is ‘0’ (address 1011100b)."

Currently, the SA0 pad on the AltIMU 10 V4 isn’t connected (I don’t think I need it), so what should the LSb of the LPS25H be defaulted to…I’m thinking 1, but can anyone confirm?

Thanks

Hello.

Yes, the LSB of the I2C slave address on the AltIMU-10’s LPS25H is 1 by default. (We mention that under the “I2C Communication” section of the AltIMU-10’s product page.)

-Jon

Thanks,

I am trying to attain temperature data from the LPS25H but I have been getting confusing numbers (numbers ranging from -xxxx to +xxxx when it should be numbers representative of Celsius degrees. I currently have the AltIMU hooked up to the PB2 (SCL) and PB4 (SDA) pins of the Orangutan X2 and wrote a software implementation of the I2C protocol using bit banging (because the hardware pins for I2C is being used by the LCD I have attached to the Orangutan X2). I have tested out my I2C functions and they work (tested via reading the device ID of the LPS25H).

I think it may be a data type issue? Is there a problem with the code or do I need to address some other registers in the chip besides just CTRL_REG1 and the temperature registers?

main.c

[code]int main(void)
{
signed int raw_temp;
float temp;
unsigned char device_id;
I2C_init(); //initializes I2C communication
lcd_init_printf(); //initializes LCD
I2C_write_regis(LPS25H, CTRL_REG1, 0xB0); //power up, enable continuous output
I2C_write_regis(LPS25H, RES_CONF, 0x0F); //set to maximum resolution

while(1)
{
raw_temp = I2C_read_temp(LPS25H, TEMP_OUT_L, TEMP_OUT_H);
temp = (raw_temp/480.0) + 42.5; //temperature in C
printf("Temperature = %d", temp);
delay(300);
}

}[/code]

signed int I2C_read_temp(unsigned char addr, unsigned char regis, unsigned char regis2) //signed because temperature data are given in 2's complement { signed int temp; signed char l, h; I2C_start(); //initiate start I2C_write(addr); //write to slave device I2C_write(regis); //set register I2C_start(); //repeat start I2C_write(addr + read_op); //write to slave as read operation l = I2C_read(0); //read the register data (NACK) I2C_stop(); // stop I2C_start(); //initiate repeat start I2C_write(addr); //write to slave device I2C_write(regis2); //set register I2C_start(); //repeat start I2C_write(addr + read_op); //write to slave as read operation h = I2C_read(0); //read the register data (NACK) I2C_stop(); // stop temp = (h<<8)|l; return temp; }

This probably won't work, because h is 8 bits long.  Try defining h and l as unsigned integers, or cast the operation appropriately.

This probably won’t work, because h is 8 bits long. Try defining h and l as unsigned integers, or cast the operation appropriately.

Ah yes, that would be a problem. However, because the data sheet says that the temperature data is given in 2’s complement, shouldn’t it be int rather than unsigned int?

I ended up keeping the defined data types, but rewrote the line of code for joining the two bytes as follows:

temp |= l; temp |= ((int)h)<<8;

I don’t think there should be a problem here, but the output results are still from -xxxxx to xxxxx.

What I am confused about is that the number range I should be expecting is from -xx to xx, since the the max value of a signed int is 2^15, that divided by 480.0 + 42.5 would result in numbers ranging from -xxx to xxx.

Update:
It works now, the problem was in the data type of temperature in the main function call. I declared it as a float initially, but after changing it to long it behaved correctly…any thoughts on this?