2020-01-23 08:34 AM
Hi, I need advise regarding my application. I can store historic data using Stream-to-FIFO mode based on single tap interrupt in buffer A. But, I cannot get data after the tap interrupt in buffer B when switching FIFO mode to Streaming mode. I believe I am not configuring the sensor properly to switch from one mode to another. My code is listed below. It collects and store historical data in buffer A and calculates threshold. If threshold is higher, then micro-controller is instructed to switch to the streaming mode and to store data in buffer B. This code returns watermark value 0 for the second part of the code (for buffer B part). It should be 1 for FIFO to output data.
S32 get_lsm6ds3_fifo_acceleration_angular_rate_data_s16(S16 *acceleration_mg, S16 *angular_rate_mdps)
{
uint16_t numA = 0;
uint16_t numB = 0;
uint16_t num_patternA = 0;
uint16_t num_patternB = 0;
uint8_t watermA = 0;
uint8_t watermB = 0;
S32 error;
volatile uint16_t acc_magn = 0;
error = lsm6ds3tr_c_fifo_wtm_flag_get(&lsm6ds3, &watermA);
kal_prompt_trace(MOD_ABM,"001 error:%d, waterm:%d", error,watermA);
if(error!=STATUS_OK) return STATUS_FAIL;
if(watermA)
{
error = lsm6ds3tr_c_fifo_data_level_get(&lsm6ds3, &numA);
kal_prompt_trace(MOD_ABM,"002 error:%d, num:%d", error,numA);
if(error!=STATUS_OK) return error;
num_patternA = numA/pattern_len;
kal_prompt_trace(MOD_ABM,"003 num_pattern:%d, pattern_len:%d", num_patternA,pattern_len);
while (num_patternA-- > 0){
lsm6ds3tr_c_fifo_raw_data_get(&lsm6ds3, data_raw_angular_rate.u8bit, 3*sizeof(int16_t));
*angular_rate_mdps = lsm6ds3tr_c_from_fs250dps_to_mdps(data_raw_angular_rate.i16bit[0]);
*(angular_rate_mdps+1) = lsm6ds3tr_c_from_fs250dps_to_mdps(data_raw_angular_rate.i16bit[1]);
*(angular_rate_mdps+2) = lsm6ds3tr_c_from_fs250dps_to_mdps(data_raw_angular_rate.i16bit[2]);
lsm6ds3tr_c_fifo_raw_data_get(&lsm6ds3, data_raw_acceleration.u8bit, 3*sizeof(int16_t));
*acceleration_mg = lsm6ds3tr_c_from_fs2g_to_mg(data_raw_acceleration.i16bit[0]);
*(acceleration_mg+1) = lsm6ds3tr_c_from_fs2g_to_mg(data_raw_acceleration.i16bit[1]);
*(acceleration_mg+2) = lsm6ds3tr_c_from_fs2g_to_mg(data_raw_acceleration.i16bit[2]);
acc_x_buffer_a[num_patternA]= acceleration_mg[0];
acc_y_buffer_a[num_patternA]= acceleration_mg[1];
acc_z_buffer_a[num_patternA]= acceleration_mg[2];
gyro_x_buffer_a[num_patternA] = angular_rate_mdps[0];
gyro_y_buffer_a[num_patternA] = angular_rate_mdps[1];
gyro_z_buffer_a[num_patternA] = angular_rate_mdps[2];
acc_magn = sqrt(pow(acc_x_buffer_a[num_patternA], 2)+ pow(acc_y_buffer_a[num_patternA], 2) + pow(acc_z_buffer_a[num_patternA], 2));
kal_prompt_trace(MOD_ABM,"BufA_No: %d, ACC: %d, %d, %d, GYR: %d, %d, %d, MAG: %d", num_patternA, acc_x_buffer_a[num_patternA], acc_y_buffer_a[num_patternA], acc_z_buffer_a[num_patternA], gyro_x_buffer_a[num_patternA], gyro_y_buffer_a[num_patternA], gyro_z_buffer_a[num_patternA], acc_magn);
}
lsm6ds3tr_c_fifo_mode_set(&lsm6ds3, LSM6DS3TR_C_BYPASS_MODE);
lsm6ds3tr_c_fifo_mode_set(&lsm6ds3, LSM6DS3TR_C_STREAM_TO_FIFO_MODE);
if( acc_magn > 0)
{
lsm6ds3tr_c_fifo_mode_set(&lsm6ds3, LSM6DS3TR_C_BYPASS_MODE);
lsm6ds3tr_c_fifo_mode_set(&lsm6ds3, LSM6DS3TR_C_STREAM_MODE);
lsm6ds3tr_c_pin_int1_route_get(&lsm6ds3, &int_1_reg);
int_1_reg.int1_fth = PROPERTY_ENABLE;
lsm6ds3tr_c_pin_int1_route_set(&lsm6ds3, int_1_reg);
error = lsm6ds3tr_c_fifo_wtm_flag_get(&lsm6ds3, &watermB);
kal_prompt_trace(MOD_ABM,"100 error:%d, watermB:%d", error,watermB);
if(error!=STATUS_OK) return STATUS_FAIL;
if(watermB)
{
error = lsm6ds3tr_c_fifo_data_level_get(&lsm6ds3, &numB);
kal_prompt_trace(MOD_ABM,"200 error:%d, num:%d", error,numB);
if(error!=STATUS_OK) return error;
num_patternB = numB/pattern_len;
kal_prompt_trace(MOD_ABM,"300 num_pattern:%d, pattern_len:%d", num_patternB,pattern_len);
while (num_patternB-- > 0)
{
lsm6ds3tr_c_fifo_raw_data_get(&lsm6ds3, data_raw_angular_rate.u8bit, 3*sizeof(int16_t));
*angular_rate_mdps = lsm6ds3tr_c_from_fs250dps_to_mdps(data_raw_angular_rate.i16bit[0]);
*(angular_rate_mdps+1) = lsm6ds3tr_c_from_fs250dps_to_mdps(data_raw_angular_rate.i16bit[1]);
*(angular_rate_mdps+2) = lsm6ds3tr_c_from_fs250dps_to_mdps(data_raw_angular_rate.i16bit[2]);
lsm6ds3tr_c_fifo_raw_data_get(&lsm6ds3, data_raw_acceleration.u8bit, 3*sizeof(int16_t));
*acceleration_mg = lsm6ds3tr_c_from_fs2g_to_mg(data_raw_acceleration.i16bit[0]);
*(acceleration_mg+1) = lsm6ds3tr_c_from_fs2g_to_mg(data_raw_acceleration.i16bit[1]);
*(acceleration_mg+2) = lsm6ds3tr_c_from_fs2g_to_mg(data_raw_acceleration.i16bit[2]);
acc_x_buffer_b[num_patternB]= acceleration_mg[0];
acc_y_buffer_b[num_patternB]= acceleration_mg[1];
acc_z_buffer_b[num_patternB]= acceleration_mg[2];
gyro_x_buffer_b[num_patternB] = angular_rate_mdps[0];
gyro_y_buffer_b[num_patternB] = angular_rate_mdps[1];
gyro_z_buffer_b[num_patternB] = angular_rate_mdps[2];
kal_prompt_trace(MOD_ABM,"BufB_No: %d, ACC: %d, %d, %d, GYRO: %d, %d, %d", num_patternB, acc_x_buffer_b[num_patternB], acc_y_buffer_b[num_patternB], acc_z_buffer_b[num_patternB], gyro_x_buffer_b[num_patternB], gyro_y_buffer_b[num_patternB], gyro_z_buffer_b[num_patternB]);
}
}
}
return STATUS_OK;
}
return STATUS_FAIL;
}
Solved! Go to Solution.
2020-04-01 05:44 AM
Hi @ASoni.2 , back to this topic after long time... Your question is that, when you switch from"Stream-to-FIFO" to "Stream" mode, you cannot get no more data after the tap interrupt, right? Let's consider the device working conditions listed here below (AN5130 p.78):
I believe you should esc the "Continuous to FIFO" mode, enter the Bypass mode (000b) and then switching to the Bypass-to-continuous mode (100b), which should be triggered by the interrupt and starting with the filling of buffer B.
Regards
2020-04-01 05:44 AM
Hi @ASoni.2 , back to this topic after long time... Your question is that, when you switch from"Stream-to-FIFO" to "Stream" mode, you cannot get no more data after the tap interrupt, right? Let's consider the device working conditions listed here below (AN5130 p.78):
I believe you should esc the "Continuous to FIFO" mode, enter the Bypass mode (000b) and then switching to the Bypass-to-continuous mode (100b), which should be triggered by the interrupt and starting with the filling of buffer B.
Regards
2020-04-29 04:39 AM
Hi @Eleon BORLINI Yes, I am fine with this query now. I have configured the sensor as stated in your answer.