STM32F439xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f4xx_hal_i2c_ex.c 00004 * @author MCD Application Team 00005 * @brief I2C Extension HAL module driver. 00006 * This file provides firmware functions to manage the following 00007 * functionalities of I2C extension peripheral: 00008 * + Extension features functions 00009 * 00010 @verbatim 00011 ============================================================================== 00012 ##### I2C peripheral extension features ##### 00013 ============================================================================== 00014 00015 [..] Comparing to other previous devices, the I2C interface for STM32F427xx/437xx/ 00016 429xx/439xx devices contains the following additional features : 00017 00018 (+) Possibility to disable or enable Analog Noise Filter 00019 (+) Use of a configured Digital Noise Filter 00020 00021 ##### How to use this driver ##### 00022 ============================================================================== 00023 [..] This driver provides functions to configure Noise Filter 00024 (#) Configure I2C Analog noise filter using the function HAL_I2C_AnalogFilter_Config() 00025 (#) Configure I2C Digital noise filter using the function HAL_I2C_DigitalFilter_Config() 00026 00027 @endverbatim 00028 ****************************************************************************** 00029 * @attention 00030 * 00031 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00032 * 00033 * Redistribution and use in source and binary forms, with or without modification, 00034 * are permitted provided that the following conditions are met: 00035 * 1. Redistributions of source code must retain the above copyright notice, 00036 * this list of conditions and the following disclaimer. 00037 * 2. Redistributions in binary form must reproduce the above copyright notice, 00038 * this list of conditions and the following disclaimer in the documentation 00039 * and/or other materials provided with the distribution. 00040 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00041 * may be used to endorse or promote products derived from this software 00042 * without specific prior written permission. 00043 * 00044 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00045 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00046 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00047 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00048 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00049 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00050 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00051 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00052 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00053 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00054 * 00055 ****************************************************************************** 00056 */ 00057 00058 /* Includes ------------------------------------------------------------------*/ 00059 #include "stm32f4xx_hal.h" 00060 00061 /** @addtogroup STM32F4xx_HAL_Driver 00062 * @{ 00063 */ 00064 00065 /** @defgroup I2CEx I2CEx 00066 * @brief I2C HAL module driver 00067 * @{ 00068 */ 00069 00070 #ifdef HAL_I2C_MODULE_ENABLED 00071 00072 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\ 00073 defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F446xx) ||\ 00074 defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F413xx) || defined(STM32F423xx) 00075 /* Private typedef -----------------------------------------------------------*/ 00076 /* Private define ------------------------------------------------------------*/ 00077 /* Private macro -------------------------------------------------------------*/ 00078 /* Private variables ---------------------------------------------------------*/ 00079 /* Private function prototypes -----------------------------------------------*/ 00080 /* Exported functions --------------------------------------------------------*/ 00081 /** @defgroup I2CEx_Exported_Functions I2C Exported Functions 00082 * @{ 00083 */ 00084 00085 00086 /** @defgroup I2CEx_Exported_Functions_Group1 Extension features functions 00087 * @brief Extension features functions 00088 * 00089 @verbatim 00090 =============================================================================== 00091 ##### Extension features functions ##### 00092 =============================================================================== 00093 [..] This section provides functions allowing to: 00094 (+) Configure Noise Filters 00095 00096 @endverbatim 00097 * @{ 00098 */ 00099 00100 /** 00101 * @brief Configures I2C Analog noise filter. 00102 * @param hi2c pointer to a I2C_HandleTypeDef structure that contains 00103 * the configuration information for the specified I2Cx peripheral. 00104 * @param AnalogFilter new state of the Analog filter. 00105 * @retval HAL status 00106 */ 00107 HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter) 00108 { 00109 /* Check the parameters */ 00110 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); 00111 assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter)); 00112 00113 if(hi2c->State == HAL_I2C_STATE_READY) 00114 { 00115 hi2c->State = HAL_I2C_STATE_BUSY; 00116 00117 /* Disable the selected I2C peripheral */ 00118 __HAL_I2C_DISABLE(hi2c); 00119 00120 /* Reset I2Cx ANOFF bit */ 00121 hi2c->Instance->FLTR &= ~(I2C_FLTR_ANOFF); 00122 00123 /* Disable the analog filter */ 00124 hi2c->Instance->FLTR |= AnalogFilter; 00125 00126 __HAL_I2C_ENABLE(hi2c); 00127 00128 hi2c->State = HAL_I2C_STATE_READY; 00129 00130 return HAL_OK; 00131 } 00132 else 00133 { 00134 return HAL_BUSY; 00135 } 00136 } 00137 00138 /** 00139 * @brief Configures I2C Digital noise filter. 00140 * @param hi2c pointer to a I2C_HandleTypeDef structure that contains 00141 * the configuration information for the specified I2Cx peripheral. 00142 * @param DigitalFilter Coefficient of digital noise filter between 0x00 and 0x0F. 00143 * @retval HAL status 00144 */ 00145 HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter) 00146 { 00147 uint16_t tmpreg = 0; 00148 00149 /* Check the parameters */ 00150 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); 00151 assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter)); 00152 00153 if(hi2c->State == HAL_I2C_STATE_READY) 00154 { 00155 hi2c->State = HAL_I2C_STATE_BUSY; 00156 00157 /* Disable the selected I2C peripheral */ 00158 __HAL_I2C_DISABLE(hi2c); 00159 00160 /* Get the old register value */ 00161 tmpreg = hi2c->Instance->FLTR; 00162 00163 /* Reset I2Cx DNF bit [3:0] */ 00164 tmpreg &= ~(I2C_FLTR_DNF); 00165 00166 /* Set I2Cx DNF coefficient */ 00167 tmpreg |= DigitalFilter; 00168 00169 /* Store the new register value */ 00170 hi2c->Instance->FLTR = tmpreg; 00171 00172 __HAL_I2C_ENABLE(hi2c); 00173 00174 hi2c->State = HAL_I2C_STATE_READY; 00175 00176 return HAL_OK; 00177 } 00178 else 00179 { 00180 return HAL_BUSY; 00181 } 00182 } 00183 00184 /** 00185 * @} 00186 */ 00187 00188 /** 00189 * @} 00190 */ 00191 #endif /* STM32F427xx || STM32F429xx || STM32F437xx || STM32F439xx || STM32F401xC ||\ 00192 STM32F401xE || STM32F446xx || STM32F469xx || STM32F479xx || STM32F413xx ||\ 00193 STM32F423xx */ 00194 00195 #endif /* HAL_I2C_MODULE_ENABLED */ 00196 /** 00197 * @} 00198 */ 00199 00200 /** 00201 * @} 00202 */ 00203 00204 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/