Reference

BMI323 API Description

 /**
   * @fn DFRobot_BMI323
   * @brief Constructor
   * @details Constructor - I2C interface
   * @param wire TwoWire object pointer, default &Wire
   * @param i2cAddr I2C address, default 0x69
   * @return None
   */
  DFRobot_BMI323(TwoWire *wire = &Wire, uint8_t i2cAddr = 0x69);

  /**
   * @fn begin
   * @brief Initialization function
   * @details Initialize I2C interface, chip registers and feature context
   * @param None
   * @return bool type, indicates the initialization status
   * @retval true Initialization successful
   * @retval false Initialization failed
   */
  bool begin(void);

  /**
   * @fn configAccel
   * @brief Configure accelerometer
   * @param odr Output data rate selection (see: eAccelODR_t)
   * @n Available rates:
   * @n - eAccelODR0_78125Hz:  0.78125 Hz
   * @n - eAccelODR1_5625Hz:   1.5625 Hz
   * @n - eAccelODR3_125Hz:    3.125 Hz
   * @n - eAccelODR6_25Hz:     6.25 Hz
   * @n - eAccelODR12_5Hz:     12.5 Hz
   * @n - eAccelODR25Hz:       25 Hz
   * @n - eAccelODR50Hz:       50 Hz
   * @n - eAccelODR100Hz:      100 Hz
   * @n - eAccelODR200Hz:      200 Hz
   * @n - eAccelODR400Hz:      400 Hz
   * @n - eAccelODR800Hz:      800 Hz
   * @n - eAccelODR1600Hz:     1600 Hz
   * @n - eAccelODR3200Hz:     3200 Hz
   * @n - eAccelODR6400Hz:     6400 Hz
   * @n @note ODR range limitations (based on operating mode):
   * @n - Low power mode: 0.78Hz ~ 400Hz
   * @n - Normal mode:    12.5Hz ~ 6400Hz
   * @n - High performance mode: 12.5Hz ~ 6400Hz
   * @param range Range selection (see: eAccelRange_t)
   * @n Available ranges:
   * @n - eAccelRange2G:   ±2g
   * @n - eAccelRange4G:   ±4g
   * @n - eAccelRange8G:   ±8g
   * @n - eAccelRange16G:  ±16g
   * @param mode Operating mode selection (see: eAccelMode_t), default eAccelModeNormal
   * @n Available modes:
   * @n - eAccelModeLowPower:  Low power mode
   * @n - eAccelModeNormal:    Normal mode (default)
   * @n - eAccelModeHighPerf:  High performance mode
   * @return bool type, indicates the configuration status
   * @retval true Configuration successful
   * @retval false Configuration failed
   */
  bool configAccel(eAccelODR_t odr, eAccelRange_t range, eAccelMode_t mode = eAccelModeNormal);

  /**
   * @fn configGyro
   * @brief Configure gyroscope
   * @param odr Output data rate selection (see: eGyroODR_t)
   * @n Available rates:
   * @n - eGyroODR0_78125Hz: 0.78125 Hz
   * @n - eGyroODR1_5625Hz:  1.5625 Hz
   * @n - eGyroODR3_125Hz:   3.125 Hz
   * @n - eGyroODR6_25Hz:    6.25 Hz
   * @n - eGyroODR12_5Hz:    12.5 Hz
   * @n - eGyroODR25Hz:      25 Hz
   * @n - eGyroODR50Hz:      50 Hz
   * @n - eGyroODR100Hz:     100 Hz
   * @n - eGyroODR200Hz:     200 Hz
   * @n - eGyroODR400Hz:     400 Hz
   * @n - eGyroODR800Hz:     800 Hz
   * @n - eGyroODR1600Hz:    1600 Hz
   * @n - eGyroODR3200Hz:    3200 Hz
   * @n - eGyroODR6400Hz:    6400 Hz
   * @n @note ODR range limitations (based on operating mode):
   * @n - Low power mode: 0.78Hz ~ 400Hz
   * @n - Normal mode:    12.5Hz ~ 6400Hz
   * @n - High performance mode: 12.5Hz ~ 6400Hz
   * @param range Range selection (see: eGyroRange_t)
   * @n Available ranges:
   * @n - eGyroRange125DPS:   ±125dps
   * @n - eGyroRange250DPS:   ±250dps
   * @n - eGyroRange500DPS:   ±500dps
   * @n - eGyroRange1000DPS:  ±1000dps
   * @n - eGyroRange2000DPS:  ±2000dps
   * @param mode Operating mode selection (see: eGyroMode_t), default eGyroModeNormal
   * @n Available modes:
   * @n - eGyroModeLowPower:  Low power mode
   * @n - eGyroModeNormal:    Normal mode (default)
   * @n - eGyroModeHighPerf:  High performance mode
   * @return bool type, indicates the configuration status
   * @retval true Configuration successful
   * @retval false Configuration failed
   */
  bool configGyro(eGyroODR_t odr, eGyroRange_t range, eGyroMode_t mode = eGyroModeNormal);

  /**
   * @fn getAccelGyroData
   * @brief Read accelerometer and gyroscope simultaneously and return physical units
   * @details Read accelerometer and gyroscope raw data at once, convert to g/dps and return
   * @param accel Accelerometer output
   * @param gyro Gyroscope output
   * @return bool type, indicates the read status
   * @retval true Read successful
   * @retval false Read failed
   */
  bool getAccelGyroData(sSensorData *accel, sSensorData *gyro);

  /**
   * @fn enableStepCounterInt
   * @brief Enable step counter interrupt function
   * @details Configure step counter function and map to specified interrupt pin, interrupt will be triggered when step count changes
   * @param pin Bound interrupt pin (eINT1 or eINT2)
   * @return bool type, indicates the configuration status
   * @retval true Configuration successful
   * @retval false Configuration failed
   */
  bool enableStepCounterInt(eInt_t pin);

  /**
   * @fn readStepCounter
   * @brief Read step counter data
   * @param stepVal Step count output pointer, the read step count will be written to the memory pointed by this pointer
   * @return int8_t BMI3_OK indicates success, other values indicate failure
   */
  int8_t readStepCounter(uint16_t *stepVal);

  /**
   * @fn getIntStatus
   * @brief Get interrupt status
   * @details Read and combine interrupt status from both INT1 and INT2 pins. The return value is the OR combination of INT1 and INT2 status registers.
   * @return uint16_t Combined interrupt status register value (INT1 | INT2). Each bit represents a different interrupt type:
   * @n - BMI3_INT_STATUS_ANY_MOTION: Any motion detected
   * @n - BMI3_INT_STATUS_NO_MOTION: No motion detected
   * @n - BMI3_INT_STATUS_FLAT: Flat detection
   * @n - BMI3_INT_STATUS_ORIENTATION: Orientation change
   * @n - BMI3_INT_STATUS_STEP_DETECTOR: Step detected
   * @n - BMI3_INT_STATUS_SIG_MOTION: Significant motion detected
   * @n - BMI3_INT_STATUS_TILT: Tilt detected
   * @n - BMI3_INT_STATUS_TAP: Tap detected
   */
  uint16_t getIntStatus(void);

  /**
   * @fn enableAnyMotionInt
   * @brief Configure any-motion threshold interrupt (using official structure parameters)
   * @param config Any-motion configuration structure (see bmi3_any_motion_config)
   * @n Parameter description:
   * @n - slope_thres: Acceleration slope threshold, range
   * 0-4095, unit 1.953mg/LSB (official example: 9 ≈ 17.6mg)
   * @n - hysteresis: Hysteresis value, range 0-1023, unit 1.953mg/LSB (official example: 5 ≈ 9.8mg)
   * @n - duration: Duration, range 0-8191, unit 20ms (official example: 9 = 180ms)
   * @n - acc_ref_up: Acceleration reference update mode, 0=OnEvent, 1=Always (official example: 1)
   * @n - wait_time: Wait time, range 0-7, unit 20ms (official example: 4-5 = 80-100ms)
   * @param pin Bound interrupt pin
   * @param axisMask Axis selection mask (default: eAxisXYZ)
   * @return bool type, indicates the configuration status
   * @retval true Configuration successful
   * @retval false Configuration failed
   */
  bool enableAnyMotionInt(const struct bmi3_any_motion_config &config,
                          eInt_t pin, uint8_t axisMask = eAxisXYZ);

  /**
   * @fn enableNoMotionInt
   * @brief Configure no-motion threshold interrupt (using official structure parameters)
   * @param config No-motion detection configuration structure (see bmi3_no_motion_config)
   * @n Parameter description:
   * @n - slope_thres: Acceleration slope threshold, range
   * 0-4095, unit 1.953mg/LSB (official example: 9 ≈ 17.6mg)
   * @n - hysteresis: Hysteresis value, range 0-1023, unit 1.953mg/LSB (official example: 5 ≈ 9.8mg)
   * @n - duration: Duration, range 0-8191, unit 20ms (official example: 9 = 180ms)
   * @n - acc_ref_up: Acceleration reference update mode, 0=OnEvent, 1=Always (official example: 1)
   * @n - wait_time: Wait time, range 0-7, unit 20ms (official example: 5 = 100ms)
   * @param pin Bound interrupt pin
   * @param axisMask Axis selection mask (default: eAxisXYZ)
   * @return bool type, indicates the configuration status
   * @retval true Configuration successful
   * @retval false Configuration failed
   */
  bool enableNoMotionInt(const struct bmi3_no_motion_config &config, eInt_t pin,
                         uint8_t axisMask = eAxisXYZ);

  /**
   * @fn enableSigMotionInt
   * @brief Configure significant motion detection interrupt (using official structure parameters)
   * @param config Significant motion configuration structure (see bmi3_sig_motion_config)
   * @n Parameter description:
   * @n - block_size: Detection segment size, range 0-65535 (official example: 200)
   * @n - peak_2_peak_min: Peak-to-peak acceleration minimum, range 0-1023 (official example: 30)
   * @n - peak_2_peak_max: Peak-to-peak acceleration maximum, range 0-1023 (official example: 30)
   * @n - mcr_min: Mean crossing rate per second minimum, range 0-62 (official example: 0x10 = 16)
   * @n - mcr_max: Mean crossing rate per second maximum, range 0-62 (official example: 0x10 = 16)
   * @param pin Bound interrupt pin
   * @return bool type, indicates the configuration status
   * @retval true Configuration successful
   * @retval false Configuration failed
   */
  bool enableSigMotionInt(const struct bmi3_sig_motion_config &config,
                          eInt_t pin);

  /**
   * @fn enableFlatInt
   * @brief Configure flat detection interrupt (using official structure parameters)
   * @param config Flat detection configuration structure (see bmi3_flat_config)
   * @n Parameter description:
   * @n - theta: Maximum allowed tilt angle, range 0-63, angle calculated as 64 *
   * (tan(angle)^2) (official example: 9)
   * @n - blocking: Blocking mode, 0=MODE_0(disabled), 1=MODE_1(>1.5g),
   * 2=MODE_2(>1.5g or slope>half threshold), 3=MODE_3(>1.5g or slope>threshold) (official example: 3)
   * @n - hold_time: Minimum duration for device to maintain flat state, range 0-255, unit 20ms (official example: 50 = 1000ms)
   * @n - hysteresis: Hysteresis angle for flat detection, range 0-255 (official example: 9)
   * @n - slope_thres: Minimum slope between consecutive acceleration samples, range 0-255 (official example: 0xCD = 205)
   * @param pin Bound interrupt pin
   * @return bool type, indicates the configuration status
   * @retval true Configuration successful
   * @retval false Configuration failed
   */
  bool enableFlatInt(const struct bmi3_flat_config &config, eInt_t pin);

  /**
   * @fn enableOrientationInt
   * @brief Configure orientation detection interrupt (using official structure parameters)
   * @param config Orientation detection configuration structure (see bmi3_orientation_config)
   * @n Parameter description:
   * @n - ud_en: Whether to detect flip (face up/down), 0=disabled, 1=enabled (official example: 1)
   * @n - hold_time: Required duration for orientation change detection, range 0-255, unit 20ms (official example: 4 = 80ms)
   * @n - hysteresis: Hysteresis for orientation detection, range 0-255 (official example: 5)
   * @n - theta: Maximum allowed tilt angle, range 0-63, angle=64*(tan(angle)^2) (official example: 16)
   * @n - mode: Orientation detection mode, 0/3=symmetric, 1=high asymmetric, 2=low asymmetric (official example: 1)
   * @n - slope_thres: Slope threshold to prevent false detection due to violent motion, range 0-255 (official example: 30)
   * @n - blocking: Blocking mode, 0-3 (official example: 3)
   * @param pin Bound interrupt pin
   * @return bool type, indicates the configuration status
   * @retval true Configuration successful
   * @retval false Configuration failed
   */
  bool enableOrientationInt(const struct bmi3_orientation_config &config,
                            eInt_t pin);

  /**
   * @fn readOrientation
   * @brief Read orientation detection output
   * @param portraitLandscape Portrait/Landscape status output pointer, can be NULL
   * @param faceUpDown Face up/down status output pointer, can be NULL
   * @return bool type, indicates the read status
   * @retval true Read successful
   * @retval false Read failed or feature not enabled
   */
  bool readOrientation(uint8_t *portraitLandscape, uint8_t *faceUpDown);

  /**
   * @fn enableTapInt
   * @brief Configure tap detection interrupt (using official structure parameters)
   * @param config Tap detection configuration structure (see bmi3_tap_detector_config)
   * @n Key parameters (refer to tap.c):
   * @n - axis_sel: Select axis for tap detection (0=X, 1=Y, 2=Z)
   * @n - mode: Detection mode (0=sensitive, 1=normal, 2=robust)
   * @n - tap_peak_thres / tap_shock_settling_dur etc. for timing/amplitude thresholds to determine tap
   * @param pin Bound interrupt pin
   * @param enableSingle Whether to enable single tap detection (default true)
   * @param enableDouble Whether to enable double tap detection (default true)
   * @param enableTriple Whether to enable triple tap detection (default true)
   * @return bool type, indicates the configuration status
   * @retval true Configuration successful
   * @retval false Configuration failed
   */
  bool enableTapInt(const struct bmi3_tap_detector_config &config, eInt_t pin,
                    bool enableSingle = true, bool enableDouble = true,
                    bool enableTriple = true);

  /**
   * @fn readTapStatus
   * @brief Read tap detection status (single/double/triple tap)
   * @param tapMask Output mask (can combine BMI3_TAP_DET_STATUS_SINGLE/DOUBLE/TRIPLE)
   * @return bool type, indicates the read status
   * @retval true Read successful
   * @retval false Read failed
   */
  bool readTapStatus(uint8_t *tapMask);

  /**
   * @fn enableTiltInt
   * @brief Configure tilt detection interrupt (using official structure parameters)
   * @param config Tilt detection configuration structure (see bmi3_tilt_config)
   * @n Key parameters (refer to tilt.c):
   * @n - segment_size: Time window for averaging reference vector, range 0-255
   * @n - min_tilt_angle: Minimum tilt angle to exceed, range 0-255, angle=256*cos(angle)
   * @n - beta_acc_mean: Low-pass averaging coefficient, range 0-65535
   * @param pin Bound interrupt pin
   * @return bool type, indicates the configuration status
   * @retval true Configuration successful
   * @retval false Configuration failed
   */
  bool enableTiltInt(const struct bmi3_tilt_config &config, eInt_t pin);

