cancel
Showing results for 
Search instead for 
Did you mean: 

iis3dwb Sampling Rate Driver Issue

Leo_leo
Associate

While using the iis3dw sensor, I discovered that when I employed an interrupt-based polling method to read data—where, ideally, the sensor captures data, triggers an interrupt, and then the data is read—the data acquisition frequency should be around 26 kHz (based on SPI transmission and code execution time). However, I found that reading the data was taking up some of that time; when I disabled this process, the issue disappeared. My SPI rate is 18 Mbps. Subsequent testing with FIFO reading also exhibited this behavior. Specifically, when I disabled the function `iis3dwb_acceleration_raw_get(&IIS3DWB_ctx, accel)` during the read process, reading 10,240 data points took approximately 391 ms (about 26k). Without disabling it, reading the same 10,240 data points took 523 ms (about 19k). Below is my read code without using FIFO. The attachment contains the official ST driver. `uint8_t iis3dwb_init_drdy_mode(void)` is the initialization function without using FIFO,

int16_t iis3dwb_read(void)
{
	int16_t accel[3];
	iis3dwb_acceleration_raw_get(&IIS3DWB_ctx, accel);
//	if(IisINITNum % 10 == 0)
	{
		AllData[IisDataNum].Iis[0] = accel[0];//iis3dwb_from_fs16g_to_mg(accel[0]) * 9.8 / 1000;
		AllData[IisDataNum].Iis[1] = accel[1];//iis3dwb_from_fs16g_to_mg(accel[1]) * 9.8 / 1000;
		AllData[IisDataNum].Iis[2] = accel[2];//iis3dwb_from_fs16g_to_mg(accel[2]) * 9.8 / 1000;
		IisDataNum++;
		if(IisDataNum >= DATA_MAX_NUM)
		{
        	IisDataNum = 0;
        	iis3dwb_xl_data_rate_set(&IIS3DWB_ctx, IIS3DWB_XL_ODR_OFF);
            g_events |= MAIN_EVENT_SEND_IIS;
            return 0;
		}
	}
	IisINITNum++;
	return 0;
}

The ST Community moderator has translated the post to comply with the language of the Community which is English.  For more information, see: ST Community Terms and Conditions - STMicroelectronics Community
Translated with DeepL.com (free version)

1 ACCEPTED SOLUTION

Accepted Solutions
Federica Bossi
ST Employee

Hi @Leo_leo ,

Your observation is correct: the overhead introduced by the iis3dwb_acceleration_raw_get() function—including SPI transactions, data conversion, and context handling—reduces the maximum achievable data rate, even with an 18 Mbps SPI clock. This is why you see a lower acquisition frequency when this function is used.

To maximize throughput:

  • Minimize function call overhead by reading sensor registers directly in a tight loop or using burst SPI reads.
  • Prefer FIFO mode and read multiple samples in a single SPI transaction.
  • Consider using DMA for SPI transfers if your MCU supports it.

The official ST driver prioritizes portability over raw speed. For high-speed applications, a streamlined, application-specific readout routine is recommended.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

View solution in original post

2 REPLIES 2
Leo_leo
Associate
 
Federica Bossi
ST Employee

Hi @Leo_leo ,

Your observation is correct: the overhead introduced by the iis3dwb_acceleration_raw_get() function—including SPI transactions, data conversion, and context handling—reduces the maximum achievable data rate, even with an 18 Mbps SPI clock. This is why you see a lower acquisition frequency when this function is used.

To maximize throughput:

  • Minimize function call overhead by reading sensor registers directly in a tight loop or using burst SPI reads.
  • Prefer FIFO mode and read multiple samples in a single SPI transaction.
  • Consider using DMA for SPI transfers if your MCU supports it.

The official ST driver prioritizes portability over raw speed. For high-speed applications, a streamlined, application-specific readout routine is recommended.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.