Shih-Ho Hsieh / XYZ_sensor_Platform_SPI

Fork of XYZ_sensor_Platform by Shih-Ho Hsieh

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lis3mdl.h Source File

lis3mdl.h

Go to the documentation of this file.
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>&copy; 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 Device Address
00254  */
00255 
00256 #define LIS3MDL_M_MEMS_ADDRESS                              0x3C    // SAD[1] = 1
00257 
00258 /**
00259  * @brief Device Identifier. Default value of the WHO_AM_I register.
00260  */
00261 #define I_AM_LIS3MDL_M                                  ((uint8_t)0x3D)
00262 
00263 /**
00264  * @brief Read Byte. Mask for reading.
00265  */
00266 #define LIS3MDL_SPI_READ_CMD                            ((uint8_t)0x80)
00267 
00268 /**
00269  * @brief Write Byte. Mask for writing.
00270  */
00271 #define LIS3MDL_SPI_WRITE_CMD                           ((uint8_t)0x00)
00272 
00273 /**
00274  * @brief Auto-incremented. Mask for auto-incrementing address in multiple read/write commands.
00275  */
00276 #define LIS3MDL_SPI_AUTO_INC_CMD                        ((uint8_t)0x40)
00277 
00278 /**
00279  * @brief Unchange. Mask for remaining unchanged address in multiple read/write commands.
00280  */
00281 #define LIS3MDL_SPI_UNCHANGE_CMD                        ((uint8_t)0x00)
00282 
00283 
00284 /*********************************** MAGNETIC SENSOR REGISTERS VALUE ****************************************/
00285 
00286 /** @defgroup LIS3MDL_M_Temperature_Compensation_Enable_Selection_CTRL_REG1_M LIS3MDL_M_Temperature_Compensation_Enable_Selection_CTRL_REG1_M
00287  * @{
00288  */
00289 #define LIS3MDL_M_TEMP_COMP_DISABLE                     ((uint8_t)0x00) /*!< Temperature compensation: disable */
00290 #define LIS3MDL_M_TEMP_COMP_ENABLE                      ((uint8_t)0x80) /*!< Temperature compensation: enable */
00291 
00292 #define LIS3MDL_M_TEMP_COMP_MASK                        ((uint8_t)0x80)
00293 /**
00294   * @}
00295   */
00296 
00297 /** @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
00298  * @{
00299  */
00300 #define LIS3MDL_M_OM_LP                                 ((uint8_t)0x00) /*!< X and Y axes operative mode: Low-power mode */
00301 #define LIS3MDL_M_OM_MP                                 ((uint8_t)0x20) /*!< X and Y axes operative mode: Medium-performance mode */
00302 #define LIS3MDL_M_OM_HP                                 ((uint8_t)0x40) /*!< X and Y axes operative mode: High-performance mode */
00303 #define LIS3MDL_M_OM_UHP                                ((uint8_t)0x60) /*!< X and Y axes operative mode: Ultra-high performance mode */
00304 
00305 #define LIS3MDL_M_OM_MASK                               ((uint8_t)0x60)
00306 /**
00307   * @}
00308   */
00309 
00310 /** @defgroup LIS3MDL_M_Output_Data_Rate_Selection_CTRL_REG1_M LIS3MDL_M_Output_Data_Rate_Selection_CTRL_REG1_M
00311  * @{
00312  */
00313 #define LIS3MDL_M_DO_0_625                              ((uint8_t)0x00) /*!< Output data rate selection: 0.625 */
00314 #define LIS3MDL_M_DO_1_25                               ((uint8_t)0x04) /*!< Output data rate selection: 1.25 */
00315 #define LIS3MDL_M_DO_2_5                                ((uint8_t)0x08) /*!< Output data rate selection: 2.5 */
00316 #define LIS3MDL_M_DO_5                                  ((uint8_t)0x0C) /*!< Output data rate selection: 5 */
00317 #define LIS3MDL_M_DO_10                                 ((uint8_t)0x10) /*!< Output data rate selection: 10 */
00318 #define LIS3MDL_M_DO_20                                 ((uint8_t)0x14) /*!< Output data rate selection: 20 */
00319 #define LIS3MDL_M_DO_40                                 ((uint8_t)0x18) /*!< Output data rate selection: 40 */
00320 #define LIS3MDL_M_DO_80                                 ((uint8_t)0x1C) /*!< Output data rate selection: 80 */
00321 
00322 #define LIS3MDL_M_DO_MASK                               ((uint8_t)0x1C)
00323 /**
00324   * @}
00325   */
00326 
00327 /** @defgroup LIS3MDL_M_Fast_Output_Data_Rate_Enable_Selection_CTRL_REG1_M LIS3MDL_M_Fast_Output_Data_Rate_Enable_Selection_CTRL_REG1_M
00328  * @{
00329  */
00330 #define LIS3MDL_M_FAST_ODR_DISABLE                      ((uint8_t)0x00) /*!< Fast output data rate: disable */
00331 #define LIS3MDL_M_FAST_ODR_ENABLE                       ((uint8_t)0x02) /*!< Fast output data rate: enable */
00332 
00333 #define LIS3MDL_M_FAST_ODR_MASK                         ((uint8_t)0x02)
00334 /**
00335   * @}
00336   */
00337 
00338 /** @defgroup LIS3MDL_M_Self_Test_Enable_Selection_CTRL_REG1_M LIS3MDL_M_Self_Test_Enable_Selection_CTRL_REG1_M
00339  * @{
00340  */
00341 #define LIS3MDL_M_ST_DISABLE                            ((uint8_t)0x00) /*!< Self-test: disable */
00342 #define LIS3MDL_M_ST_ENABLE                             ((uint8_t)0x01) /*!< Self-test: enable */
00343 
00344 #define LIS3MDL_M_ST_MASK                               ((uint8_t)0x01)
00345 /**
00346   * @}
00347   */
00348 
00349 /** @defgroup LIS3MDL_M_Full_Scale_Selection_CTRL_REG2_M LIS3MDL_M_Full_Scale_Selection_CTRL_REG2_M
00350  * @{
00351  */
00352 #define LIS3MDL_M_FS_4                                  ((uint8_t)0x00) /*!< Full scale: +-4 guass */
00353 #define LIS3MDL_M_FS_8                                  ((uint8_t)0x20) /*!< Full scale: +-8 gauss */
00354 #define LIS3MDL_M_FS_12                                 ((uint8_t)0x40) /*!< Full scale: +-12 gauss */
00355 #define LIS3MDL_M_FS_16                                 ((uint8_t)0x60) /*!< Full scale: +-16 gauss */
00356 
00357 #define LIS3MDL_M_FS_MASK                               ((uint8_t)0x60)
00358 /**
00359   * @}
00360   */
00361 
00362 /** @defgroup LIS3MDL_M_Reboot_Memory_Selection_CTRL_REG2_M LIS3MDL_M_Reboot_Memory_Selection_CTRL_REG2_M
00363  * @{
00364  */
00365 #define LIS3MDL_M_REBOOT_NORMAL                         ((uint8_t)0x00) /*!< Reboot mode: normal mode */
00366 #define LIS3MDL_M_REBOOT_MEM_CONTENT                    ((uint8_t)0x08) /*!< Reboot mode: reboot memory content */
00367 
00368 #define LIS3MDL_M_REBOOT_MASK                           ((uint8_t)0x08)
00369 /**
00370   * @}
00371   */
00372 
00373 /** @defgroup LIS3MDL_M_Configuration_Registers_And_User_Register_Reset_CTRL_REG2_M LIS3MDL_M_Configuration_Registers_And_User_Register_Reset_CTRL_REG2_M
00374  * @{
00375  */
00376 #define LIS3MDL_M_SOFT_RST_DEFAULT                      ((uint8_t)0x00) /*!< Reset function: default value */
00377 #define LIS3MDL_M_SOFT_RST_RESET                        ((uint8_t)0x04) /*!< Reset function: reset operation */
00378 
00379 #define LIS3MDL_M_SOFT_RST_MASK                         ((uint8_t)0x04)
00380 /**
00381   * @}
00382   */
00383 
00384 /** @defgroup LIS3MDL_M_Disable_I2C_Interface_Selection_CTRL_REG3_M LIS3MDL_M_Disable_I2C_Interface_Selection_CTRL_REG3_M
00385  * @{
00386  */
00387 #define LIS3MDL_M_I2C_ENABLE                            ((uint8_t)0x00) /*!< I2C interface: enable */
00388 #define LIS3MDL_M_I2C_DISABLE                           ((uint8_t)0x80) /*!< I2C interface: disable */
00389 
00390 #define LIS3MDL_M_I2C_MASK                              ((uint8_t)0x80)
00391 /**
00392   * @}
00393   */
00394 
00395 /** @defgroup LIS3MDL_M_Low_Power_Mode_Selection_CTRL_REG3_M LIS3MDL_M_Low_Power_Mode_Selection_CTRL_REG3_M
00396  * @{
00397  */
00398 #define LIS3MDL_M_LP_ENABLE                            ((uint8_t)0x00) /*!< Low-power mode: magnetic data rate is configured by
00399                                                                                             the DO bits in the CTRL_REG1_M */
00400 #define LIS3MDL_M_LP_DISABLE                           ((uint8_t)0x20) /*!< Low-power mode: the DO bits is set to 0.625 Hz and the system performs,
00401                                                                                             for each channel, the minimum number of averages */
00402 
00403 #define LIS3MDL_M_LP_MASK                              ((uint8_t)0x20)
00404 /**
00405   * @}
00406   */
00407 
00408 /** @defgroup LIS3MDL_M_SPI_Serial_Interface_Mode_Selection_CTRL_REG3_M LIS3MDL_M_SPI_Serial_Interface_Mode_Selection_CTRL_REG3_M
00409  * @{
00410  */
00411 #define LIS3MDL_M_SPI_R_ENABLE                          ((uint8_t)0x00) /*!< SPI Serial Interface mode: only write operations enabled */
00412 #define LIS3MDL_M_SPI_R_DISABLE                         ((uint8_t)0x40) /*!< SPI Serial Interface mode: read and write operations enable */
00413 
00414 #define LIS3MDL_M_SPI_R_MASK                            ((uint8_t)0x40)
00415 /**
00416   * @}
00417   */
00418   
00419 
00420 /** @defgroup LIS3MDL_M_Operating_Mode_Selection_CTRL_REG3_M LIS3MDL_M_Operating_Mode_Selection_CTRL_REG3_M
00421  * @{
00422  */
00423 #define LIS3MDL_M_MD_CONTINUOUS                         ((uint8_t)0x00) /*!< Operating mode: Continuous-conversion mode */
00424 #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. */
00425 #define LIS3MDL_M_MD_PD                                 ((uint8_t)0x02) /*!< Operating mode: Power-down mode */
00426 
00427 #define LIS3MDL_M_MD_MASK                               ((uint8_t)0x03)
00428 /**
00429  * @}
00430  */
00431 
00432 /**
00433   * @}
00434   */
00435 
00436 /** @defgroup LIS3MDL_Imported_Functions LIS3MDL_Imported_Functions
00437  * @{
00438  */
00439 
00440 /* Magneto sensor IO functions */
00441 extern MAGNETO_StatusTypeDef LIS3MDL_IO_Init(void);
00442 extern MAGNETO_StatusTypeDef LIS3MDL_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr,
00443     uint16_t NumByteToWrite);
00444 extern MAGNETO_StatusTypeDef LIS3MDL_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr,
00445     uint16_t NumByteToRead);
00446 extern void LIS3MDL_IO_ITConfig( void );
00447 
00448 /**
00449  * @}
00450  */
00451 
00452 /* ------------------------------------------------------- */
00453 /* Here you should declare the internal struct of          */
00454 /* extended features of LSM6DS0. See the example of        */
00455 /* LSM6DS3 in lsm6ds3.h                                    */
00456 /* ------------------------------------------------------- */
00457 
00458 /** @addtogroup LIS3MDL_Exported_Variables LIS3MDL_Exported_Variables
00459  * @{
00460  */
00461 /* Magneto sensor driver structure */
00462 extern MAGNETO_DrvTypeDef LIS3MDLDrv;
00463 extern MAGNETO_DrvExtTypeDef LIS3MDLDrv_ext;
00464 
00465 /**
00466  * @}
00467  */
00468 
00469 /**
00470  * @}
00471  */
00472 
00473 /**
00474  * @}
00475  */
00476 
00477 /**
00478  * @}
00479  */
00480 
00481 #ifdef __cplusplus
00482 }
00483 #endif
00484 
00485 #endif /* __LIS3MDL_H */
00486 
00487 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/