_BSP_User_Manual
|
stm3210c_eval_accelerometer.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm3210c_eval_accelerometer.c 00004 * @author MCD Application Team 00005 * @version $VERSION$ 00006 * @date $DATE$ 00007 * @brief This file provides a set of functions needed to manage the ACCELEROMETER 00008 * MEMS accelerometer available on STM32F4-Discovery Kit. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© 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 /* Includes ------------------------------------------------------------------*/ 00040 #include "stm3210c_eval_accelerometer.h" 00041 00042 /** @addtogroup BSP 00043 * @{ 00044 */ 00045 00046 /** @addtogroup STM3210C_EVAL 00047 * @{ 00048 */ 00049 00050 /** @addtogroup STM3210C_EVAL_ACCELEROMETER 00051 * @brief This file includes the motion sensor driver for ACCELEROMETER motion sensor 00052 * devices. 00053 * @{ 00054 */ 00055 00056 /** @defgroup STM3210C_EVAL_ACCELEROMETER_Private_TypesDefinitions Private Types Definitions 00057 * @{ 00058 */ 00059 /** 00060 * @} 00061 */ 00062 00063 /** @defgroup STM3210C_EVAL_ACCELEROMETER_Private_Defines Private Defines 00064 * @{ 00065 */ 00066 00067 /** 00068 * @} 00069 */ 00070 00071 /** @defgroup STM3210C_EVAL_ACCELEROMETER_Private_Macros Private Macros 00072 * @{ 00073 */ 00074 00075 /** 00076 * @} 00077 */ 00078 00079 /** @defgroup STM3210C_EVAL_ACCELEROMETER_Private_Variables Private Variables 00080 * @{ 00081 */ 00082 static ACCELERO_DrvTypeDef *AcceleroDrv; 00083 00084 /** 00085 * @} 00086 */ 00087 00088 /** @defgroup STM3210C_EVAL_ACCELEROMETER_Private_FunctionPrototypes Private FunctionPrototypes 00089 * @{ 00090 */ 00091 00092 /** 00093 * @} 00094 */ 00095 00096 /** @defgroup STM3210C_EVAL_ACCELEROMETER_Exported_Functions Exported Functions 00097 * @{ 00098 */ 00099 00100 /** 00101 * @brief Set ACCELEROMETER Initialization. 00102 * @retval None 00103 */ 00104 uint8_t BSP_ACCELERO_Init(void) 00105 { 00106 uint8_t ret = ACCELERO_ERROR; 00107 uint16_t ctrl = 0x0000; 00108 LIS302DL_InitTypeDef lis302dl_initstruct; 00109 LIS302DL_FilterConfigTypeDef lis302dl_filter={0,0,0}; 00110 00111 if(Lis302dlDrv.ReadID() == I_AM_LIS302DL) 00112 { 00113 /* Initialize the gyroscope driver structure */ 00114 AcceleroDrv = &Lis302dlDrv; 00115 00116 /* Set configuration of LIS302DL MEMS Accelerometer *********************/ 00117 lis302dl_initstruct.Power_Mode = LIS302DL_LOWPOWERMODE_ACTIVE; 00118 lis302dl_initstruct.Output_DataRate = LIS302DL_DATARATE_100; 00119 lis302dl_initstruct.Axes_Enable = LIS302DL_XYZ_ENABLE; 00120 lis302dl_initstruct.Full_Scale = LIS302DL_FULLSCALE_2_3; 00121 lis302dl_initstruct.Self_Test = LIS302DL_SELFTEST_NORMAL; 00122 00123 /* Configure MEMS: data rate, power mode, full scale, self test and axes */ 00124 ctrl = (uint16_t) (lis302dl_initstruct.Output_DataRate | lis302dl_initstruct.Power_Mode | \ 00125 lis302dl_initstruct.Full_Scale | lis302dl_initstruct.Self_Test | \ 00126 lis302dl_initstruct.Axes_Enable); 00127 00128 /* Configure the accelerometer main parameters */ 00129 AcceleroDrv->Init(ctrl); 00130 00131 /* MEMS High Pass Filter configuration */ 00132 lis302dl_filter.HighPassFilter_Data_Selection = LIS302DL_FILTEREDDATASELECTION_OUTPUTREGISTER; 00133 lis302dl_filter.HighPassFilter_CutOff_Frequency = LIS302DL_HIGHPASSFILTER_LEVEL_1; 00134 lis302dl_filter.HighPassFilter_Interrupt = LIS302DL_HIGHPASSFILTERINTERRUPT_1_2; 00135 00136 /* Configure MEMS high pass filter cut-off level, interrupt and data selection bits */ 00137 ctrl = (uint8_t)(lis302dl_filter.HighPassFilter_Data_Selection | \ 00138 lis302dl_filter.HighPassFilter_CutOff_Frequency | \ 00139 lis302dl_filter.HighPassFilter_Interrupt); 00140 00141 /* Configure the accelerometer LPF main parameters */ 00142 AcceleroDrv->FilterConfig(ctrl); 00143 00144 ret = ACCELERO_OK; 00145 } 00146 else 00147 { 00148 ret = ACCELERO_ERROR; 00149 } 00150 00151 return ret; 00152 } 00153 00154 /** 00155 * @brief Read ID of Accelerometer component 00156 * @retval ID 00157 */ 00158 uint8_t BSP_ACCELERO_ReadID(void) 00159 { 00160 uint8_t id = 0x00; 00161 00162 if(AcceleroDrv->ReadID != NULL) 00163 { 00164 id = AcceleroDrv->ReadID(); 00165 } 00166 return id; 00167 } 00168 00169 /** 00170 * @brief Reboot memory content of ACCELEROMETER 00171 * @retval None 00172 */ 00173 void BSP_ACCELERO_Reset(void) 00174 { 00175 if(AcceleroDrv->Reset != NULL) 00176 { 00177 AcceleroDrv->Reset(); 00178 } 00179 } 00180 00181 /** 00182 * @brief Config Accelerometer click IT 00183 * @retval None 00184 */ 00185 void BSP_ACCELERO_Click_ITConfig(void) 00186 { 00187 if(AcceleroDrv->ConfigIT!= NULL) 00188 { 00189 AcceleroDrv->ConfigIT(); 00190 } 00191 } 00192 00193 00194 /** 00195 * @brief Clear Accelerometer click IT 00196 * @retval None 00197 */ 00198 void BSP_ACCELERO_Click_ITClear(void) 00199 { 00200 if(AcceleroDrv->ClearIT!= NULL) 00201 { 00202 AcceleroDrv->ClearIT(); 00203 } 00204 } 00205 00206 /** 00207 * @brief Get XYZ acceleration 00208 * @param pDataXYZ: angular acceleration on X/Y/Z axis 00209 * @retval None 00210 */ 00211 void BSP_ACCELERO_GetXYZ(int16_t *pDataXYZ) 00212 { 00213 int16_t SwitchXY = 0; 00214 00215 if(AcceleroDrv->GetXYZ!= NULL) 00216 { 00217 AcceleroDrv->GetXYZ(pDataXYZ); 00218 00219 /* Switch X and Y Axis in case of MEMS LIS302DL */ 00220 if(AcceleroDrv == &Lis302dlDrv) 00221 { 00222 SwitchXY = pDataXYZ[0]; 00223 pDataXYZ[0] = pDataXYZ[1]; 00224 /* Invert Y Axis to be conpliant with LIS3DSH */ 00225 pDataXYZ[1] = -SwitchXY; 00226 } 00227 } 00228 } 00229 00230 00231 /** 00232 * @} 00233 */ 00234 00235 /** 00236 * @} 00237 */ 00238 00239 /** 00240 * @} 00241 */ 00242 00243 /** 00244 * @} 00245 */ 00246 00247 00248 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
Generated on Thu Dec 11 2014 15:38:28 for _BSP_User_Manual by 1.7.5.1