cancel
Showing results for 
Search instead for 
Did you mean: 

IIS3DWB accelerometer. Unable to read the data in FIFO mode.

ASM
Associate II

Screenshot (311).png

 

 

int main( void )
{
  /* STM32 HAL library initialization*/
  HAL_Init( );
  
  /* Configure the system clock*/
  SystemClock_Config( );
  
  /* Configure the debug mode*/
  DBG_Init( );
  PRINTF("\n----------------------Firmare starts here---------------------\n");
	
  /* Configure the hardware*/
  HW_Init( );
	MX_GPIO_Init();
	MX_I2C1_Init();
 //MX_RTC_Init();
	GNSS_Init();
  /* SPI initialization function*/
	SPI_Init();
	
  /* Initialize mems driver interface */
  dev_ctx.write_reg = IIS3DWB_write;
  dev_ctx.read_reg = IIS3DWB_read;
  dev_ctx.mdelay = IIS3DWB_delay;
  dev_ctx.handle = &hspi2;   
	IIS3DWB_delay(BOOT_TIME);
  iis3dwb_device_id_get(&dev_ctx, &whoamI); // check the ID of the accelerometer. Default ID: 0X7B
	PRINTF("\nAccelerometer_ID: %X\n\r", whoamI);  
		 
  if (whoamI != IIS3DWB_ID)
    while (1);

  /* Restore default configuration */
  iis3dwb_reset_set(&dev_ctx, PROPERTY_ENABLE);

  do {
    iis3dwb_reset_get(&dev_ctx, &rst);
		HAL_Delay(BOOT_TIME);
  } while (rst);

	/* Set Output Data Rate */
  iis3dwb_xl_data_rate_set(&dev_ctx, IIS3DWB_XL_ODR_26k7Hz);
	/* Set full scale */
  iis3dwb_xl_full_scale_set(&dev_ctx, IIS3DWB_8g);
	/* Set FIFO mode to Stream mode (aka Continuous Mode) */
  iis3dwb_fifo_mode_set(&dev_ctx, IIS3DWB_STREAM_MODE);
	/*
   * Set FIFO watermark (number of unread sensor data TAG + 6 bytes
   * stored in FIFO) to FIFO_WATERMARK samples
   */
  iis3dwb_fifo_watermark_set(&dev_ctx, FIFO_WATERMARK);
	iis3dwb_fifo_stop_on_wtm_set(&dev_ctx, 1);
	/* Set FIFO batch XL ODR to 12.5Hz */
  iis3dwb_fifo_xl_batch_set(&dev_ctx, IIS3DWB_XL_BATCHED_AT_26k7Hz);
  /* Enable Block Data Update */
  iis3dwb_block_data_update_set(&dev_ctx, 1);
 
  iis3dwb_fifo_timestamp_batch_set(&dev_ctx, IIS3DWB_DEC_8);
  iis3dwb_timestamp_set(&dev_ctx, PROPERTY_ENABLE);

  /* Wait samples */
  while (1) {
    uint16_t num = 0, k;
    /* Read watermark flag */
    iis3dwb_fifo_status_get(&dev_ctx, &fifo_status);

    if (fifo_status.fifo_th == 1) {
      num = fifo_status.fifo_level;
      sprintf((char *)tx_buffer, "-- FIFO num %d \r\n", num);
      PRINTF("-- FIFO num %d \r\n", num);

      /* read out all FIFO entries in a single read */
      iis3dwb_fifo_out_multi_raw_get(&dev_ctx, fifo_data, num);

      for (k = 0; k < num; k++) {
        iis3dwb_fifo_out_raw_t *f_data;

        /* print out first two and last two FIFO entries only */
        if (k > 1 && k < num - 2)
          continue;

        f_data = &fifo_data[k];

        /* Read FIFO sensor value */
        datax = (int16_t *)&f_data->data[0];
        datay = (int16_t *)&f_data->data[2];
        dataz = (int16_t *)&f_data->data[4];
        ts = (int32_t *)&f_data->data[0];

        switch (f_data->tag >> 3) {
        case IIS3DWB_XL_TAG:
          sprintf((char *)tx_buffer, "%d: ACC [mg]:\t%4.2f\t%4.2f\t%4.2f\r\n",
                  k,
                  iis3dwb_from_fs8g_to_mg(*datax),
                  iis3dwb_from_fs8g_to_mg(*datay),
                  iis3dwb_from_fs8g_to_mg(*dataz));
          //tx_com(tx_buffer, strlen((char const *)tx_buffer));
					PRINTF("%d: ACC [mg]:\t%4.2f\t%4.2f\t%4.2f\r\n",
                  k,
                  iis3dwb_from_fs8g_to_mg(*datax),
                  iis3dwb_from_fs8g_to_mg(*datay),
                  iis3dwb_from_fs8g_to_mg(*dataz));
          break;
        case IIS3DWB_TIMESTAMP_TAG:
          sprintf((char *)tx_buffer, "%d TIMESTAMP [ms] %d\r\n", k, *ts);
          //tx_com(tx_buffer, strlen((char const *)tx_buffer));
				PRINTF("%d TIMESTAMP [ms] %d\r\n", k, *ts);
          break;
        default:
          break;
        }
      }
      
      sprintf((char *)tx_buffer, "------ \r\n\r\n");
      //tx_com(tx_buffer, strlen((char const *)tx_buffer));
			PRINTF("------ \r\n\r\n");
    }
  }
}

 

 

This is the code I'am working on. I'am using the example which is provided by the ST but unable to read the accelerometer data in FIFO mode. I tried the read polling example and can successfully receiving the data. Attaching the screen shot of the serial monitor here

2 REPLIES 2
Federica Bossi
ST Employee

Hi @ASM ,

Are you using this example? Did you do any changes?

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.

Yes Iam using the same example. Didnt make any changes except the SPI initialization