cancel
Showing results for 
Search instead for 
Did you mean: 

How to use INT1 or INT2 interrupts in lsm6dso with relative tilt function

LClad.1
Associate II

Hi,

I'm trying to implement a relative tilt function using lsm6dso with nrf52832 processor.

Following the AN5192, the procedures to enable tilt detection are:

1.Write 80h to FUNC_CFG_ACCESS// Enable access to embedded functions registers

2.Write 10h to EMB_FUNC_EN_A// Enable tilt detection

3.Write 10h to EMB_FUNC_INT1// Tilt interrupt driven to INT1 pin

4.Write 80h to PAGE_RW// Enable latched mode for embedded functions

5.Write 00h to FUNC_CFG_ACCESS// Disable access to embedded functions registers

6.Write 02h to MD1_CFG// Enable embedded functions interrupt routing

7.Write 20h to CTRL1_XL// Turn on the accelerometer// ODR_XL = 26 Hz, FS_XL = ±2 g

Below is my code:

void LSM6DSO_CFG(){

   ret_code_t err_code;

   uint8_t dataToWrite = 0; //Temporary variable

   uint8_t func_cfg_access = 0x80U;

   err_code = write_LSM6DSO(m_twi_lsm6ds0, LSM6DSO_I2C_ADD_H, FUNC_CFG_ACCESS,&func_cfg_access, sizeof(func_cfg_access),true); // enable gyro and accel data ready interrupt on INT1

   APP_ERROR_CHECK(err_code);

   func_cfg_access = 0x10U; //tilt detection

   err_code = write_LSM6DSO(m_twi_lsm6ds0, LSM6DSO_I2C_ADD_H, EMB_FUNC_EN_A,&func_cfg_access, sizeof(func_cfg_access),true); // enable gyro and accel data ready interrupt on INT1

   APP_ERROR_CHECK(err_code);

   func_cfg_access = 0x10U; //tilt interrupt

   err_code = write_LSM6DSO(m_twi_lsm6ds0, LSM6DSO_I2C_ADD_H, EMB_FUNC_INT1,&func_cfg_access, sizeof(func_cfg_access),true); // enable gyro and accel data ready interrupt on INT1

   APP_ERROR_CHECK(err_code);

   func_cfg_access = 0x80U; //Enable latched mode

   err_code = write_LSM6DSO(m_twi_lsm6ds0, LSM6DSO_I2C_ADD_H, PAGE_RW,&func_cfg_access, sizeof(func_cfg_access),true); // enable gyro and accel data ready interrupt on INT1

   APP_ERROR_CHECK(err_code);

   func_cfg_access = 0x00U;

   err_code = write_LSM6DSO(m_twi_lsm6ds0, LSM6DSO_I2C_ADD_H, FUNC_CFG_ACCESS,&func_cfg_access, sizeof(func_cfg_access),true); // enable gyro and accel data ready interrupt on INT1

   APP_ERROR_CHECK(err_code);

   func_cfg_access = 0x02U;

   err_code = write_LSM6DSO(m_twi_lsm6ds0, LSM6DSO_I2C_ADD_H, MD1_CFG,&func_cfg_access, sizeof(func_cfg_access),true); // enable gyro and accel data ready interrupt on INT1

   APP_ERROR_CHECK(err_code);

   dataToWrite = 0x20U;

 err_code = write_LSM6DSO(m_twi_lsm6ds0, LSM6DSO_I2C_ADD_H, LSM6DSO_CTRL1_XL_REG,&dataToWrite, sizeof(dataToWrite),true);

 APP_ERROR_CHECK(err_code);

}

//===================================================

int main(void)

{

    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));

   NRF_LOG_DEFAULT_BACKENDS_INIT();

    ret_code_t ret;

   twi_init();

    gpio_init(); //enable pin interrupt

   LSM6DSO_CFG();

   NRF_LOG_INFO("\r\nTWI sensor example started.");

   NRF_LOG_FLUSH();

   while (true)   {

     

        LSM6DSO_READ();

   }

}

//===================================================

void LSM6DSO_READ(void)

{

   ret_code_t err_code;

   uint8_t rx_data = EMB_FUNC_STATUS;

   err_code = read_LSM6DSO(m_twi_lsm6ds0, LSM6DSO_I2C_ADD_H,EMB_FUNC_STATUS ,&rx_data, sizeof(rx_data),true);

   APP_ERROR_CHECK(err_code);

}

I was enabled interrupt in nrf and tested independentlly with success, but using osciloscope, the pin int1 connected doesn't work.

Anyone can help me?

Laerte

1 REPLY 1
Eleon BORLINI
ST Employee

Hi @LClad.1​ , I don't understand if you was able to detect the interrupt or not... Did you check the INT1_TILT bit of the EMB_FUNC_INT1 (0Ah) register by polling it, to see if it is set to '1', even if not routed on the INT1 pin? Regards