Thanks for your reply BSTRobin, I would like to be more precise in my question. I would like to confirm that after leaving function "p_bma2x2->BMA2x2_BUS_READ_FUNC" which I've marked with "(A) read from a bus" the "data_u8" has to be filled with all 6 bytes of accelerometer data in order to whole operation of reading accelerometer data from X,Y,Z be successful. That is what I meant when I was asking if the whole API is designed to be used in a synchronous way. Am I correct or am I missing something obvious? BMA2x2_RETURN_FUNCTION_TYPE bma2x2_read_accel_xyz(
struct bma2x2_accel_data *accel) {
/* Variable used to return value of
communication routine*/
BMA2x2_RETURN_FUNCTION_TYPE com_rslt = ERROR;
/* Array holding the accel xyz value
data_u8[0] - x->LSB
data_u8[1] - x->MSB
data_u8[2] - y->MSB
data_u8[3] - y->MSB
data_u8[4] - z->MSB
data_u8[5] - z->MSB
*/
u8 data_u8[BMA2x2_ACCEL_XYZ_DATA_SIZE] = {
BMA2x2_INIT_VALUE, BMA2x2_INIT_VALUE,
BMA2x2_INIT_VALUE, BMA2x2_INIT_VALUE,
BMA2x2_INIT_VALUE, BMA2x2_INIT_VALUE };
if (p_bma2x2 == BMA2x2_NULL) {
/* Check the struct p_bma2x2 is empty */
return E_BMA2x2_NULL_PTR;
} else {
switch (V_BMA2x2RESOLUTION_U8) {
(...)
/* This case used for the resolution bit 14*/
case BMA2x2_14_RESOLUTION:
com_rslt = p_bma2x2->BMA2x2_BUS_READ_FUNC( // <--------------------------------------------- (A) read from a bus
p_bma2x2->dev_addr,
BMA2x2_ACCEL_X12_LSB_REG,
data_u8,
BMA2x2_SHIFT_SIX_BITS
);
/* read the x data_u8*/
accel->x =
(s16) ((((s32) ((s8) data_u8[BMA2x2_SENSOR_DATA_XYZ_X_MSB]))
<<
BMA2x2_SHIFT_EIGHT_BITS)
| (data_u8[BMA2x2_SENSOR_DATA_XYZ_X_LSB]
& BMA2x2_14_BIT_SHIFT));
accel->x = accel->x >> BMA2x2_SHIFT_TWO_BITS;
/* read the y data_u8*/
accel->y =
(s16) ((((s32) ((s8) data_u8[BMA2x2_SENSOR_DATA_XYZ_Y_MSB]))
<<
BMA2x2_SHIFT_EIGHT_BITS)
| (data_u8[BMA2x2_SENSOR_DATA_XYZ_Y_LSB]
& BMA2x2_14_BIT_SHIFT));
accel->y = accel->y >> BMA2x2_SHIFT_TWO_BITS;
/* read the z data_u8*/
accel->z =
(s16) ((((s32) ((s8) data_u8[BMA2x2_SENSOR_DATA_XYZ_Z_MSB]))
<<
BMA2x2_SHIFT_EIGHT_BITS)
| (data_u8[BMA2x2_SENSOR_DATA_XYZ_Z_LSB]
& BMA2x2_14_BIT_SHIFT));
accel->z = accel->z >> BMA2x2_SHIFT_TWO_BITS;
break;
default:
break;
}
}
return com_rslt;
}
... View more