Reference
Last revision 2025/12/17
API Description
/*!
* @brief Soft reset, restore to suspended mode after soft reset and then enter sleep mode, soft reset can't be implemented under suspend mode
*/
void softReset(void);
/*!
* @brief Set sensor operation mode
* @param op mode
* BMM150_POWERMODE_NORMAL // normal mode Get geomagnetic data normally
* BMM150_POWERMODE_FORCED // forced mode Single measurement, the sensor restores to sleep mode when the measurement is done.
* BMM150_POWERMODE_SLEEP // sleep mode Users can visit all the registers, but can’t measure geomagnetic data
* BMM150_POWERMODE_SUSPEND // suspend mode At the time the sensor cpu doesn’t work and can’t implement any operation. Users can only visit the content of the control register BMM150_REG_POWER_CONTROL
*/
void setOperationMode(uint8_t opMode);
/*!
* @brief Get sensor operation mode
* @return result Return sensor operation mode as a character string
*/
String getOperationMode(void);
/*!
* @brief Set preset mode, make it easier for users to configure sensor to get geomagnetic data
* @param presetMode
* BMM150_PRESETMODE_LOWPOWER // Low power mode, get a fraction of data and take the mean value.
* BMM150_PRESETMODE_REGULAR // Regular mode, get a number of data and take the mean value.
* BMM150_PRESETMODE_ENHANCED // Enhanced mode, get a plenty of data and take the mean value.
* BMM150_PRESETMODE_HIGHACCURACY // High accuracy mode, get a huge number of data and take the mean value.
*/
void setPresetMode(uint8_t presetMode);
/*!
* @brief Set the rate of obtaining geomagnetic data, the higher, the faster (without delay function)
* @param rate
* BMM150_DATA_RATE_02HZ
* BMM150_DATA_RATE_06HZ
* BMM150_DATA_RATE_08HZ
* BMM150_DATA_RATE_10HZ (default rate)
* BMM150_DATA_RATE_15HZ
* BMM150_DATA_RATE_20HZ
* BMM150_DATA_RATE_25HZ
* BMM150_DATA_RATE_30HZ
*/
void setRate(uint8_t rate);
/*!
* @brief Get the config data rate, unit: HZ
* @return rate
*/
uint8_t getRate(void);
/*!
* @brief Get the geomagnetic data of 3 axis (x, y, z)
*
* @return Geomagnetic data structure, unit: (uT)
*/
sMagData getGeomagneticData(void);
/*!
* @brief Get compass degree
*
* @return Compass degree (0° - 360°)
* 0° = North, 90° = East, 180° = South, 270° = West.
*/
float getCompassDegree(void);
/*!
* @brief Enable or disable data ready interrupt pin
* After enabling, the DRDY pin jump when there's data coming.
* After disabling, the DRDY pin will not jump when there's data coming.
* High polarity: active on high, the default is low level, which turns to high level when the interrupt is triggered.
* Low polarity: active on low, default is high level, which turns to low level when the interrupt is triggered.
* @param modes
* DRDY_ENABLE // Enable DRDY
* DRDY_DISABLE // Disable DRDY
* @param polarity
* POLARITY_HIGH // High polarity
* POLARITY_LOW // Low polarity
*/
void setDataReadyPin(uint8_t modes, uint8_t polarity=POLARITY_HIGH);
/*!
* @brief Get the data ready status, determine whether the data is ready
*
* @return status
* true Data ready
* false Data is not ready
*/
bool getDataReadyState(void);
/*!
* @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 channelX
* MEASUREMENT_X_ENABLE // Enable the measurement at x-axis
* MEASUREMENT_X_DISABLE // Disable the measurement at x-axis
* @param channelY
* MEASUREMENT_Y_ENABLE // Enable the measurement at y-axis
* MEASUREMENT_Y_DISABLE // Disable the measurement at y-axis
* @param channelZ
* MEASUREMENT_Z_ENABLE // Enable the measurement at z-axis
* MEASUREMENT_Z_DISABLE // Disable the measurement at z-axis
*/
void setMeasurementXYZ(uint8_t channelX = MEASUREMENT_X_ENABLE, uint8_t channelY = MEASUREMENT_Y_ENABLE, uint8_t channelZ = MEASUREMENT_Z_ENABLE);
/*!
* @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);
/*!
* @brief Set threshold interrupt, an interrupt is triggered when the geomagnetic value of a channel is beyond/below the threshold
* High polarity: active on high level, the default is low level, which turns to high level when the interrupt is triggered.
* Low polarity: active on low level, the default is high level, which turns to low level when the interrupt is triggered.
* @param modes
* LOW_THRESHOLD_INTERRUPT // Low threshold interrupt mode
* HIGH_THRESHOLD_INTERRUPT // High threshold interrupt mode
* @param threshold
* 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
* POLARITY_HIGH // High polarity
* POLARITY_LOW // Low polarity
*/
void 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
* When an interrupt occurs, INT pin level will jump
* High polarity: active on high level, the default is low level, which turns to high level when the interrupt is triggered.
* Low polarity: active on low level, the default is high level, which turns to low level when the interrupt is triggered.
* @param modes
* LOW_THRESHOLD_INTERRUPT // Low threshold interrupt mode
* HIGH_THRESHOLD_INTERRUPT // High threshold interrupt mode
* @param channelX
* INTERRUPT_X_ENABLE // Enable high threshold interrupt at x-axis
* INTERRUPT_X_DISABLE // Disable high threshold interrupt at x-axis
* @param channelY
* INTERRUPT_Y_ENABLE // Enable high threshold interrupt at y-axis
* INTERRUPT_Y_DISABLE // Disable high threshold interrupt at y-axis
* @param channelZ
* INTERRUPT_Z_ENABLE // Enable high threshold interrupt at z-axis
* INTERRUPT_Z_DISABLE // Disable high threshold interrupt at z-axis
* @param threshold
* Threshold, default to expand 16 times, for example: if the threshold is set to be 1, actually the geomagnetic data below 16 will trigger an interrupt
* @param polarity
* POLARITY_HIGH // High polarity
* POLARITY_LOW // Low polarity
*/
void setThresholdInterrupt(uint8_t modes, uint8_t channelX, uint8_t channelY, uint8_t channelZ, int8_t threshold, uint8_t polarity);
/*!
* @brief Get the data when threshold interrupt occurred
* @return Returns the structure for storing geomagnetic data, the structure stores the data of 3 axis and interrupt status,
* The interrupt is not triggered when the data at x-axis, y-axis and z-axis are NO_DATA
* String state The storage state is binary data string
* uint8_t value The storage state is binary raw value, the data format are as follows:
* bit0 is 1 Indicate the interrupt occur at x-axis
* bit1 is 1 Indicate the interrupt occur at y-axis
* bit2 is 1 Indicate the interrupt occur at z-axis
* ------------------------------------
* | bit7 ~ bit3 | bit2 | bit1 | bit0 |
* ------------------------------------
* | reserved | 0 | 0 | 0 |
* ------------------------------------
*/
sThresholdData getThresholdData(void);
/*!
* @brief The sensor self test, the returned value indicate the self test result.
*
* @param mode:
* BMM150_SELF_TEST_NORMAL // Normal self test, test whether x-axis, y-axis and z-axis are connected or short-circuited
* BMM150_SELF_TEST_ADVANCED // Advanced self test, test the data accuracy at z-axis
*
* @return result The returned character string is the self test result
*/
String selfTest(uint8_t testMode);
Was this article helpful?
