2 ******************************************************************************
3 * @file stm32f3xx_hal_i2c_ex.c
4 * @author MCD Application Team
7 * @brief I2C Extended HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of I2C Extended peripheral:
10 * + Extended features functions
13 ==============================================================================
14 ##### I2C peripheral Extended features #####
15 ==============================================================================
17 [..] Comparing to other previous devices, the I2C interface for STM32F3XX
18 devices contains the following additional features
20 (+) Possibility to disable or enable Analog Noise Filter
21 (+) Use of a configured Digital Noise Filter
22 (+) Disable or enable wakeup from Stop mode
24 ##### How to use this driver #####
25 ==============================================================================
26 [..] This driver provides functions to configure Noise Filter
27 (#) Configure I2C Analog noise filter using the function HAL_I2CEx_AnalogFilter_Config()
28 (#) Configure I2C Digital noise filter using the function HAL_I2CEx_DigitalFilter_Config()
29 (#) Configure the enabling or disabling of I2C Wake Up Mode using the functions :
30 + HAL_I2CEx_EnableWakeUp()
31 + HAL_I2CEx_DisableWakeUp()
34 ******************************************************************************
37 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
39 * Redistribution and use in source and binary forms, with or without modification,
40 * are permitted provided that the following conditions are met:
41 * 1. Redistributions of source code must retain the above copyright notice,
42 * this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright notice,
44 * this list of conditions and the following disclaimer in the documentation
45 * and/or other materials provided with the distribution.
46 * 3. Neither the name of STMicroelectronics nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
51 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
53 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
56 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
57 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
58 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 ******************************************************************************
64 /* Includes ------------------------------------------------------------------*/
65 #include "stm32f3xx_hal.h"
67 /** @addtogroup STM32F3xx_HAL_Driver
71 /** @defgroup I2CEx I2C Extended HAL module driver
72 * @brief I2C Extended HAL module driver
76 #ifdef HAL_I2C_MODULE_ENABLED
78 /* Private typedef -----------------------------------------------------------*/
79 /* Private define ------------------------------------------------------------*/
80 /* Private macro -------------------------------------------------------------*/
81 /* Private variables ---------------------------------------------------------*/
82 /* Private function prototypes -----------------------------------------------*/
83 /* Private functions ---------------------------------------------------------*/
85 /** @defgroup I2CEx_Exported_Functions I2C Extended Exported Functions
89 /** @defgroup I2CEx_Exported_Functions_Group1 Extended features functions
90 * @brief Extended features functions
93 ===============================================================================
94 ##### Extended features functions #####
95 ===============================================================================
96 [..] This section provides functions allowing to:
97 (+) Configure Noise Filters
104 * @brief Configures I2C Analog noise filter.
105 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
106 * the configuration information for the specified I2Cx peripheral.
107 * @param AnalogFilter : new state of the Analog filter.
110 HAL_StatusTypeDef HAL_I2CEx_AnalogFilter_Config(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
112 /* Check the parameters */
113 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
114 assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));
116 if((hi2c->State == HAL_I2C_STATE_BUSY) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_RX)
117 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
125 hi2c->State = HAL_I2C_STATE_BUSY;
127 /* Disable the selected I2C peripheral */
128 __HAL_I2C_DISABLE(hi2c);
130 /* Reset I2Cx ANOFF bit */
131 hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF);
133 /* Set analog filter bit*/
134 hi2c->Instance->CR1 |= AnalogFilter;
136 __HAL_I2C_ENABLE(hi2c);
138 hi2c->State = HAL_I2C_STATE_READY;
140 /* Process Unlocked */
147 * @brief Configures I2C Digital noise filter.
148 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
149 * the configuration information for the specified I2Cx peripheral.
150 * @param DigitalFilter : Coefficient of digital noise filter between 0x00 and 0x0F.
153 HAL_StatusTypeDef HAL_I2CEx_DigitalFilter_Config(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
157 /* Check the parameters */
158 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
159 assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter));
161 if((hi2c->State == HAL_I2C_STATE_BUSY) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_RX)
162 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
170 hi2c->State = HAL_I2C_STATE_BUSY;
172 /* Disable the selected I2C peripheral */
173 __HAL_I2C_DISABLE(hi2c);
175 /* Get the old register value */
176 tmpreg = hi2c->Instance->CR1;
178 /* Reset I2Cx DNF bits [11:8] */
179 tmpreg &= ~(I2C_CR1_DFN);
181 /* Set I2Cx DNF coefficient */
182 tmpreg |= DigitalFilter << 8;
184 /* Store the new register value */
185 hi2c->Instance->CR1 = tmpreg;
187 __HAL_I2C_ENABLE(hi2c);
189 hi2c->State = HAL_I2C_STATE_READY;
191 /* Process Unlocked */
198 * @brief Enables I2C wakeup from stop mode.
199 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
200 * the configuration information for the specified I2Cx peripheral.
203 HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp (I2C_HandleTypeDef *hi2c)
205 /* Check the parameters */
206 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
208 if((hi2c->State == HAL_I2C_STATE_BUSY) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_RX)
209 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
217 hi2c->State = HAL_I2C_STATE_BUSY;
219 /* Disable the selected I2C peripheral */
220 __HAL_I2C_DISABLE(hi2c);
222 /* Enable wakeup from stop mode */
223 hi2c->Instance->CR1 |= I2C_CR1_WUPEN;
225 __HAL_I2C_ENABLE(hi2c);
227 hi2c->State = HAL_I2C_STATE_READY;
229 /* Process Unlocked */
237 * @brief Disables I2C wakeup from stop mode.
238 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
239 * the configuration information for the specified I2Cx peripheral.
242 HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp (I2C_HandleTypeDef *hi2c)
244 /* Check the parameters */
245 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
247 if((hi2c->State == HAL_I2C_STATE_BUSY) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_RX)
248 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
256 hi2c->State = HAL_I2C_STATE_BUSY;
258 /* Disable the selected I2C peripheral */
259 __HAL_I2C_DISABLE(hi2c);
261 /* Enable wakeup from stop mode */
262 hi2c->Instance->CR1 &= ~(I2C_CR1_WUPEN);
264 __HAL_I2C_ENABLE(hi2c);
266 hi2c->State = HAL_I2C_STATE_READY;
268 /* Process Unlocked */
282 #endif /* HAL_I2C_MODULE_ENABLED */
291 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/