STM32F4xx_HAL_Driver  1.8.3
stm32f4xx_hal_i2c_ex.c
Go to the documentation of this file.
1 
41 /* Includes ------------------------------------------------------------------*/
42 #include "stm32f4xx_hal.h"
43 
53 #ifdef HAL_I2C_MODULE_ENABLED
54 
55 #if defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF)
56 /* Private typedef -----------------------------------------------------------*/
57 /* Private define ------------------------------------------------------------*/
58 /* Private macro -------------------------------------------------------------*/
59 /* Private variables ---------------------------------------------------------*/
60 /* Private function prototypes -----------------------------------------------*/
61 /* Exported functions --------------------------------------------------------*/
88 HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
89 {
90  /* Check the parameters */
91  assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
92  assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));
93 
94  if (hi2c->State == HAL_I2C_STATE_READY)
95  {
96  hi2c->State = HAL_I2C_STATE_BUSY;
97 
98  /* Disable the selected I2C peripheral */
99  __HAL_I2C_DISABLE(hi2c);
100 
101  /* Reset I2Cx ANOFF bit */
102  hi2c->Instance->FLTR &= ~(I2C_FLTR_ANOFF);
103 
104  /* Disable the analog filter */
105  hi2c->Instance->FLTR |= AnalogFilter;
106 
107  __HAL_I2C_ENABLE(hi2c);
108 
109  hi2c->State = HAL_I2C_STATE_READY;
110 
111  return HAL_OK;
112  }
113  else
114  {
115  return HAL_BUSY;
116  }
117 }
118 
126 HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
127 {
128  uint16_t tmpreg = 0;
129 
130  /* Check the parameters */
131  assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
132  assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter));
133 
134  if (hi2c->State == HAL_I2C_STATE_READY)
135  {
136  hi2c->State = HAL_I2C_STATE_BUSY;
137 
138  /* Disable the selected I2C peripheral */
139  __HAL_I2C_DISABLE(hi2c);
140 
141  /* Get the old register value */
142  tmpreg = hi2c->Instance->FLTR;
143 
144  /* Reset I2Cx DNF bit [3:0] */
145  tmpreg &= ~(I2C_FLTR_DNF);
146 
147  /* Set I2Cx DNF coefficient */
148  tmpreg |= DigitalFilter;
149 
150  /* Store the new register value */
151  hi2c->Instance->FLTR = tmpreg;
152 
153  __HAL_I2C_ENABLE(hi2c);
154 
155  hi2c->State = HAL_I2C_STATE_READY;
156 
157  return HAL_OK;
158  }
159  else
160  {
161  return HAL_BUSY;
162  }
163 }
164 
172 #endif
173 
174 #endif /* HAL_I2C_MODULE_ENABLED */
@ HAL_I2C_STATE_BUSY
@ HAL_I2C_STATE_READY
HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
Configures I2C Analog noise filter.
HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
Configures I2C Digital noise filter.
This file contains all the functions prototypes for the HAL module driver.