Christian Dupaty 03/2021 Library and demo for BMM150 see datasheet here : https://www.bosch-sensortec.com/products/motion-sensors/magnetometers-bmm150/ Adaptation of BOSCH driver https://github.com/BoschSensortec/BMM150-Sensor-API for ARM MBED and tested on NUCLEO-L073RZ and GEOMAGNETIC CLICK https://www.mikroe.com/geomagnetic-click
Dependents: BMM150_HelloWorld2
bmm150.h
00001 /* 00002 Christian Dupaty 03/2021 00003 Library and demo for BMM150 see datasheet here : https://www.bosch-sensortec.com/products/motion-sensors/magnetometers-bmm150/ 00004 Adaptation of BOSCH driver https://github.com/BoschSensortec/BMM150-Sensor-API 00005 for ARM MBED and tested on NUCLEO-L073RZ and GEOMAGNETIC CLICK 00006 https://www.mikroe.com/geomagnetic-click 00007 */ 00008 00009 #ifndef _BMM150_H_ 00010 #define _BMM150_H_ 00011 00012 00013 /** Includes */ 00014 #include "mbed.h" 00015 #include "bmm150_defs.h" 00016 00017 class BMM150 { 00018 00019 public: 00020 BMM150(PinName sda, PinName scl); 00021 /** 00022 \brief initialze device 00023 00024 */ 00025 int8_t initialize(void); 00026 00027 /** 00028 \brief Read magnetometer data 00029 */ 00030 void read_mag_data(); 00031 00032 /** 00033 @brief This internal API is used to obtain the compensated 00034 magnetometer x axis data(micro-tesla) in float. 00035 */ 00036 int16_t compensate_x(int16_t mag_data_z, uint16_t data_rhall); 00037 00038 /** 00039 @brief This internal API is used to obtain the compensated 00040 magnetometer Y axis data(micro-tesla) in int. 00041 */ 00042 int16_t compensate_y(int16_t mag_data_z, uint16_t data_rhall); 00043 00044 /** 00045 @brief This internal API is used to obtain the compensated 00046 magnetometer Z axis data(micro-tesla) in int. 00047 */ 00048 int16_t compensate_z(int16_t mag_data_z, uint16_t data_rhall); 00049 00050 /** 00051 \brief Set power mode 00052 */ 00053 void set_op_mode(uint8_t op_mode); 00054 00055 /** 00056 @brief This internal API reads the trim registers of the sensor and stores 00057 the trim values in the "trim_data" of device structure. 00058 */ 00059 void read_trim_registers(); 00060 00061 /** 00062 @brief This internal API writes the op_mode value in the Opmode bits 00063 (bits 1 and 2) of 0x4C register. 00064 */ 00065 void write_op_mode(uint8_t op_mode); 00066 00067 /** 00068 \brief Set preset mode mode 00069 */ 00070 void set_preset_mode(uint8_t mode); 00071 00072 /** 00073 @brief This internal API sets/resets the power control bit of 0x4B register. 00074 */ 00075 void set_power_control_bit(uint8_t pwrcntrl_bit); 00076 00077 /** 00078 @brief This internal API sets the device from suspend to sleep mode 00079 by setting the power control bit to '1' of 0x4B register 00080 */ 00081 void suspend_to_sleep_mode(); 00082 00083 /** 00084 @brief This API is used to set the preset mode of the sensor. 00085 */ 00086 void set_presetmode(uint8_t preset_mode); 00087 00088 /** 00089 Self test functionality 00090 */ 00091 /* 00092 int8_t perform_self_test(uint8_t self_test_mode); 00093 int8_t perform_normal_self_test(); 00094 void enable_normal_self_test(uint8_t *self_test_enable); 00095 int8_t validate_normal_self_test(); 00096 int8_t perform_adv_self_test(); 00097 void adv_self_test_settings(); 00098 void adv_self_test_measurement(uint8_t self_test_current, int16_t *data_z); 00099 int8_t validate_adv_self_test(int16_t positive_data_z, int16_t negative_data_z); 00100 void set_adv_self_test_current(uint8_t self_test_current); 00101 void set_control_measurement_xyz(struct bmm150_settings settings); 00102 */ 00103 00104 /** 00105 @brief This internal API sets the preset mode ODR and repetition settings. 00106 */ 00107 void set_odr_xyz_rep(struct bmm150_settings settings); 00108 00109 /** 00110 @brief This internal API sets the xy repetition value in the 0x51 register. 00111 */ 00112 void set_xy_rep(struct bmm150_settings settings); 00113 00114 /** 00115 @brief This internal API sets the z repetition value in the 0x52 register. 00116 */ 00117 void set_z_rep(struct bmm150_settings settings); 00118 00119 /** 00120 @brief This internal API is used to set the output data rate of the sensor. 00121 */ 00122 void set_odr(struct bmm150_settings settings); 00123 00124 /** 00125 @brief This API is used to perform soft-reset of the sensor 00126 where all the registers are reset to their default values except 0x4B. 00127 */ 00128 void soft_reset(); 00129 00130 00131 /** 00132 00133 */ 00134 // int8_t* getErrorText(short errorCode); 00135 00136 00137 // protected: 00138 struct bmm150_settings settings; 00139 struct bmm150_raw_mag_data raw_mag_data; 00140 struct bmm150_mag_data mag_data; 00141 struct bmm150_trim_registers trim_data; 00142 00143 00144 void i2c_write(short address, short byte); 00145 void i2c_write(short address) ; 00146 void i2c_read(short address, uint8_t* buffer, short length); 00147 void i2c_read(short address, int8_t* buffer, short length); 00148 uint8_t i2c_read(short address); 00149 00150 private: 00151 I2C *i2c; 00152 00153 }; 00154 00155 00156 #endif
Generated on Sat Jul 16 2022 16:40:58 by 1.7.2