STM32F479xx 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) 2016 STMicroelectronics. 00032 * All rights reserved.</center></h2> 00033 * 00034 * This software component is licensed by ST under BSD 3-Clause license, 00035 * the "License"; You may not use this file except in compliance with the 00036 * License. You may obtain a copy of the License at: 00037 * opensource.org/licenses/BSD-3-Clause 00038 * 00039 ****************************************************************************** 00040 */ 00041 00042 /* Includes ------------------------------------------------------------------*/ 00043 #include "stm32f4xx_hal.h" 00044 00045 /** @addtogroup STM32F4xx_HAL_Driver 00046 * @{ 00047 */ 00048 00049 /** @defgroup I2CEx I2CEx 00050 * @brief I2C HAL module driver 00051 * @{ 00052 */ 00053 00054 #ifdef HAL_I2C_MODULE_ENABLED 00055 00056 #if defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF) 00057 /* Private typedef -----------------------------------------------------------*/ 00058 /* Private define ------------------------------------------------------------*/ 00059 /* Private macro -------------------------------------------------------------*/ 00060 /* Private variables ---------------------------------------------------------*/ 00061 /* Private function prototypes -----------------------------------------------*/ 00062 /* Exported functions --------------------------------------------------------*/ 00063 /** @defgroup I2CEx_Exported_Functions I2C Exported Functions 00064 * @{ 00065 */ 00066 00067 00068 /** @defgroup I2CEx_Exported_Functions_Group1 Extension features functions 00069 * @brief Extension features functions 00070 * 00071 @verbatim 00072 =============================================================================== 00073 ##### Extension features functions ##### 00074 =============================================================================== 00075 [..] This section provides functions allowing to: 00076 (+) Configure Noise Filters 00077 00078 @endverbatim 00079 * @{ 00080 */ 00081 00082 /** 00083 * @brief Configures I2C Analog noise filter. 00084 * @param hi2c pointer to a I2C_HandleTypeDef structure that contains 00085 * the configuration information for the specified I2Cx peripheral. 00086 * @param AnalogFilter new state of the Analog filter. 00087 * @retval HAL status 00088 */ 00089 HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter) 00090 { 00091 /* Check the parameters */ 00092 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); 00093 assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter)); 00094 00095 if (hi2c->State == HAL_I2C_STATE_READY) 00096 { 00097 hi2c->State = HAL_I2C_STATE_BUSY; 00098 00099 /* Disable the selected I2C peripheral */ 00100 __HAL_I2C_DISABLE(hi2c); 00101 00102 /* Reset I2Cx ANOFF bit */ 00103 hi2c->Instance->FLTR &= ~(I2C_FLTR_ANOFF); 00104 00105 /* Disable the analog filter */ 00106 hi2c->Instance->FLTR |= AnalogFilter; 00107 00108 __HAL_I2C_ENABLE(hi2c); 00109 00110 hi2c->State = HAL_I2C_STATE_READY; 00111 00112 return HAL_OK; 00113 } 00114 else 00115 { 00116 return HAL_BUSY; 00117 } 00118 } 00119 00120 /** 00121 * @brief Configures I2C Digital noise filter. 00122 * @param hi2c pointer to a I2C_HandleTypeDef structure that contains 00123 * the configuration information for the specified I2Cx peripheral. 00124 * @param DigitalFilter Coefficient of digital noise filter between 0x00 and 0x0F. 00125 * @retval HAL status 00126 */ 00127 HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter) 00128 { 00129 uint16_t tmpreg = 0; 00130 00131 /* Check the parameters */ 00132 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); 00133 assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter)); 00134 00135 if (hi2c->State == HAL_I2C_STATE_READY) 00136 { 00137 hi2c->State = HAL_I2C_STATE_BUSY; 00138 00139 /* Disable the selected I2C peripheral */ 00140 __HAL_I2C_DISABLE(hi2c); 00141 00142 /* Get the old register value */ 00143 tmpreg = hi2c->Instance->FLTR; 00144 00145 /* Reset I2Cx DNF bit [3:0] */ 00146 tmpreg &= ~(I2C_FLTR_DNF); 00147 00148 /* Set I2Cx DNF coefficient */ 00149 tmpreg |= DigitalFilter; 00150 00151 /* Store the new register value */ 00152 hi2c->Instance->FLTR = tmpreg; 00153 00154 __HAL_I2C_ENABLE(hi2c); 00155 00156 hi2c->State = HAL_I2C_STATE_READY; 00157 00158 return HAL_OK; 00159 } 00160 else 00161 { 00162 return HAL_BUSY; 00163 } 00164 } 00165 00166 /** 00167 * @} 00168 */ 00169 00170 /** 00171 * @} 00172 */ 00173 #endif 00174 00175 #endif /* HAL_I2C_MODULE_ENABLED */ 00176 /** 00177 * @} 00178 */ 00179 00180 /** 00181 * @} 00182 */ 00183 00184 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/