Hi, I’m trying to get the “Single Tap Interrupt” from the integrated LSM6DS3 working on XIAO BLE Sense.
As far as I know from the schematics, Int1 of LSM6DS3 is connected to P0.11 from NRF52480, which is the digital pin 18, as defined by PIN_LSM6DS3TR_C_INT1 .
In my following code, I try to set up the “Single Tap” recognition on LMS6DS3 as described via Application Note. I also used as reference the interrupt set up from another board, which is published by sparkfun.
Unfortunately, no interrupt is generated.
I was able to verify, that at least my pin assumptions must be correct, by optionally setting the “Interrupt Level Activation” from default HIGH, to optinally LOW via LSM6DS3_ACC_GYRO_CTRL3_C register. For these cases, I was able to read the non active interrupt pin regarding as HIGH or LOW.
Did anybody already set up a working interrupt from LMS6DS3 on this board? Any corrections regarding my code?
Thanks in advance!
#include "LSM6DS3.h" // from Seeed_Arduino_LSM6DS3 Package
#include "Wire.h"
#include "SPI.h"
//Interrupt variables
#define int1Pin PIN_LSM6DS3TR_C_INT1 //Pin 18
uint8_t int1Status = 0;
LSM6DS3Core myIMU( I2C_MODE, 0x6A );
void setup()
{
Serial.begin(9600);
delay(1000); //relax...
//Call .beginCore() to configure the IMU
if( myIMU.beginCore() != 0 )
{
Serial.print("Error at beginCore().\n");
}
else
{
Serial.print("\nbeginCore() passed.\n");
}
//Error accumulation variable
uint8_t errorAccumulator = 0;
uint8_t dataToWrite = 0; //Temporary variable
// Turn on the accelerometer
// ODR_XL = 416 Hz, FS_XL = 2g
errorAccumulator += myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, 0x60);
// Enable tap detection on X, Y, Z axis, but do not latch output
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_TAP_CFG1, 0x0E );
// Set tap threshold
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_TAP_THS_6D, 0x09 );
// Set Duration, Quiet and Shock time windows
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_INT_DUR2, 0x06);
// Only single tap enabled (SINGLE_DOUBLE_TAP = 0)
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_WAKE_UP_THS, 0x00 );
// Single tap interrupt driven to INT1 pin
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_MD1_CFG, 0x40 );
if( errorAccumulator )
{
Serial.println("Problem configuring the device.");
}
else
{
Serial.println("Device O.K.");
}
pinMode(int1Pin, INPUT);
attachInterrupt(digitalPinToInterrupt(int1Pin), int1ISR, RISING);
}
void loop()
{
if( int1Status > 0 ) //If ISR has been serviced at least once
{
Serial.print("Single-tap event\n");
//Clear the ISR counter
int1Status = 0;
}
Serial.print("Loop is alive...\n");
delay(1000);
}
void int1ISR()
{
//Serial.println("Interrupt serviced.");
int1Status++;
}