cancel
Showing results for 
Search instead for 
Did you mean: 

I am working on STM32WB55 to read LSMDSOX sensor data. And I have set up an interrupt to occur when FIFO reaches watermark. It all works fine when if my code includes just reading data in a loop.

vtall.1
Associate

But when I add calling a fall algorithm task after reading each sample and try to simulate a fall (the rapid moment) causing program not causing interrupt.

Any help regarding why interrupt is not set would be of great help.

//code

int main(void)

{

 /* USER CODE BEGIN 1 */

uint8_t status;

uint16_t watermark;

uint8_t tag;

 /* USER CODE END 1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

 HAL_Init();

 /* Config code for STM32_WPAN (HSE Tuning must be done before system clock configuration) */

 MX_APPE_Config();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */

 SystemClock_Config();

/* Configure the peripherals common clocks */

 PeriphCommonClock_Config();

 /* IPCC initialisation */

  MX_IPCC_Init();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_DMA_Init();

 MX_RF_Init();

 MX_RTC_Init();

 /* USER CODE BEGIN 2 */

 /* USER CODE END 2 */

 /* Init code for STM32_WPAN */

 MX_APPE_Init();

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 /* Initializing the LSM6DSOX sensor */

 MY_MOTION_SENSOR_CUSTOM();

 /* Register my_task to sequencer */

 UTIL_SEQ_RegTask(1 << CFG_TASK_MY_TASK_ID, UTIL_SEQ_RFU, my_task);

 status = 1;

 watermark = 10;

 CUSTOM_MOTION_SENSOR_FIFO_Set_Watermark_Level(CUSTOM_LSM6DSOX_0, watermark);

 uint8_t regVal = 0;

 CUSTOM_MOTION_SENSOR_FIFO_Set_Mode(CUSTOM_LSM6DSOX_0, LSM6DSOX_BYPASS_MODE);

  CUSTOM_MOTION_SENSOR_Write_Register(CUSTOM_LSM6DSOX_0, LSM6DSOX_FIFO_CTRL3, 0x44);

  CUSTOM_MOTION_SENSOR_FIFO_Set_Mode(CUSTOM_LSM6DSOX_0, LSM6DSOX_STREAM_MODE);

  CUSTOM_MOTION_SENSOR_FIFO_Set_INT2_FIFO_Watermark(CUSTOM_LSM6DSOX_0, status);

  uint8_t buff[6];

  axis3bit16_t data_raw_acceleration;

  float acceleration_mg[3];

  while (1)

  {

  //Declaring local variables

    uint8_t wmflag = 0;

    uint16_t numberSamples = 0;

    axis3bit16_t dummy;

    CUSTOM_MOTION_SENSOR_FIFO_Get_WMFlag(CUSTOM_LSM6DSOX_0, &wmflag);

   if (Get_Read_Flag()) {

    Set_Read_Flag(0);

numberSamples = 0;

    /* Read Number Samples */

  CUSTOM_MOTION_SENSOR_FIFO_Get_Num_Samples(CUSTOM_LSM6DSOX_0, &numberSamples);

   snprintf(dataOut, MAX_BUF_SIZE, "BEG Num Samples %d\r\n", numberSamples);

    printf("%s", dataOut);

    while (numberSamples--)

    {

CUSTOM_MOTION_SENSOR_FIFO_Get_Tag(CUSTOM_LSM6DSOX_0, &tag);

switch (tag) {

     case LSM6DSOX_XL_NC_TAG:

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

     CUSTOM_MOTION_SENSOR_Read_raw_FIFO_data(CUSTOM_LSM6DSOX_0, data_raw_acceleration.u8bit);

 // call fall detection algorithm here

fall_detection();

    break;

  

default:

/* Flush unused samples */

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

   CUSTOM_MOTION_SENSOR_Read_raw_FIFO_data(CUSTOM_LSM6DSOX_0, dummy.u8bit);

   break;

}

}

 }

  HAL_Delay(400);

 }

while(1)

  /* USER CODE END WHILE */

{

  MX_APPE_Process();

  /* USER CODE BEGIN 3 */

  UTIL_SEQ_SetTask(1 << CFG_TASK_MY_TASK_ID, CFG_SCH_PRIO_0);

 }

 }

// Code to set interrupt

/**

 * @brief Set the LSM6DSOX FIFO watermark on INT2 pin

 * @param pObj the device pObj

 * @param Status FIFO watermark interrupt on INT2 pin status

 * @retval 0 in case of success, an error code otherwise

 */

int32_t LSM6DSOX_FIFO_Set_INT2_FIFO_Watermark(LSM6DSOX_Object_t *pObj, uint8_t Status)

{

// lsm6dsox_reg_t reg;

 lsm6dsox_int2_ctrl_t reg;

// if (lsm6dsox_read_reg(&(pObj->Ctx), LSM6DSOX_INT2_CTRL, &reg.byte, 1) != LSM6DSOX_OK)

 if (lsm6dsox_read_reg(&(pObj->Ctx), LSM6DSOX_INT2_CTRL, (uint8_t*)&reg, 1) != LSM6DSOX_OK)

 {

  return LSM6DSOX_ERROR;

 }

 reg.int2_fifo_th = 1;

 if (lsm6dsox_write_reg(&(pObj->Ctx), LSM6DSOX_INT2_CTRL, (uint8_t*)&reg, 1) != LSM6DSOX_OK)

 {

  return LSM6DSOX_ERROR;

 }

 return LSM6DSOX_OK;

}

// External interrupt callback.

/* USER CODE BEGIN FD_WRAP_FUNCTIONS */

void HAL_GPIO_EXTI_Callback( uint16_t GPIO_Pin )

{

//printf("GPIO_Pin %d\n\r",GPIO_Pin);

 switch (GPIO_Pin)

 {

  case BUTTON_SW1_PIN:

   APP_BLE_Key_Button1_Action();

   break; 

  case BUTTON_SW2_PIN:

   APP_BLE_Key_Button2_Action();

   break; 

  case BUTTON_SW3_PIN:

   APP_BLE_Key_Button3_Action();

   break;

  default:

   break;

 }

 if (GPIO_Pin == 64) {

 readFlag = 1;

 }

 return;

}

1 REPLY 1
Andrew Neil
Evangelist III

@vtall.1​ ​  "LSMDSOX sensor"

Do you mean LSM6DSOX ?

"try to simulate a fall (the rapid moment) causing program not causing interrupt."

Do you mean the accelerometer doesn't generate an interrupt, or the STM32 doesn't see the interrupt?

0693W000008xsqBQAQ.png