I’m really struggling with triggering on IMU generated interrupts.
It seems that I am setting up the interrupt on the IMU correctly since the interrupt pin on the nrf is going up and down when I read it in the loop instead of in the ISR. However, the ISR appears to never be triggered or it’s otherwise stuck.
I initially started with sending data out using BLE and thought that I somehow encountered this bug: Only one pin interrupt supported · Issue #7 · arduino/ArduinoCore-nRF528x-mbedos · GitHub, so I went back to basing the ISR on the HighLevelExample and eventually even to the LowLevelExample to isolate the issue, attached below. I couldn’t even light up an LED in the ISR. Any ideas what’s wrong?
#include "LSM6DS3.h"
#include "Wire.h"
//#include "SPI.h"
uint16_t errorsAndWarnings = 0;
int16_t gyroX, gyroY, gyroZ, accX, accY, accZ;
//Create instance of LSM6DS3Core
LSM6DS3Core myIMU(I2C_MODE, 0x6A); //I2C device address 0x6A
#define int1Pin PIN_LSM6DS3TR_C_INT1
void setup() {
//Init Serial port
Serial.begin(9600);
while (!Serial);
//Call .beginCore() to configure the IMU
if (myIMU.beginCore() != 0) {
Serial.print("\nDevice Error.\n");
} else {
Serial.print("\nDevice OK.\n");
}
uint8_t dataToWrite = 0; //Temporary variable
//Setup the accelerometer******************************
dataToWrite = 0; //Start Fresh!
// dataToWrite |= LSM6DS3_ACC_GYRO_BW_XL_50Hz;
// dataToWrite |= LSM6DS3_ACC_GYRO_FS_XL_8g;
dataToWrite |= LSM6DS3_ACC_GYRO_ODR_XL_13Hz;
//Now, write the patched together data
errorsAndWarnings += myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, dataToWrite);
//Set the ODR bit
//errorsAndWarnings += myIMU.readRegister(&dataToWrite, LSM6DS3_ACC_GYRO_CTRL4_C);
//dataToWrite &= ~((uint8_t)LSM6DS3_ACC_GYRO_BW_SCAL_ODR_ENABLED);
// myIMU.writeRegister(LSM6DS3_ACC_GYRO_INT1_CTRL, LSM6DS3_ACC_GYRO_INT1_DRDY_XL_ENABLED|LSM6DS3_ACC_GYRO_INT1_DRDY_G_ENABLED);
errorsAndWarnings += myIMU.writeRegister(LSM6DS3_ACC_GYRO_INT1_CTRL, LSM6DS3_ACC_GYRO_INT1_DRDY_XL_ENABLED);
Serial.println("Attaching IMU interrupt ...");
pinMode(int1Pin, INPUT);
attachInterrupt(digitalPinToInterrupt(int1Pin), interruptService, RISING);
// interrupts();
}
void loop() {
//Get all parameters
Serial.print("\nAccelerometer Counts:\n");
Serial.println(digitalRead(int1Pin));
/* //Acelerometer axis X
if (myIMU.readRegisterInt16(&gyroX, LSM6DS3_ACC_GYRO_OUTX_L_XL) != 0) {
errorsAndWarnings++;
}
*/
Serial.print(" X = ");
Serial.println(gyroX);
//Acelerometer axis Y
Serial.print(" Y = ");
Serial.println(gyroY);
//Acelerometer axis Z
Serial.print(" Z = ");
Serial.println(gyroZ);
Serial.println();
Serial.print("Total reported Errors and Warnings: ");
Serial.println(errorsAndWarnings);
delay(1000);
// while(1);
}
void interruptService () {
// digitalWrite(LED_BUILTIN, HIGH);
// detachInterrupt(digitalPinToInterrupt(int1Pin));
//Acelerometer axis X
if (myIMU.readRegisterInt16(&gyroX, LSM6DS3_ACC_GYRO_OUTX_L_XL) != 0) {
errorsAndWarnings++;
}
//Acelerometer axis Y
if (myIMU.readRegisterInt16(&gyroY, LSM6DS3_ACC_GYRO_OUTY_L_XL) != 0) {
errorsAndWarnings++;
}
//Acelerometer axis Z
if (myIMU.readRegisterInt16(&gyroZ, LSM6DS3_ACC_GYRO_OUTZ_L_XL) != 0) {
errorsAndWarnings++;
}
}```