ble

Dependencies:   HC_SR04_Ultrasonic_Library Servo mbed

Fork of FIP_REV1 by Robotique FIP

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.0.0
00006  * @date    30-July-2014
00007  * @brief   This file contains definitions for the lis3mdl.c 
00008  *          firmware driver.
00009  ******************************************************************************
00010  * @attention
00011  *
00012  * <h2><center>&copy; COPYRIGHT(c) 2014 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 LIS3MDL
00055  * @{
00056  */
00057 
00058 /** @defgroup LIS3MDL_Exported_Constants
00059  * @{
00060  */
00061 
00062 
00063 
00064 /******************************************************************************/
00065 /***************** START MAGNETIC SENSOR REGISTER MAPPING  ********************/
00066 /******************************************************************************/
00067 
00068 /**
00069   * @brief Device identifier register.
00070   * \code
00071   * Read
00072   * Default value:
00073   * 7:0 This read-only register contains the device identifier
00074   * \endcode
00075 */
00076 #define LIS3MDL_M_WHO_AM_I_ADDR                             0x0F
00077 
00078 
00079 /**
00080  * @brief Magnetic sensor Control Register 1
00081  * \code
00082  * Read/write
00083  * Default value: 0x10
00084  * [7] TEMP_COMP: Temperature compensation enable
00085  * [6:5] OM1-0: X and Y axes operative mode selection
00086  * [4:2] DO2-0: Output data rate selection
00087  * [1] This bit must be set to �0� for the correct operation of the device
00088  * [0] ST: Self-test enable
00089  * \endcode
00090  */
00091 #define LIS3MDL_M_CTRL_REG1_M                               0x20
00092 
00093 
00094 /**
00095  * @brief Magnetic sensor Control Register 2
00096  * \code
00097  * Read/write
00098  * Default value: 0x00
00099  * [7] These bits must be set to �0� for the correct operation of the device
00100  * [6:5] FS1-0: Full-scale configuration
00101  * [4] These bits must be set to �0� for the correct operation of the device
00102  * [3] REBOOT: Reboot memory content
00103  * [2] SOFT_RST: Configuration registers and user register reset function
00104  * [1:0] These bits must be set to �0� for the correct operation of the device
00105  * \endcode
00106  */
00107 #define LIS3MDL_M_CTRL_REG2_M                               0x21
00108 
00109 
00110 /**
00111  * @brief Magnetic sensor Control Register 3
00112  * \code
00113  * Read/write
00114  * Default value: 0x03
00115  * [7] I2C_DISABLE: Disable I2C interface
00116  * [6] These bits must be set to �0� for the correct operation of the device
00117  * [5] LP: Low-power mode configuration
00118  * [4:3] These bits must be set to �0� for the correct operation of the device
00119  * [2] SIM: SPI Serial Interface mode selection
00120  * [1:0] MD1-0: Operating mode selection
00121  * \endcode
00122  */
00123 #define LIS3MDL_M_CTRL_REG3_M                               0x22
00124 
00125 
00126 /**
00127  * @brief Magnetic sensor data (LSB)
00128  * \code
00129  * Read
00130  * \endcode
00131  */
00132 #define LIS3MDL_M_OUT_X_L_M                                 0x28
00133 
00134 
00135 /**
00136  * @brief Magnetic sensor data (MSB)
00137  * \code
00138  * Read
00139  * \endcode
00140  */
00141 #define LIS3MDL_M_OUT_X_H_M                                  0x29
00142 
00143 
00144 /**
00145  * @brief Magnetic sensor data (LSB)
00146  * \code
00147  * Read
00148  * \endcode
00149  */
00150 #define LIS3MDL_M_OUT_Y_L_M                                  0x2A
00151 
00152 
00153 /**
00154  * @brief Magnetic sensor data (MSB)
00155  * \code
00156  * Read
00157  * \endcode
00158  */
00159 #define LIS3MDL_M_OUT_Y_H_M                                  0x2B
00160 
00161 
00162 /**
00163  * @brief Magnetic sensor data (LSB)
00164  * \code
00165  * Read
00166  * \endcode
00167  */
00168 #define LIS3MDL_M_OUT_Z_L_M                                  0x2C
00169 
00170 
00171 /**
00172  * @brief Magnetic sensor data (MSB)
00173  * \code
00174  * Read
00175  * \endcode
00176  */
00177 #define LIS3MDL_M_OUT_Z_H_M                                  0x2D
00178 
00179 
00180 /**
00181  * @brief Magnetic sensor Interrupt config register
00182  * \code
00183  * Read/write
00184  * Default value: 0x00
00185  * [7] XIEN: Enable interrupt generation on X axis
00186  * [6] YIEN: Enable interrupt generation on Y axis
00187  * [5] ZIEN: Enable interrupt generation on Z axis
00188  * [4:3] Must be 0
00189  * [2] IEA: Interrupt active configuration on INT
00190  * [1] LIR: Latch interrupt request
00191  * [0] IEN: Interrupt enable on INT pin
00192  * \endcode
00193  */
00194 #define LIS3MDL_M_INT_CFG                                   0x30
00195 
00196 
00197 /**
00198  * @brief Magnetic sensor Interrupt source register
00199  * \code
00200  * Read/write
00201  * Default value: 0x00
00202  * [7] PTH_X: Value on X-axis exceeds the threshold on the positive side
00203  * [6] PTH_Y: Value on Y-axis exceeds the threshold on the positive side
00204  * [5] PTH_Z: Value on Z-axis exceeds the threshold on the positive side
00205  * [4] NTH_X: Value on X-axis exceeds the threshold on the negative side
00206  * [3] NTH_Y: Value on Y-axis exceeds the threshold on the negative side
00207  * [2] NTH_Z: Value on Z-axis exceeds the threshold on the negative side
00208  * [1] MROI: Internal measurement range overflow on magnetic value
00209  * [0] INT: This bit signals when interrupt event occours
00210  * \endcode
00211  */
00212 #define LIS3MDL_M_INT_SRC                                   0x31
00213 
00214 
00215 /**
00216  * @brief Magnetic sensor Interrupt threshold register low
00217  * \code
00218  * Read/write
00219  * Default value: 0x00
00220  * [7:0] THS7-0: Least 8 significant bits of interrupt threshold
00221  * \endcode
00222  */
00223 #define LIS3MDL_M_INT_THS_L_M                               0x32
00224 
00225 
00226 /**
00227  * @brief Magnetic sensor Interrupt threshold register high
00228  * \code
00229  * Read/write
00230  * Default value: 0x00
00231  * [7] Must be 0
00232  * [6:0] THS14-8: Most 7 significant bits of interrupt threshold
00233  * \endcode
00234  */
00235 #define LIS3MDL_M_INT_THS_H_M                               0x33
00236 
00237 /******************************************************************************/
00238 /******************* END MAGNETIC SENSOR REGISTER MAPPING  ********************/
00239 /******************************************************************************/
00240 
00241 
00242 
00243 /**
00244  * @brief Device Address
00245  */
00246 #define LIS3MDL_M_MEMS_ADDRESS                              0x38    // SAD[1] = 0
00247 //#define LIS3MDL_M_MEMS_ADDRESS                              0x3C    // SAD[1] = 1
00248      
00249 /**
00250  * @brief Device Identifier. Default value of the WHO_AM_I register.
00251  */
00252 #define I_AM_LIS3MDL_M                                  ((uint8_t)0x3D)
00253 
00254 
00255 /*********************************** MAGNETIC SENSOR REGISTERS VALUE ****************************************/
00256 
00257 /** @defgroup LIS3MDL_M Temperature compensation enable selection CTRL_REG1_M
00258  * @{
00259  */
00260 #define LIS3MDL_M_TEMP_COMP_DISABLE                     ((uint8_t)0x00) /*!< Temperature compensation: disable */
00261 #define LIS3MDL_M_TEMP_COMP_ENABLE                      ((uint8_t)0x80) /*!< Temperature compensation: enable */
00262 
00263 #define LIS3MDL_M_TEMP_COMP_MASK                        ((uint8_t)0x80)
00264 
00265 
00266 /** @defgroup LIS3MDL_M X and Y axes operative mode selection CTRL_REG1_M
00267  * @{
00268  */
00269 #define LIS3MDL_M_OM_LP                                 ((uint8_t)0x00) /*!< X and Y axes operative mode: Low-power mode */
00270 #define LIS3MDL_M_OM_MP                                 ((uint8_t)0x20) /*!< X and Y axes operative mode: Medium-performance mode */
00271 #define LIS3MDL_M_OM_HP                                 ((uint8_t)0x40) /*!< X and Y axes operative mode: High-performance mode */
00272 #define LIS3MDL_M_OM_UHP                                ((uint8_t)0x60) /*!< X and Y axes operative mode: Ultra-high performance mode */
00273 
00274 #define LIS3MDL_M_OM_MASK                               ((uint8_t)0x60)
00275 
00276 
00277 /** @defgroup LIS3MDL_M Output data rate selection CTRL_REG1_M
00278  * @{
00279  */
00280 #define LIS3MDL_M_DO_0_625                              ((uint8_t)0x00) /*!< Output data rate selection: 0.625 */
00281 #define LIS3MDL_M_DO_1_25                               ((uint8_t)0x04) /*!< Output data rate selection: 1.25 */
00282 #define LIS3MDL_M_DO_2_5                                ((uint8_t)0x08) /*!< Output data rate selection: 2.5 */
00283 #define LIS3MDL_M_DO_5                                  ((uint8_t)0x0C) /*!< Output data rate selection: 5 */
00284 #define LIS3MDL_M_DO_10                                 ((uint8_t)0x10) /*!< Output data rate selection: 10 */
00285 #define LIS3MDL_M_DO_20                                 ((uint8_t)0x14) /*!< Output data rate selection: 20 */
00286 #define LIS3MDL_M_DO_40                                 ((uint8_t)0x18) /*!< Output data rate selection: 40 */
00287 #define LIS3MDL_M_DO_80                                 ((uint8_t)0x1C) /*!< Output data rate selection: 80 */
00288 
00289 #define LIS3MDL_M_DO_MASK                               ((uint8_t)0x1C)
00290 
00291 
00292 /** @defgroup LIS3MDL_M Self-test enable selection CTRL_REG1_M
00293  * @{
00294  */
00295 #define LIS3MDL_M_ST_DISABLE                            ((uint8_t)0x00) /*!< Self-test: disable */
00296 #define LIS3MDL_M_ST_ENABLE                             ((uint8_t)0x01) /*!< Self-test: enable */
00297 
00298 #define LIS3MDL_M_ST_MASK                               ((uint8_t)0x01)
00299 
00300 
00301 /** @defgroup LIS3MDL_M Full scale selection CTRL_REG2_M
00302  * @{
00303  */
00304 #define LIS3MDL_M_FS_4                                  ((uint8_t)0x00) /*!< Full scale: +-4 guass */
00305 #define LIS3MDL_M_FS_8                                  ((uint8_t)0x20) /*!< Full scale: +-8 gauss */
00306 #define LIS3MDL_M_FS_12                                 ((uint8_t)0x40) /*!< Full scale: +-12 gauss */
00307 #define LIS3MDL_M_FS_16                                 ((uint8_t)0x60) /*!< Full scale: +-16 gauss */
00308 
00309 #define LIS3MDL_M_FS_MASK                               ((uint8_t)0x60)
00310 
00311 
00312 /** @defgroup LIS3MDL_M Reboot memory selection CTRL_REG2_M
00313  * @{
00314  */
00315 #define LIS3MDL_M_REBOOT_NORMAL                         ((uint8_t)0x00) /*!< Reboot mode: normal mode */
00316 #define LIS3MDL_M_REBOOT_MEM_CONTENT                    ((uint8_t)0x08) /*!< Reboot mode: reboot memory content */
00317 
00318 #define LIS3MDL_M_REBOOT_MASK                           ((uint8_t)0x08)
00319 
00320 
00321 /** @defgroup LIS3MDL_M Configuration registers and user register reset CTRL_REG2_M
00322  * @{
00323  */
00324 #define LIS3MDL_M_SOFT_RST_DEFAULT                      ((uint8_t)0x00) /*!< Reset function: default value */
00325 #define LIS3MDL_M_SOFT_RST_RESET                        ((uint8_t)0x04) /*!< Reset function: reset operation */
00326 
00327 #define LIS3MDL_M_SOFT_RST_MASK                         ((uint8_t)0x04)
00328 
00329 
00330 /** @defgroup LIS3MDL_M Disable I2C interface selection CTRL_REG3_M
00331  * @{
00332  */
00333 #define LIS3MDL_M_I2C_ENABLE                            ((uint8_t)0x00) /*!< I2C interface: enable */
00334 #define LIS3MDL_M_I2C_DISABLE                           ((uint8_t)0x80) /*!< I2C interface: disable */
00335 
00336 #define LIS3MDL_M_I2C_MASK                              ((uint8_t)0x80)
00337 
00338 
00339 /** @defgroup LIS3MDL_M Low-power mode selection CTRL_REG3_M
00340  * @{
00341  */
00342 #define LIS3MDL_M_LP_ENABLE                            ((uint8_t)0x00) /*!< Low-power mode: magnetic data rate is configured by
00343                                                                                             the DO bits in the CTRL_REG1_M */
00344 #define LIS3MDL_M_LP_DISABLE                           ((uint8_t)0x20) /*!< Low-power mode: the DO bits is set to 0.625 Hz and the system performs,
00345                                                                                             for each channel, the minimum number of averages */
00346 
00347 #define LIS3MDL_M_LP_MASK                              ((uint8_t)0x20)
00348 
00349 
00350 /** @defgroup LIS3MDL_M SPI Serial Interface mode selection CTRL_REG3_M
00351  * @{
00352  */
00353 #define LIS3MDL_M_SPI_R_ENABLE                          ((uint8_t)0x00) /*!< SPI Serial Interface mode: only write operations enabled */
00354 #define LIS3MDL_M_SPI_R_DISABLE                         ((uint8_t)0x40) /*!< SPI Serial Interface mode: read and write operations enable */
00355 
00356 #define LIS3MDL_M_SPI_R_MASK                            ((uint8_t)0x40)
00357 
00358 
00359 /** @defgroup LIS3MDL_M Operating mode selection CTRL_REG3_M
00360  * @{
00361  */
00362 #define LIS3MDL_M_MD_CONTINUOUS                         ((uint8_t)0x00) /*!< Operating mode: Continuous-conversion mode */
00363 #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. */
00364 #define LIS3MDL_M_MD_PD                                 ((uint8_t)0x02) /*!< Operating mode: Power-down mode */
00365 
00366 #define LIS3MDL_M_MD_MASK                               ((uint8_t)0x03)
00367 
00368 /**
00369  * @}
00370  */
00371 
00372     
00373 /** @defgroup LIS3MDL_Imported_Functions
00374  * @{
00375  */
00376 
00377 /* Magneto sensor driver structure */
00378 extern MAGNETO_DrvTypeDef LIS3MDLDrv;
00379 
00380 /* Magneto sensor IO functions */
00381 void MAGNETO_IO_Init(void);
00382 void MAGNETO_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t WriteAddr,
00383                        uint16_t NumByteToWrite);
00384 void MAGNETO_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr,
00385                       uint8_t RegisterAddr, uint16_t NumByteToRead);
00386 
00387 /**
00388  * @}
00389  */
00390 
00391 
00392 /** @defgroup LIS3MDL_Exported_Functions
00393  * @{
00394  */
00395 
00396 /* Sensor Functions */
00397 void LIS3MDL_Init(MAGNETO_InitTypeDef *LIS3MDL_Init);
00398 uint8_t LIS3MDL_Read_M_ID(void);
00399 void LIS3MDL_M_GetAxes(int32_t *pData);
00400 
00401 /**
00402  * @}
00403  */
00404 
00405 /**
00406  * @}
00407  */
00408 
00409 /**
00410  * @}
00411  */
00412 
00413 #ifdef __cplusplus
00414 }
00415 #endif
00416 
00417 #endif /* __LIS3MDL_H */
00418 
00419 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
00420