cancel
Showing results for 
Search instead for 
Did you mean: 

LSM6DSL Interrupt Generation -- Interrupts constantly fire

EBurnsy
Associate

I'm trying to get the Activity/Inactivity interrupt generation on the LSM6DSL working. I've implemented the example code in the data sheet below. I'm using an stm32L475.

However, this interrupt fires constantly, regardless of either the sleep duration time or the activity threshold. From reading the SLEEP_STATE_IA from the WAKE_UP_SRC register, it also appears to always be the inactivity interrupt firing, not the activity one.

In trying to debug this, I also tried implementing the other interrupt generators (Free Fall, Single Tap, etc...). These interrupts also constantly fired, regardless of their configurations.

However, when I tried implementing the Data Ready Interrupt, it worked correctly. I even slowed the accelerometer down to 1.6Hz to verify.

So what am I doing wrong for interrupt generation? Is my GPIO interrupt line maybe messed up?

@Miroslav BATEK  I read through like a thousand of your answers in trying to debug this, so maybe you're the right person to ask 🙂

Example Free Fall code:

uint8_t data1[2] = {CTRL1_XL, 0x50};
i2c_transaction(WRITE_ADR, WRITE_I2C, data1, 2);

// 2. Write 02h to WAKE_UP_DUR
uint8_t data2[2] = {WAKE_UP_DUR, 0x02};
i2c_transaction(WRITE_ADR, WRITE_I2C, data2, 2);

// 3. Write 02h to WAKE_UP_THS
uint8_t data3[2] = {WAKE_UP_THS, 0x02};
i2c_transaction(WRITE_ADR, WRITE_I2C, data3, 2);

// 4. Write E0h to TAP_CFG
uint8_t data4[2] = {TAP_CFG, 0xE0};
i2c_transaction(WRITE_ADR, WRITE_I2C, data4, 2);


// 5. Write 80h to MD1_CFG
uint8_t data5[2] = {MD1_CFG, 0x80};
i2c_transaction(WRITE_ADR, WRITE_I2C, data5, 2);

------------------------------------------------------------------------

My interrupt line config:

// GPIO D11 is the I2C interrupt line for LSD6DSL
RCC->AHB2ENR |= RCC_AHB2ENR_GPIODEN;
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;

// Clear mode bits (and also set to input mode 00)
GPIOD->MODER &= ~(GPIO_MODER_MODE11_Msk);
GPIOD->PUPDR &= ~(GPIO_PUPDR_PUPD11_Msk);
GPIOD->PUPDR |= (GPIO_PUPDR_PUPD11_1);

SYSCFG->EXTICR[2] |= SYSCFG_EXTICR3_EXTI11_PD;
EXTI->IMR1 |= EXTI_IMR1_IM11;
EXTI->RTSR1 |= EXTI_RTSR1_RT11;

NVIC_EnableIRQ(EXTI15_10_IRQn);
NVIC_SetPriority(EXTI15_10_IRQn, 0); // Adjust priority as needed

------------------------------------------------------------------------------------------

My interrupt handler:
void EXTI15_10_IRQHandler(void) {
  if (EXTI->PR1 & EXTI_PR1_PIF11) { // Check if PD11 triggered the interrupt
    read_xl = 1;
    EXTI->PR1 = EXTI_PR1_PIF11;
  }
}

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Miroslav BATEK
ST Employee

I think the sensor configuration is correct.

But I think you interrupt handler is not correct. You should clear the interrupt.

This line seems to me wrong: EXTI->PR1 = EXTI_PR1_PIF11;

I'm not expect on register approach I prefer to use HAL drivers. You can use an example for GPIO interrupts.

View solution in original post

2 REPLIES 2
Miroslav BATEK
ST Employee

I think the sensor configuration is correct.

But I think you interrupt handler is not correct. You should clear the interrupt.

This line seems to me wrong: EXTI->PR1 = EXTI_PR1_PIF11;

I'm not expect on register approach I prefer to use HAL drivers. You can use an example for GPIO interrupts.

I ended up reflashing the board with the same exact code as before (albeit from a different laptop) and it worked perfectly and never gave me problems again. Maybe my IDE had acquired some weird state. Thanks for responding though!