Skip to content

Can't get the interrupts to work consistently #26

Open
@njhulst

Description

@njhulst

Hi, I'm trying to run the interrupts_subclassing example (with a small change: a bool flag instead of a print statement in the interrupt function) and I'm experiencing inconsistent behavior. When I upload the code to the board or push the button to restart the program, sometimes the interrupts will come in ("Got new data!" will be printed in my Serial monitor, as expected), sometimes they won't come in (nothing will be printed). I tried with a blinking led in the interrupt function, that results in the same observation (behavior is sometimes as I expect, sometimes nothing happens). I have tried on a different (brand new) board, the same happens.
I added my code below:

#include <Arduino.h>
#include <Arduino_BMI270_BMM150.h>

class MyBoschSensor: public BoschSensorClass {

  public:
    MyBoschSensor(TwoWire& wire = Wire) : BoschSensorClass(wire) {};

  protected:
    virtual int8_t configure_sensor(struct bmi2_dev *dev)
    {
      int8_t rslt;
      uint8_t sens_list[2] = { BMI2_ACCEL, BMI2_GYRO };

      struct bmi2_int_pin_config int_pin_cfg;
      int_pin_cfg.pin_type = BMI2_INT1;
      int_pin_cfg.int_latch = BMI2_INT_NON_LATCH;
      int_pin_cfg.pin_cfg[0].lvl = BMI2_INT_ACTIVE_HIGH;
      int_pin_cfg.pin_cfg[0].od = BMI2_INT_PUSH_PULL;
      int_pin_cfg.pin_cfg[0].output_en = BMI2_INT_OUTPUT_ENABLE;
      int_pin_cfg.pin_cfg[0].input_en = BMI2_INT_INPUT_DISABLE;

      struct bmi2_sens_config sens_cfg[2];
      sens_cfg[0].type = BMI2_ACCEL;
      sens_cfg[0].cfg.acc.bwp = BMI2_ACC_OSR2_AVG2;
      sens_cfg[0].cfg.acc.odr = BMI2_ACC_ODR_25HZ;
      sens_cfg[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
      sens_cfg[0].cfg.acc.range = BMI2_ACC_RANGE_4G;
      sens_cfg[1].type = BMI2_GYRO;
      sens_cfg[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
      sens_cfg[1].cfg.gyr.bwp = BMI2_GYR_OSR2_MODE;
      sens_cfg[1].cfg.gyr.odr = BMI2_GYR_ODR_25HZ;
      sens_cfg[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
      sens_cfg[1].cfg.gyr.ois_range = BMI2_GYR_OIS_2000;

      rslt = bmi2_set_int_pin_config(&int_pin_cfg, dev);
      if (rslt != BMI2_OK)
        return rslt;

      rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, dev);
      if (rslt != BMI2_OK)
        return rslt;

      rslt = bmi2_set_sensor_config(sens_cfg, 2, dev);
      if (rslt != BMI2_OK)
        return rslt;

      rslt = bmi2_sensor_enable(sens_list, 2, dev);
      if (rslt != BMI2_OK)
        return rslt;

      return rslt;
    }
};

volatile bool interruptDetected;
MyBoschSensor customIMU(Wire1);

void handleInterrupt() {
  interruptDetected = true;
  //digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}

void setup() {
  Serial.begin(9600);
  while (!Serial);

  //pinMode(LED_BUILTIN, OUTPUT);

  customIMU.debug(Serial);
  customIMU.onInterrupt(handleInterrupt);
  customIMU.begin();
}

void loop() {
  if (interruptDetected) {
    Serial.println("Got new data!");
    interruptDetected = false;
  }
}

Is anyone experiencing something similar, could it be something in my setup? I'm using platformio in VSCode, the following is my ini file:

[env:nano33ble]
platform = [email protected]
board = nano33ble
framework = arduino

board_build.mcu = nrf52840

monitor_speed = 9600

I'm using a Nano 33 BLE Sense Rev 2 obviously, should I change something in the ini file? I haven't found an option to select the sense rev 2 in platformIO.

Any clues on what might be going on are much appreciated !

Metadata

Metadata

Assignees

Labels

type: imperfectionPerceived defect in any part of project

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions