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@1:9651fd7ee8f6, 2021-03-25 (annotated)
- Committer:
- cdupaty
- Date:
- Thu Mar 25 13:08:05 2021 +0000
- Revision:
- 1:9651fd7ee8f6
- Parent:
- 0:ef20a9039c0c
New I2C functions
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cdupaty | 0:ef20a9039c0c | 1 | /* |
cdupaty | 0:ef20a9039c0c | 2 | Christian Dupaty 03/2021 |
cdupaty | 0:ef20a9039c0c | 3 | Library and demo for BMM150 see datasheet here : https://www.bosch-sensortec.com/products/motion-sensors/magnetometers-bmm150/ |
cdupaty | 0:ef20a9039c0c | 4 | Adaptation of BOSCH driver https://github.com/BoschSensortec/BMM150-Sensor-API |
cdupaty | 0:ef20a9039c0c | 5 | for ARM MBED and tested on NUCLEO-L073RZ and GEOMAGNETIC CLICK |
cdupaty | 0:ef20a9039c0c | 6 | https://www.mikroe.com/geomagnetic-click |
cdupaty | 0:ef20a9039c0c | 7 | */ |
cdupaty | 0:ef20a9039c0c | 8 | |
cdupaty | 0:ef20a9039c0c | 9 | #ifndef _BMM150_H_ |
cdupaty | 0:ef20a9039c0c | 10 | #define _BMM150_H_ |
cdupaty | 0:ef20a9039c0c | 11 | |
cdupaty | 0:ef20a9039c0c | 12 | |
cdupaty | 0:ef20a9039c0c | 13 | /** Includes */ |
cdupaty | 0:ef20a9039c0c | 14 | #include "mbed.h" |
cdupaty | 0:ef20a9039c0c | 15 | #include "bmm150_defs.h" |
cdupaty | 0:ef20a9039c0c | 16 | |
cdupaty | 0:ef20a9039c0c | 17 | class BMM150 { |
cdupaty | 0:ef20a9039c0c | 18 | |
cdupaty | 0:ef20a9039c0c | 19 | public: |
cdupaty | 0:ef20a9039c0c | 20 | BMM150(PinName sda, PinName scl); |
cdupaty | 0:ef20a9039c0c | 21 | /** |
cdupaty | 0:ef20a9039c0c | 22 | \brief initialze device |
cdupaty | 0:ef20a9039c0c | 23 | |
cdupaty | 0:ef20a9039c0c | 24 | */ |
cdupaty | 0:ef20a9039c0c | 25 | int8_t initialize(void); |
cdupaty | 0:ef20a9039c0c | 26 | |
cdupaty | 0:ef20a9039c0c | 27 | /** |
cdupaty | 0:ef20a9039c0c | 28 | \brief Read magnetometer data |
cdupaty | 0:ef20a9039c0c | 29 | */ |
cdupaty | 0:ef20a9039c0c | 30 | void read_mag_data(); |
cdupaty | 0:ef20a9039c0c | 31 | |
cdupaty | 0:ef20a9039c0c | 32 | /** |
cdupaty | 0:ef20a9039c0c | 33 | @brief This internal API is used to obtain the compensated |
cdupaty | 0:ef20a9039c0c | 34 | magnetometer x axis data(micro-tesla) in float. |
cdupaty | 0:ef20a9039c0c | 35 | */ |
cdupaty | 0:ef20a9039c0c | 36 | int16_t compensate_x(int16_t mag_data_z, uint16_t data_rhall); |
cdupaty | 0:ef20a9039c0c | 37 | |
cdupaty | 0:ef20a9039c0c | 38 | /** |
cdupaty | 0:ef20a9039c0c | 39 | @brief This internal API is used to obtain the compensated |
cdupaty | 0:ef20a9039c0c | 40 | magnetometer Y axis data(micro-tesla) in int. |
cdupaty | 0:ef20a9039c0c | 41 | */ |
cdupaty | 0:ef20a9039c0c | 42 | int16_t compensate_y(int16_t mag_data_z, uint16_t data_rhall); |
cdupaty | 0:ef20a9039c0c | 43 | |
cdupaty | 0:ef20a9039c0c | 44 | /** |
cdupaty | 0:ef20a9039c0c | 45 | @brief This internal API is used to obtain the compensated |
cdupaty | 0:ef20a9039c0c | 46 | magnetometer Z axis data(micro-tesla) in int. |
cdupaty | 0:ef20a9039c0c | 47 | */ |
cdupaty | 0:ef20a9039c0c | 48 | int16_t compensate_z(int16_t mag_data_z, uint16_t data_rhall); |
cdupaty | 0:ef20a9039c0c | 49 | |
cdupaty | 0:ef20a9039c0c | 50 | /** |
cdupaty | 0:ef20a9039c0c | 51 | \brief Set power mode |
cdupaty | 0:ef20a9039c0c | 52 | */ |
cdupaty | 0:ef20a9039c0c | 53 | void set_op_mode(uint8_t op_mode); |
cdupaty | 0:ef20a9039c0c | 54 | |
cdupaty | 0:ef20a9039c0c | 55 | /** |
cdupaty | 0:ef20a9039c0c | 56 | @brief This internal API reads the trim registers of the sensor and stores |
cdupaty | 0:ef20a9039c0c | 57 | the trim values in the "trim_data" of device structure. |
cdupaty | 0:ef20a9039c0c | 58 | */ |
cdupaty | 0:ef20a9039c0c | 59 | void read_trim_registers(); |
cdupaty | 0:ef20a9039c0c | 60 | |
cdupaty | 0:ef20a9039c0c | 61 | /** |
cdupaty | 0:ef20a9039c0c | 62 | @brief This internal API writes the op_mode value in the Opmode bits |
cdupaty | 0:ef20a9039c0c | 63 | (bits 1 and 2) of 0x4C register. |
cdupaty | 0:ef20a9039c0c | 64 | */ |
cdupaty | 0:ef20a9039c0c | 65 | void write_op_mode(uint8_t op_mode); |
cdupaty | 0:ef20a9039c0c | 66 | |
cdupaty | 0:ef20a9039c0c | 67 | /** |
cdupaty | 0:ef20a9039c0c | 68 | \brief Set preset mode mode |
cdupaty | 0:ef20a9039c0c | 69 | */ |
cdupaty | 0:ef20a9039c0c | 70 | void set_preset_mode(uint8_t mode); |
cdupaty | 0:ef20a9039c0c | 71 | |
cdupaty | 0:ef20a9039c0c | 72 | /** |
cdupaty | 0:ef20a9039c0c | 73 | @brief This internal API sets/resets the power control bit of 0x4B register. |
cdupaty | 0:ef20a9039c0c | 74 | */ |
cdupaty | 0:ef20a9039c0c | 75 | void set_power_control_bit(uint8_t pwrcntrl_bit); |
cdupaty | 0:ef20a9039c0c | 76 | |
cdupaty | 0:ef20a9039c0c | 77 | /** |
cdupaty | 0:ef20a9039c0c | 78 | @brief This internal API sets the device from suspend to sleep mode |
cdupaty | 0:ef20a9039c0c | 79 | by setting the power control bit to '1' of 0x4B register |
cdupaty | 0:ef20a9039c0c | 80 | */ |
cdupaty | 0:ef20a9039c0c | 81 | void suspend_to_sleep_mode(); |
cdupaty | 0:ef20a9039c0c | 82 | |
cdupaty | 0:ef20a9039c0c | 83 | /** |
cdupaty | 0:ef20a9039c0c | 84 | @brief This API is used to set the preset mode of the sensor. |
cdupaty | 0:ef20a9039c0c | 85 | */ |
cdupaty | 0:ef20a9039c0c | 86 | void set_presetmode(uint8_t preset_mode); |
cdupaty | 0:ef20a9039c0c | 87 | |
cdupaty | 0:ef20a9039c0c | 88 | /** |
cdupaty | 0:ef20a9039c0c | 89 | Self test functionality |
cdupaty | 0:ef20a9039c0c | 90 | */ |
cdupaty | 0:ef20a9039c0c | 91 | /* |
cdupaty | 0:ef20a9039c0c | 92 | int8_t perform_self_test(uint8_t self_test_mode); |
cdupaty | 0:ef20a9039c0c | 93 | int8_t perform_normal_self_test(); |
cdupaty | 0:ef20a9039c0c | 94 | void enable_normal_self_test(uint8_t *self_test_enable); |
cdupaty | 0:ef20a9039c0c | 95 | int8_t validate_normal_self_test(); |
cdupaty | 0:ef20a9039c0c | 96 | int8_t perform_adv_self_test(); |
cdupaty | 0:ef20a9039c0c | 97 | void adv_self_test_settings(); |
cdupaty | 0:ef20a9039c0c | 98 | void adv_self_test_measurement(uint8_t self_test_current, int16_t *data_z); |
cdupaty | 0:ef20a9039c0c | 99 | int8_t validate_adv_self_test(int16_t positive_data_z, int16_t negative_data_z); |
cdupaty | 0:ef20a9039c0c | 100 | void set_adv_self_test_current(uint8_t self_test_current); |
cdupaty | 0:ef20a9039c0c | 101 | void set_control_measurement_xyz(struct bmm150_settings settings); |
cdupaty | 0:ef20a9039c0c | 102 | */ |
cdupaty | 0:ef20a9039c0c | 103 | |
cdupaty | 0:ef20a9039c0c | 104 | /** |
cdupaty | 0:ef20a9039c0c | 105 | @brief This internal API sets the preset mode ODR and repetition settings. |
cdupaty | 0:ef20a9039c0c | 106 | */ |
cdupaty | 0:ef20a9039c0c | 107 | void set_odr_xyz_rep(struct bmm150_settings settings); |
cdupaty | 0:ef20a9039c0c | 108 | |
cdupaty | 0:ef20a9039c0c | 109 | /** |
cdupaty | 0:ef20a9039c0c | 110 | @brief This internal API sets the xy repetition value in the 0x51 register. |
cdupaty | 0:ef20a9039c0c | 111 | */ |
cdupaty | 0:ef20a9039c0c | 112 | void set_xy_rep(struct bmm150_settings settings); |
cdupaty | 0:ef20a9039c0c | 113 | |
cdupaty | 0:ef20a9039c0c | 114 | /** |
cdupaty | 0:ef20a9039c0c | 115 | @brief This internal API sets the z repetition value in the 0x52 register. |
cdupaty | 0:ef20a9039c0c | 116 | */ |
cdupaty | 0:ef20a9039c0c | 117 | void set_z_rep(struct bmm150_settings settings); |
cdupaty | 0:ef20a9039c0c | 118 | |
cdupaty | 0:ef20a9039c0c | 119 | /** |
cdupaty | 0:ef20a9039c0c | 120 | @brief This internal API is used to set the output data rate of the sensor. |
cdupaty | 0:ef20a9039c0c | 121 | */ |
cdupaty | 0:ef20a9039c0c | 122 | void set_odr(struct bmm150_settings settings); |
cdupaty | 0:ef20a9039c0c | 123 | |
cdupaty | 0:ef20a9039c0c | 124 | /** |
cdupaty | 0:ef20a9039c0c | 125 | @brief This API is used to perform soft-reset of the sensor |
cdupaty | 0:ef20a9039c0c | 126 | where all the registers are reset to their default values except 0x4B. |
cdupaty | 0:ef20a9039c0c | 127 | */ |
cdupaty | 0:ef20a9039c0c | 128 | void soft_reset(); |
cdupaty | 0:ef20a9039c0c | 129 | |
cdupaty | 0:ef20a9039c0c | 130 | |
cdupaty | 0:ef20a9039c0c | 131 | /** |
cdupaty | 0:ef20a9039c0c | 132 | |
cdupaty | 0:ef20a9039c0c | 133 | */ |
cdupaty | 0:ef20a9039c0c | 134 | // int8_t* getErrorText(short errorCode); |
cdupaty | 0:ef20a9039c0c | 135 | |
cdupaty | 0:ef20a9039c0c | 136 | |
cdupaty | 0:ef20a9039c0c | 137 | // protected: |
cdupaty | 0:ef20a9039c0c | 138 | struct bmm150_settings settings; |
cdupaty | 0:ef20a9039c0c | 139 | struct bmm150_raw_mag_data raw_mag_data; |
cdupaty | 0:ef20a9039c0c | 140 | struct bmm150_mag_data mag_data; |
cdupaty | 0:ef20a9039c0c | 141 | struct bmm150_trim_registers trim_data; |
cdupaty | 0:ef20a9039c0c | 142 | |
cdupaty | 0:ef20a9039c0c | 143 | |
cdupaty | 0:ef20a9039c0c | 144 | void i2c_write(short address, short byte); |
cdupaty | 1:9651fd7ee8f6 | 145 | void i2c_write(short address) ; |
cdupaty | 0:ef20a9039c0c | 146 | void i2c_read(short address, uint8_t* buffer, short length); |
cdupaty | 0:ef20a9039c0c | 147 | void i2c_read(short address, int8_t* buffer, short length); |
cdupaty | 0:ef20a9039c0c | 148 | uint8_t i2c_read(short address); |
cdupaty | 0:ef20a9039c0c | 149 | |
cdupaty | 0:ef20a9039c0c | 150 | private: |
cdupaty | 0:ef20a9039c0c | 151 | I2C *i2c; |
cdupaty | 0:ef20a9039c0c | 152 | |
cdupaty | 0:ef20a9039c0c | 153 | }; |
cdupaty | 0:ef20a9039c0c | 154 | |
cdupaty | 0:ef20a9039c0c | 155 | |
cdupaty | 0:ef20a9039c0c | 156 | #endif |