cancel
Showing results for 
Search instead for 
Did you mean: 

FIFO usage and sample storage based on interrupt.

ASoni.2
Associate III

Hi, I am using LSM6DS3TR-C sensor. In my application, I require two buffers to store MEMS samples. One buffer contains data before the event and second buffer after the event.

Currently, I am using continuous-to-FIFO mode for my application and two interrupts, FIFO_threshold and single_tap. When I enable both interrupts, I get data continuously from the sensor and this is useful for first buffer but on tap_interrupt, I do not have any data for second buffer. Moreover, when using only tap_interrupt, I get data after tap interrupt for second buffer but cannot get data for the first buffer.

Using continuous-to-FIFO mode, I would like to update my first buffer continuously and during interrupt, I would like to switch to FIFO mode to store data after the interrupt event.

I have attache the code below;

error = lsm6ds3tr_c_fifo_wtm_flag_get(&lsm6ds3, &waterm);
kal_prompt_trace(MOD_ABM,"001 error:%d, waterm:%d", error,waterm);
if(error!=STATUS_OK) return STATUS_FAIL;
if(waterm){
	error = lsm6ds3tr_c_fifo_data_level_get(&lsm6ds3, &num);
	kal_prompt_trace(MOD_ABM,"002 error:%d, num:%d", error,num); 
	if(error!=STATUS_OK) return error;
	num_pattern = num/pattern_len;
	kal_prompt_trace(MOD_ABM,"003 num_pattern:%d, pattern_len:%d", num_pattern,pattern_len); 
	while (num_pattern-- > 0){
		if(all_source.tap_src.single_tap){
			lsm6ds3tr_c_fifo_raw_data_get(&lsm6ds3, data_raw_angular_rate.u8bit, 3*sizeof(int16_t));
			kal_prompt_trace(MOD_ABM,"004 num_pattern:%d, data_raw_angular_rate.i16bit:%x %x %x", num_pattern, angular_rate_mdps[0],angular_rate_mdps[1],angular_rate_mdps[2]);
 
                       *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));
                       kal_prompt_trace(MOD_ABM,"004 num_pattern:%d, data_raw_acceleration.i16bit:%x %x %x", num_pattern, acceleration_mg[0], acceleration_mg[1], acceleration_mg[2]);
 
                       *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_pattern]= acceleration_mg[0];
                       acc_y_buffer_b[num_pattern]= acceleration_mg[1];
                       acc_z_buffer_b[num_pattern]= acceleration_mg[2];
                       gyro_x_buffer_b[num_pattern]= angular_rate_mdps[0];
                       gyro_y_buffer_b[num_pattern]= angular_rate_mdps[1];
                       gyro_z_buffer_b[num_pattern]= angular_rate_mdps[2];
 
		        kal_prompt_trace(MOD_ABM,"BufB_No: %d, ACC: %d %d %d, GYR: %d %d %d", num_pattern, acc_x_buffer_b[num_pattern], acc_y_buffer_b[num_pattern], acc_z_buffer_b[num_pattern], gyro_x_buffer_b[num_pattern], gyro_y_buffer_b[num_pattern], gyro_z_buffer_a[num_pattern]);
				}
			else{
				lsm6ds3tr_c_fifo_raw_data_get(&lsm6ds3, data_raw_angular_rate.u8bit, 3*sizeof(int16_t));
				kal_prompt_trace(MOD_ABM,"004 num_pattern:%d, data_raw_angular_rate.i16bit:%x %x %x", num_pattern, angular_rate_mdps[0], angular_rate_mdps[1], angular_rate_mdps[2]);
				*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));
				kal_prompt_trace(MOD_ABM,"004 num_pattern:%d, data_raw_acceleration.i16bit:%x %x %x", num_pattern, acceleration_mg[0], acceleration_mg[1], acceleration_mg[2]);
				*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_pattern]= acceleration_mg[0];
				acc_y_buffer_a[num_pattern]= acceleration_mg[1];
				acc_z_buffer_a[num_pattern]= acceleration_mg[2];
				gyro_x_buffer_a[num_pattern]= angular_rate_mdps[0];
				gyro_y_buffer_a[num_pattern]= angular_rate_mdps[1];
				gyro_z_buffer_a[num_pattern]= angular_rate_mdps[2];
 
				kal_prompt_trace(MOD_ABM,"BufA_No: %d, ACC: %d %d %d, GYR: %d %d %d", num_pattern, acc_x_buffer_a[num_pattern], acc_y_buffer_a[num_pattern], acc_z_buffer_a[num_pattern], gyro_x_buffer_a[num_pattern], gyro_y_buffer_a[num_pattern], gyro_z_buffer_a[num_pattern]);			
			}
		}
 
		kal_prompt_trace(MOD_ABM,"angular_rate_mdps:%x %x %x, acceleration_mg:%x %x %x", angular_rate_mdps[0], angular_rate_mdps[1], angular_rate_mdps[2], acceleration_mg[0], acceleration_mg[1], acceleration_mg[2]);
		
		lsm6ds3tr_c_fifo_mode_set(&lsm6ds3, LSM6DS3TR_C_BYPASS_MODE);
		lsm6ds3tr_c_fifo_mode_set(&lsm6ds3, LSM6DS3TR_C_STREAM_TO_FIFO_MODE);

Could you please advice me on this application?

Kind regards,

Aakash Soni.

1 REPLY 1
ASoni.2
Associate III