Workshop example
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
lis3mdl.h
00001 /** 00002 ****************************************************************************** 00003 * @file lis3mdl.h 00004 * @author MEMS Application Team 00005 * @version V1.3.0 00006 * @date 28-May-2015 00007 * @brief This file contains definitions for the lis3mdl.c 00008 * firmware driver. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> 00013 * 00014 * Redistribution and use in source and binary forms, with or without modification, 00015 * are permitted provided that the following conditions are met: 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 2. Redistributions in binary form must reproduce the above copyright notice, 00019 * this list of conditions and the following disclaimer in the documentation 00020 * and/or other materials provided with the distribution. 00021 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00022 * may be used to endorse or promote products derived from this software 00023 * without specific prior written permission. 00024 * 00025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00028 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00029 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00030 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00031 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00033 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00034 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 ****************************************************************************** 00037 */ 00038 00039 /* Define to prevent recursive inclusion -------------------------------------*/ 00040 #ifndef __LIS3MDL_H 00041 #define __LIS3MDL_H 00042 00043 #ifdef __cplusplus 00044 extern "C" { 00045 #endif 00046 00047 /* Includes ------------------------------------------------------------------*/ 00048 #include "magneto.h" 00049 00050 /** @addtogroup BSP 00051 * @{ 00052 */ 00053 00054 /** @addtogroup Components 00055 * @{ 00056 */ 00057 00058 /** @addtogroup LIS3MDL 00059 * @{ 00060 */ 00061 00062 /** @defgroup LIS3MDL_Exported_Defines LIS3MDL_Exported_Defines 00063 * @{ 00064 */ 00065 #ifndef NULL 00066 #define NULL (void *) 0 00067 #endif 00068 00069 00070 /******************************************************************************/ 00071 /***************** START MAGNETIC SENSOR REGISTER MAPPING ********************/ 00072 /******************************************************************************/ 00073 00074 /** 00075 * @brief Device identifier register. 00076 * \code 00077 * Read 00078 * Default value: 00079 * 7:0 This read-only register contains the device identifier 00080 * \endcode 00081 */ 00082 #define LIS3MDL_M_WHO_AM_I_ADDR 0x0F 00083 00084 00085 /** 00086 * @brief Magnetic sensor Control Register 1 00087 * \code 00088 * Read/write 00089 * Default value: 0x10 00090 * [7] TEMP_COMP: Temperature compensation enable 00091 * [6:5] OM1-0: X and Y axes operative mode selection 00092 * [4:2] DO2-0: Output data rate selection 00093 * [1] This bit must be set to �0� for the correct operation of the device 00094 * [0] ST: Self-test enable 00095 * \endcode 00096 */ 00097 #define LIS3MDL_M_CTRL_REG1_M 0x20 00098 00099 00100 /** 00101 * @brief Magnetic sensor Control Register 2 00102 * \code 00103 * Read/write 00104 * Default value: 0x00 00105 * [7] These bits must be set to �0� for the correct operation of the device 00106 * [6:5] FS1-0: Full-scale configuration 00107 * [4] These bits must be set to �0� for the correct operation of the device 00108 * [3] REBOOT: Reboot memory content 00109 * [2] SOFT_RST: Configuration registers and user register reset function 00110 * [1:0] These bits must be set to �0� for the correct operation of the device 00111 * \endcode 00112 */ 00113 #define LIS3MDL_M_CTRL_REG2_M 0x21 00114 00115 00116 /** 00117 * @brief Magnetic sensor Control Register 3 00118 * \code 00119 * Read/write 00120 * Default value: 0x03 00121 * [7] I2C_DISABLE: Disable I2C interface 00122 * [6] These bits must be set to �0� for the correct operation of the device 00123 * [5] LP: Low-power mode configuration 00124 * [4:3] These bits must be set to �0� for the correct operation of the device 00125 * [2] SIM: SPI Serial Interface mode selection 00126 * [1:0] MD1-0: Operating mode selection 00127 * \endcode 00128 */ 00129 #define LIS3MDL_M_CTRL_REG3_M 0x22 00130 00131 00132 /** 00133 * @brief Magnetic sensor data (LSB) 00134 * \code 00135 * Read 00136 * \endcode 00137 */ 00138 #define LIS3MDL_M_OUT_X_L_M 0x28 00139 00140 00141 /** 00142 * @brief Magnetic sensor data (MSB) 00143 * \code 00144 * Read 00145 * \endcode 00146 */ 00147 #define LIS3MDL_M_OUT_X_H_M 0x29 00148 00149 00150 /** 00151 * @brief Magnetic sensor data (LSB) 00152 * \code 00153 * Read 00154 * \endcode 00155 */ 00156 #define LIS3MDL_M_OUT_Y_L_M 0x2A 00157 00158 00159 /** 00160 * @brief Magnetic sensor data (MSB) 00161 * \code 00162 * Read 00163 * \endcode 00164 */ 00165 #define LIS3MDL_M_OUT_Y_H_M 0x2B 00166 00167 00168 /** 00169 * @brief Magnetic sensor data (LSB) 00170 * \code 00171 * Read 00172 * \endcode 00173 */ 00174 #define LIS3MDL_M_OUT_Z_L_M 0x2C 00175 00176 00177 /** 00178 * @brief Magnetic sensor data (MSB) 00179 * \code 00180 * Read 00181 * \endcode 00182 */ 00183 #define LIS3MDL_M_OUT_Z_H_M 0x2D 00184 00185 00186 /** 00187 * @brief Magnetic sensor Interrupt config register 00188 * \code 00189 * Read/write 00190 * Default value: 0x00 00191 * [7] XIEN: Enable interrupt generation on X axis 00192 * [6] YIEN: Enable interrupt generation on Y axis 00193 * [5] ZIEN: Enable interrupt generation on Z axis 00194 * [4:3] Must be 0 00195 * [2] IEA: Interrupt active configuration on INT 00196 * [1] LIR: Latch interrupt request 00197 * [0] IEN: Interrupt enable on INT pin 00198 * \endcode 00199 */ 00200 #define LIS3MDL_M_INT_CFG 0x30 00201 00202 00203 /** 00204 * @brief Magnetic sensor Interrupt source register 00205 * \code 00206 * Read/write 00207 * Default value: 0x00 00208 * [7] PTH_X: Value on X-axis exceeds the threshold on the positive side 00209 * [6] PTH_Y: Value on Y-axis exceeds the threshold on the positive side 00210 * [5] PTH_Z: Value on Z-axis exceeds the threshold on the positive side 00211 * [4] NTH_X: Value on X-axis exceeds the threshold on the negative side 00212 * [3] NTH_Y: Value on Y-axis exceeds the threshold on the negative side 00213 * [2] NTH_Z: Value on Z-axis exceeds the threshold on the negative side 00214 * [1] MROI: Internal measurement range overflow on magnetic value 00215 * [0] INT: This bit signals when interrupt event occours 00216 * \endcode 00217 */ 00218 #define LIS3MDL_M_INT_SRC 0x31 00219 00220 00221 /** 00222 * @brief Magnetic sensor Interrupt threshold register low 00223 * \code 00224 * Read/write 00225 * Default value: 0x00 00226 * [7:0] THS7-0: Least 8 significant bits of interrupt threshold 00227 * \endcode 00228 */ 00229 #define LIS3MDL_M_INT_THS_L_M 0x32 00230 00231 00232 /** 00233 * @brief Magnetic sensor Interrupt threshold register high 00234 * \code 00235 * Read/write 00236 * Default value: 0x00 00237 * [7] Must be 0 00238 * [6:0] THS14-8: Most 7 significant bits of interrupt threshold 00239 * \endcode 00240 */ 00241 #define LIS3MDL_M_INT_THS_H_M 0x33 00242 00243 /******************************************************************************/ 00244 /******************* END MAGNETIC SENSOR REGISTER MAPPING ********************/ 00245 /******************************************************************************/ 00246 00247 /** 00248 * @brief Multiple Byte. Mask for enabling multiple byte read/write command. 00249 */ 00250 #define LIS3MDL_I2C_MULTIPLEBYTE_CMD ((uint8_t)0x80) 00251 00252 /** 00253 * @brief I2C Device Address 00254 */ 00255 //#define LIS3MDL_M_MEMS_ADDRESS 0x3C // SAD[1] = 1 00256 #define LIS3MDL_M_MEMS_ADDRESS_LOW 0x38 // SAD[1] = 0 00257 #define LIS3MDL_M_MEMS_ADDRESS_HIGH 0x3C // SAD[1] = 1 00258 00259 /** 00260 * @brief Device Identifier. Default value of the WHO_AM_I register. 00261 */ 00262 #define I_AM_LIS3MDL_M ((uint8_t)0x3D) 00263 00264 00265 /*********************************** MAGNETIC SENSOR REGISTERS VALUE ****************************************/ 00266 00267 /** @defgroup LIS3MDL_M_Temperature_Compensation_Enable_Selection_CTRL_REG1_M LIS3MDL_M_Temperature_Compensation_Enable_Selection_CTRL_REG1_M 00268 * @{ 00269 */ 00270 #define LIS3MDL_M_TEMP_COMP_DISABLE ((uint8_t)0x00) /*!< Temperature compensation: disable */ 00271 #define LIS3MDL_M_TEMP_COMP_ENABLE ((uint8_t)0x80) /*!< Temperature compensation: enable */ 00272 00273 #define LIS3MDL_M_TEMP_COMP_MASK ((uint8_t)0x80) 00274 /** 00275 * @} 00276 */ 00277 00278 /** @defgroup LIS3MDL_M_X_And_Y_Axes_Operative_Mode_Selection_CTRL_REG1_M LIS3MDL_M_X_And_Y_Axes_Operative_Mode_Selection_CTRL_REG1_M 00279 * @{ 00280 */ 00281 #define LIS3MDL_M_OM_LP ((uint8_t)0x00) /*!< X and Y axes operative mode: Low-power mode */ 00282 #define LIS3MDL_M_OM_MP ((uint8_t)0x20) /*!< X and Y axes operative mode: Medium-performance mode */ 00283 #define LIS3MDL_M_OM_HP ((uint8_t)0x40) /*!< X and Y axes operative mode: High-performance mode */ 00284 #define LIS3MDL_M_OM_UHP ((uint8_t)0x60) /*!< X and Y axes operative mode: Ultra-high performance mode */ 00285 00286 #define LIS3MDL_M_OM_MASK ((uint8_t)0x60) 00287 /** 00288 * @} 00289 */ 00290 00291 /** @defgroup LIS3MDL_M_Output_Data_Rate_Selection_CTRL_REG1_M LIS3MDL_M_Output_Data_Rate_Selection_CTRL_REG1_M 00292 * @{ 00293 */ 00294 #define LIS3MDL_M_DO_0_625 ((uint8_t)0x00) /*!< Output data rate selection: 0.625 */ 00295 #define LIS3MDL_M_DO_1_25 ((uint8_t)0x04) /*!< Output data rate selection: 1.25 */ 00296 #define LIS3MDL_M_DO_2_5 ((uint8_t)0x08) /*!< Output data rate selection: 2.5 */ 00297 #define LIS3MDL_M_DO_5 ((uint8_t)0x0C) /*!< Output data rate selection: 5 */ 00298 #define LIS3MDL_M_DO_10 ((uint8_t)0x10) /*!< Output data rate selection: 10 */ 00299 #define LIS3MDL_M_DO_20 ((uint8_t)0x14) /*!< Output data rate selection: 20 */ 00300 #define LIS3MDL_M_DO_40 ((uint8_t)0x18) /*!< Output data rate selection: 40 */ 00301 #define LIS3MDL_M_DO_80 ((uint8_t)0x1C) /*!< Output data rate selection: 80 */ 00302 00303 #define LIS3MDL_M_DO_MASK ((uint8_t)0x1C) 00304 /** 00305 * @} 00306 */ 00307 00308 /** @defgroup LIS3MDL_M_Self_Test_Enable_Selection_CTRL_REG1_M LIS3MDL_M_Self_Test_Enable_Selection_CTRL_REG1_M 00309 * @{ 00310 */ 00311 #define LIS3MDL_M_ST_DISABLE ((uint8_t)0x00) /*!< Self-test: disable */ 00312 #define LIS3MDL_M_ST_ENABLE ((uint8_t)0x01) /*!< Self-test: enable */ 00313 00314 #define LIS3MDL_M_ST_MASK ((uint8_t)0x01) 00315 /** 00316 * @} 00317 */ 00318 00319 /** @defgroup LIS3MDL_M_Full_Scale_Selection_CTRL_REG2_M LIS3MDL_M_Full_Scale_Selection_CTRL_REG2_M 00320 * @{ 00321 */ 00322 #define LIS3MDL_M_FS_4 ((uint8_t)0x00) /*!< Full scale: +-4 guass */ 00323 #define LIS3MDL_M_FS_8 ((uint8_t)0x20) /*!< Full scale: +-8 gauss */ 00324 #define LIS3MDL_M_FS_12 ((uint8_t)0x40) /*!< Full scale: +-12 gauss */ 00325 #define LIS3MDL_M_FS_16 ((uint8_t)0x60) /*!< Full scale: +-16 gauss */ 00326 00327 #define LIS3MDL_M_FS_MASK ((uint8_t)0x60) 00328 /** 00329 * @} 00330 */ 00331 00332 /** @defgroup LIS3MDL_M_Reboot_Memory_Selection_CTRL_REG2_M LIS3MDL_M_Reboot_Memory_Selection_CTRL_REG2_M 00333 * @{ 00334 */ 00335 #define LIS3MDL_M_REBOOT_NORMAL ((uint8_t)0x00) /*!< Reboot mode: normal mode */ 00336 #define LIS3MDL_M_REBOOT_MEM_CONTENT ((uint8_t)0x08) /*!< Reboot mode: reboot memory content */ 00337 00338 #define LIS3MDL_M_REBOOT_MASK ((uint8_t)0x08) 00339 /** 00340 * @} 00341 */ 00342 00343 /** @defgroup LIS3MDL_M_Configuration_Registers_And_User_Register_Reset_CTRL_REG2_M LIS3MDL_M_Configuration_Registers_And_User_Register_Reset_CTRL_REG2_M 00344 * @{ 00345 */ 00346 #define LIS3MDL_M_SOFT_RST_DEFAULT ((uint8_t)0x00) /*!< Reset function: default value */ 00347 #define LIS3MDL_M_SOFT_RST_RESET ((uint8_t)0x04) /*!< Reset function: reset operation */ 00348 00349 #define LIS3MDL_M_SOFT_RST_MASK ((uint8_t)0x04) 00350 /** 00351 * @} 00352 */ 00353 00354 /** @defgroup LIS3MDL_M_Disable_I2C_Interface_Selection_CTRL_REG3_M LIS3MDL_M_Disable_I2C_Interface_Selection_CTRL_REG3_M 00355 * @{ 00356 */ 00357 #define LIS3MDL_M_I2C_ENABLE ((uint8_t)0x00) /*!< I2C interface: enable */ 00358 #define LIS3MDL_M_I2C_DISABLE ((uint8_t)0x80) /*!< I2C interface: disable */ 00359 00360 #define LIS3MDL_M_I2C_MASK ((uint8_t)0x80) 00361 /** 00362 * @} 00363 */ 00364 00365 /** @defgroup LIS3MDL_M_Low_Power_Mode_Selection_CTRL_REG3_M LIS3MDL_M_Low_Power_Mode_Selection_CTRL_REG3_M 00366 * @{ 00367 */ 00368 #define LIS3MDL_M_LP_ENABLE ((uint8_t)0x00) /*!< Low-power mode: magnetic data rate is configured by 00369 the DO bits in the CTRL_REG1_M */ 00370 #define LIS3MDL_M_LP_DISABLE ((uint8_t)0x20) /*!< Low-power mode: the DO bits is set to 0.625 Hz and the system performs, 00371 for each channel, the minimum number of averages */ 00372 00373 #define LIS3MDL_M_LP_MASK ((uint8_t)0x20) 00374 /** 00375 * @} 00376 */ 00377 00378 /** @defgroup LIS3MDL_M_SPI_Serial_Interface_Mode_Selection_CTRL_REG3_M LIS3MDL_M_SPI_Serial_Interface_Mode_Selection_CTRL_REG3_M 00379 * @{ 00380 */ 00381 #define LIS3MDL_M_SPI_R_ENABLE ((uint8_t)0x00) /*!< SPI Serial Interface mode: only write operations enabled */ 00382 #define LIS3MDL_M_SPI_R_DISABLE ((uint8_t)0x40) /*!< SPI Serial Interface mode: read and write operations enable */ 00383 00384 #define LIS3MDL_M_SPI_R_MASK ((uint8_t)0x40) 00385 /** 00386 * @} 00387 */ 00388 00389 /** @defgroup LIS3MDL_M_Operating_Mode_Selection_CTRL_REG3_M LIS3MDL_M_Operating_Mode_Selection_CTRL_REG3_M 00390 * @{ 00391 */ 00392 #define LIS3MDL_M_MD_CONTINUOUS ((uint8_t)0x00) /*!< Operating mode: Continuous-conversion mode */ 00393 #define LIS3MDL_M_MD_SINGLE ((uint8_t)0x01) /*!< Operating mode: Single-conversion mode has to be used with sampling frequency from 0.625 Hz to 80 Hz. */ 00394 #define LIS3MDL_M_MD_PD ((uint8_t)0x02) /*!< Operating mode: Power-down mode */ 00395 00396 #define LIS3MDL_M_MD_MASK ((uint8_t)0x03) 00397 /** 00398 * @} 00399 */ 00400 00401 /** 00402 * @} 00403 */ 00404 00405 /** @defgroup LIS3MDL_Imported_Functions LIS3MDL_Imported_Functions 00406 * @{ 00407 */ 00408 00409 /* Magneto sensor IO functions */ 00410 extern MAGNETO_StatusTypeDef LIS3MDL_IO_Init(void); 00411 extern MAGNETO_StatusTypeDef LIS3MDL_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, 00412 uint16_t NumByteToWrite); 00413 extern MAGNETO_StatusTypeDef LIS3MDL_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, 00414 uint16_t NumByteToRead); 00415 extern void LIS3MDL_IO_ITConfig( void ); 00416 00417 /** 00418 * @} 00419 */ 00420 00421 /* ------------------------------------------------------- */ 00422 /* Here you should declare the internal struct of */ 00423 /* extended features of LSM6DS0. See the example of */ 00424 /* LSM6DS3 in lsm6ds3.h */ 00425 /* ------------------------------------------------------- */ 00426 typedef enum { LIS3MDL_SPI_4_WIRE = (uint8_t)0x00, LIS3MDL_SPI_3_WIRE = (uint8_t)0x04} LIS3MDL_SPIMode_t; 00427 /** @addtogroup LIS3MDL_Exported_Variables LIS3MDL_Exported_Variables 00428 * @{ 00429 */ 00430 /* Magneto sensor driver structure */ 00431 extern MAGNETO_DrvTypeDef LIS3MDLDrv; 00432 extern MAGNETO_DrvExtTypeDef LIS3MDLDrv_ext; 00433 00434 /** 00435 * @} 00436 */ 00437 00438 /** 00439 * @} 00440 */ 00441 00442 /** 00443 * @} 00444 */ 00445 00446 /** 00447 * @} 00448 */ 00449 00450 #ifdef __cplusplus 00451 } 00452 #endif 00453 00454 #endif /* __LIS3MDL_H */ 00455 00456 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 22:34:14 by 1.7.2