cancel
Showing results for 
Search instead for 
Did you mean: 

ASM330LHH works abnormally when using FIFO threshold interrupt

Talos
Associate

I use the continuous mode of FIFO and set the WATERMASK of FIFO to 2. Then, I route the FIFO threshold interrupt to INT1. In theory, for each set of XL+GY data generated, an interrupt should be generated. Then, I can read a set of XL+GY data in the interrupt handling function. In practical operation, it was found that when a second interrupt was generated and data was read, no new interrupt was generated.

The following is the waveform of the INT1 pin that I captured:

af1ae0caecf3012997bf1f0f3e23947.jpg

 

 

 

Part of the code is as follows:

asm330lhh_fifo_sensor_tag_get(&dev_ctx, &reg_tag);

{

  if(GPIO_Pin == IMU_INT1_Pin)

  {

    asm330lhh_fifo_read();

  }

}

 

void asm330lhh_fifo_init(ASM330LHH_FREQ freq)

{

  /* Uncomment to configure INT 1 */

  asm330lhh_pin_int1_route_t int1_route;

  dev_ctx.write_reg = (stmdev_write_ptr)platform_write;

  dev_ctx.read_reg = platform_read;

  dev_ctx.handle = &SENSOR_BUS;

   

  /* Check device ID */

  asm330lhh_device_id_get(&dev_ctx, &whoamI);

 

  if (whoamI != ASM330LHH_ID)

    while (1);

 

  /* Restore default configuration */

  asm330lhh_reset_set(&dev_ctx, PROPERTY_ENABLE);

 

  do

  {

    asm330lhh_reset_get(&dev_ctx, &rst);

  }

  while (rst);

 

  /* Start device configuration. */

  asm330lhh_device_conf_set(&dev_ctx, PROPERTY_ENABLE);

  /* Enable Block Data Update */

  asm330lhh_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);

  /* Set full scale */

  asm330lhh_xl_full_scale_set(&dev_ctx, ASM330LHH_8g);

  asm330lhh_gy_full_scale_set(&dev_ctx, ASM330LHH_500dps);

     

  /* Set FIFO mode to Stream mode (aka Continuous Mode) */

  asm330lhh_fifo_mode_set(&dev_ctx, ASM330LHH_STREAM_MODE);

  /* Uncomment if interrupt generation on FIFO INT1 pin */

  int1_route.int1_ctrl.int1_fifo_th = PROPERTY_ENABLE;

  asm330lhh_pin_int1_route_set(&dev_ctx, &int1_route);

  /* Set FIFO watermark (number of unread sensor data TAG + 6 bytes

   * stored in FIFO) to 2 samples

   */

  asm330lhh_fifo_watermark_set(&dev_ctx, 2);

  /* Set FIFO batch XL/Gyro ODR to freq */

  /* Set Output Data Rate */

  asm330lhh_fifo_xl_batch_set(&dev_ctx, ASM330LHH_XL_BATCHED_AT_26Hz);

  asm330lhh_fifo_gy_batch_set(&dev_ctx, ASM330LHH_GY_BATCHED_AT_26Hz);

  asm330lhh_xl_data_rate_set(&dev_ctx, ASM330LHH_XL_ODR_26Hz);

  asm330lhh_gy_data_rate_set(&dev_ctx, ASM330LHH_GY_ODR_26Hz);

}

 

void asm330lhh_fifo_read(void)

{

  asm330lhh_fifo_tag_t reg_tag;

  uint8_t wmflag = 0;

  uint16_t num = 0;

  /* Read watermark flag */

  asm330lhh_fifo_wtm_flag_get(&dev_ctx, &wmflag);

 

  if (wmflag > 0)

  {

    /* Read number of samples in FIFO */

    asm330lhh_fifo_data_level_get(&dev_ctx, &num);

 

    while (num--)

    {

      /* Read FIFO tag */

      asm330lhh_fifo_sensor_tag_get(&dev_ctx, &reg_tag);

 

破;

      {

      case ASM330LHH_XL_NC_TAG:

      {

        static unsigned long last_tick = 0;

        memset(data_raw_acceleration.u8bit, 0x00, 3 * sizeof(int16_t));

        asm330lhh_fifo_out_raw_get(&dev_ctx, data_raw_acceleration.u8bit);

        acceleration_mg[0] =

          asm330lhh_from_fs8g_to_mg(data_raw_acceleration.i16bit[0]);

        acceleration_mg[1] =

          asm330lhh_from_fs8g_to_mg(data_raw_acceleration.i16bit[1]);

        acceleration_mg[2] =

          asm330lhh_from_fs8g_to_mg(data_raw_acceleration.i16bit[2]);

        /* read temperature */

        memset(&data_raw_temperature, 0x00, sizeof(int16_t));

        asm330lhh_temperature_raw_get(&dev_ctx, &data_raw_temperature);

        temperature_degC = asm330lhh_from_lsb_to_celsius(data_raw_temperature);

#if LOG_OUT

        tx_com(tx_buffer, strlen((char const *)tx_buffer));

#endif

      }

      break;

 

      case ASM330LHH_GYRO_NC_TAG:

      {

        memset(data_raw_angular_rate.u8bit, 0x00, 3 * sizeof(int16_t));

        asm330lhh_fifo_out_raw_get(&dev_ctx, data_raw_angular_rate.u8bit);

        angular_rate_mdps[0] =

          asm330lhh_from_fs500dps_to_mdps(data_raw_angular_rate.i16bit[0]);

        angular_rate_mdps[1] =

          asm330lhh_from_fs500dps_to_mdps(data_raw_angular_rate.i16bit[1]);

        angular_rate_mdps[2] =

          asm330lhh_from_fs500dps_to_mdps(data_raw_angular_rate.i16bit[2]);

 

#if LOG_OUT

        tx_com(tx_buffer, strlen((char const *)tx_buffer));

#endif

      }

      break;

 

      default:

      {

        /* Flush unused samples */

        memset(dummy.u8bit, 0x00, 3 * sizeof(int16_t));

        asm330lhh_fifo_out_raw_get(&dev_ctx, dummy.u8bit);

      }

      break;

      }

    }

  }

}

1 REPLY 1
Federica Bossi
ST Employee

Hi @Talos ,

Welcome to ST Community!

Can you try to follow our PID example on github and and let me know if you still encounter the issue?

 

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.