BMM350 API Description

 /**
   * @fn softReset
   * @brief Soft reset, restore to suspended mode after soft reset.
   */
  void softReset(void);

  /**
   * @fn setOperationMode
   * @brief Set sensor operation mode
   * @param powermode
   * @n eBmm350SuspendMode      suspend mode: Suspend mode is the default power mode of BMM350 after the chip is powered, Current consumption in suspend mode is minimal, 
   *                                           so, this mode is useful for periods when data conversion is not needed. Read and write of all registers is possible.
   * @n eBmm350NormalMode       normal mode: Get geomagnetic data normally.      
   * @n eBmm350ForcedMode       forced mode: Single measurement, the sensor restores to suspend mode when the measurement is done.
   * @n eBmm350ForcedModeFast  To reach ODR = 200Hz is only possible by using FM_ FAST.
   */
  void setOperationMode(enum eBmm350PowerModes_t powermode);


  /**
   * @fn getOperationMode
   * @brief Get sensor operation mode
   * @return result Return sensor operation mode as a character string
   */
  String getOperationMode(void);

  /**
   * @fn setPresetMode
   * @brief Set preset mode, make it easier for users to configure sensor to get geomagnetic data (The default collection rate is 12.5Hz)
   * @param presetMode
   * @n BMM350_PRESETMODE_LOWPOWER       Low power mode, get a fraction of data and take the mean value.
   * @n BMM350_PRESETMODE_REGULAR        Regular mode, get a number of data and take the mean value.
   * @n BMM350_PRESETMODE_ENHANCED       Enhanced mode, get a plenty of data and take the mean value.
   * @n BMM350_PRESETMODE_HIGHACCURACY   High accuracy mode, get a huge number of data and take the mean value.
   */
  void setPresetMode(uint8_t presetMode, uint8_t rate = BMM350_DATA_RATE_12_5HZ);

  /**
   * @fn setRate
   * @brief Set the rate of obtaining geomagnetic data, the higher, the faster (without delay function)
   * @param rate
   * @n BMM350_DATA_RATE_1_5625HZ
   * @n BMM350_DATA_RATE_3_125HZ
   * @n BMM350_DATA_RATE_6_25HZ
   * @n BMM350_DATA_RATE_12_5HZ  (default rate)
   * @n BMM350_DATA_RATE_25HZ
   * @n BMM350_DATA_RATE_50HZ
   * @n BMM350_DATA_RATE_100HZ
   * @n BMM350_DATA_RATE_200HZ
   * @n BMM350_DATA_RATE_400HZ
   */
  void setRate(uint8_t rate);

  /**
   * @fn getRate
   * @brief Get the config data rate, unit: HZ
   * @return rate
   */
  float getRate(void);

  /**
   * @fn selfTest
   * @brief The sensor self test, the returned value indicate the self test result.
   * @param testMode:
   * @n     eBmm350SelfTestNormal               Normal self test, test whether x-axis, y-axis and z-axis are connected or short-circuited
   * @return result The returned character string is the self test result
   */
  String selfTest(eBmm350SelfTest_t testMode = eBmm350SelfTestNormal);

  /**
   * @fn setMeasurementXYZ
   * @brief Enable the measurement at x-axis, y-axis and z-axis, default to be enabled. After disabling, the geomagnetic data at x, y, and z axis are wrong.
   * @param en_x
   * @n   BMM350_X_EN        Enable the measurement at x-axis
   * @n   BMM350_X_DIS       Disable the measurement at x-axis
   * @param en_y
   * @n   BMM350_Y_EN        Enable the measurement at y-axis
   * @n   BMM350_Y_DIS       Disable the measurement at y-axis
   * @param en_z
   * @n   BMM350_Z_EN        Enable the measurement at z-axis
   * @n   BMM350_Z_DIS       Disable the measurement at z-axis
   */
  void setMeasurementXYZ(enum eBmm350XAxisEnDis_t enX = BMM350_X_EN, enum eBmm350YAxisEnDis_t enY = BMM350_Y_EN, enum eBmm350ZAxisEnDis_t enZ = BMM350_Z_EN);

  /**
   * @fn getMeasurementStateXYZ
   * @brief Get the enabling status at x-axis, y-axis and z-axis
   * @return result Return enabling status as a character string
   */
  String getMeasurementStateXYZ(void);

  /**
   * @fn getGeomagneticData
   * @brief Get the geomagnetic data of 3 axis (x, y, z)
   * @return Geomagnetic data structure, unit: (uT)
   */
  sBmm350MagData_t getGeomagneticData(void);

  /**
   * @fn getCompassDegree
   * @brief Get compass degree
   * @return Compass degree (0° - 360°)
   * @n      0° = North, 90° = East, 180° = South, 270° = West.
   */
  float getCompassDegree(void);

  /**
   * @fn setDataReadyPin
   * @brief Enable or disable data ready interrupt pin
   * @n After enabling, the DRDY pin jump when there's data coming.
   * @n After disabling, the DRDY pin will not jump when there's data coming.
   * @n High polarity: active on high, the default is low level, which turns to high level when the interrupt is triggered.
   * @n Low polarity: active on low, default is high level, which turns to low level when the interrupt is triggered.
   * @param modes
   * @n     BMM350_ENABLE_INTERRUPT        Enable DRDY
   * @n     BMM350_DISABLE_INTERRUPT       Disable DRDY
   * @param polarity
   * @n     BMM350_ACTIVE_HIGH              High polarity
   * @n     BMM350_ACTIVE_LOW               Low polarity
   */
  void setDataReadyPin(enum eBmm350InterruptEnableDisable_t modes, enum eBmm350IntrPolarity_t polarity=BMM350_ACTIVE_HIGH);

  /**
   * @fn getDataReadyState
   * @brief Get the data ready status, determine whether the data is ready
   * @return status
   * @n true  Data ready
   * @n false Data is not ready
   */
  bool getDataReadyState(void);

  /**
   * @fn setThresholdInterrupt(uint8_t modes, int8_t threshold, uint8_t polarity)
   * @brief Set threshold interrupt, an interrupt is triggered when the geomagnetic value of a channel is beyond/below the threshold
   * @n      High polarity: active on high level, the default is low level, which turns to high level when the interrupt is triggered.
   * @n      Low polarity: active on low level, the default is high level, which turns to low level when the interrupt is triggered.
   * @param modes
   * @n     LOW_THRESHOLD_INTERRUPT       Low threshold interrupt mode
   * @n     HIGH_THRESHOLD_INTERRUPT      High threshold interrupt mode
   * @param  threshold
   * @n     Threshold, default to expand 16 times, for example: under low threshold mode, if the threshold is set to be 1, actually the geomagnetic data below 16 will trigger an interrupt
   * @param polarity
   * @n     POLARITY_HIGH      High polarity
   * @n     POLARITY_LOW       Low polarity
   */
  void setThresholdInterrupt(uint8_t modes, int8_t threshold, enum eBmm350IntrPolarity_t polarity);

  /**
   * @fn getThresholdData
   * @brief Get the data with threshold interrupt occurred
   * @return Returns the structure for storing geomagnetic data, the structure stores the data of 3 axis and interrupt status,
   * @n The interrupt is not triggered when the data at x-axis, y-axis and z-axis are NO_DATA
   * @n mag_x、mag_y、mag_z store geomagnetic data
   * @n interrupt_x、interrupt_y、interrupt_z store the xyz axis interrupt state
   */
  sBmm350ThresholdData_t getThresholdData(void);

Was this article helpful?

TOP