I succesfully connected the MMA-7455L sensor and I am getting data from it. Although I have one question if someone can help me.
Can someone help me understand this piece of code? That I am using to get the data from.
i2cbuf[1] = 0x00;
HAL_I2C_Master_Receive(&hi2c1, 0x1D<<1, &i2cbuf[1], 6, 10);
ax = -(i2cbuf[1]<<8 | i2cbuf[2]);
ay = -(i2cbuf[3]<<8 | i2cbuf[4]);
az = -(i2cbuf[5]<<8 | i2cbuf[6]);
I am getting data and the outpit is in 8 bit. I understand that I am combining two 8 bit responses to make it a 16 bit response. But what I do not understand is the minus part.
Thank you in advance
&i2cbuf[1]
in C is implementation defined (check your compiler doc) – Adriano Repettifloat
but unless you need some further processing then you're just wasting memory and CPU cycles because it's a signed 16 integerint16_t
(and not even "full"). Unless you're abstracting these things (in case in future you'll use a different sensor) it's probably useless. – Adriano Repetti