2 ******************************************************************************
3 * @file stm32f0xx_hal_i2c_ex.c
4 * @author MCD Application Team
6 * @date 11-December-2014
7 * @brief I2C Extension HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of I2C extension peripheral:
10 * + Extension features functions
13 ==============================================================================
14 ##### I2C peripheral extension features #####
15 ==============================================================================
17 [..] Comparing to other previous devices, the I2C interface for STM32F0XX
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 "stm32f0xx_hal.h"
67 /** @addtogroup STM32F0xx_HAL_Driver
71 /** @defgroup I2CEx I2CEx 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 I2CEx Exported Functions
89 /** @defgroup I2CEx_Exported_Functions_Group1 Extended features functions
90 * @brief Extended features functions
93 ===============================================================================
94 ##### Extension 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 */
197 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
199 * @brief Enables I2C wakeup from stop mode.
200 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
201 * the configuration information for the specified I2Cx peripheral.
204 HAL_StatusTypeDef
HAL_I2CEx_EnableWakeUp (I2C_HandleTypeDef
*hi2c
)
206 /* Check the parameters */
207 assert_param(IS_I2C_ALL_INSTANCE(hi2c
->Instance
));
209 if((hi2c
->State
== HAL_I2C_STATE_BUSY
) || (hi2c
->State
== HAL_I2C_STATE_MASTER_BUSY_TX
) || (hi2c
->State
== HAL_I2C_STATE_MASTER_BUSY_RX
)
210 || (hi2c
->State
== HAL_I2C_STATE_SLAVE_BUSY_TX
) || (hi2c
->State
== HAL_I2C_STATE_SLAVE_BUSY_RX
))
218 hi2c
->State
= HAL_I2C_STATE_BUSY
;
220 /* Disable the selected I2C peripheral */
221 __HAL_I2C_DISABLE(hi2c
);
223 /* Enable wakeup from stop mode */
224 hi2c
->Instance
->CR1
|= I2C_CR1_WUPEN
;
226 __HAL_I2C_ENABLE(hi2c
);
228 hi2c
->State
= HAL_I2C_STATE_READY
;
230 /* Process Unlocked */
238 * @brief Disables I2C wakeup from stop mode.
239 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
240 * the configuration information for the specified I2Cx peripheral.
243 HAL_StatusTypeDef
HAL_I2CEx_DisableWakeUp (I2C_HandleTypeDef
*hi2c
)
245 /* Check the parameters */
246 assert_param(IS_I2C_ALL_INSTANCE(hi2c
->Instance
));
248 if((hi2c
->State
== HAL_I2C_STATE_BUSY
) || (hi2c
->State
== HAL_I2C_STATE_MASTER_BUSY_TX
) || (hi2c
->State
== HAL_I2C_STATE_MASTER_BUSY_RX
)
249 || (hi2c
->State
== HAL_I2C_STATE_SLAVE_BUSY_TX
) || (hi2c
->State
== HAL_I2C_STATE_SLAVE_BUSY_RX
))
257 hi2c
->State
= HAL_I2C_STATE_BUSY
;
259 /* Disable the selected I2C peripheral */
260 __HAL_I2C_DISABLE(hi2c
);
262 /* Enable wakeup from stop mode */
263 hi2c
->Instance
->CR1
&= ~(I2C_CR1_WUPEN
);
265 __HAL_I2C_ENABLE(hi2c
);
267 hi2c
->State
= HAL_I2C_STATE_READY
;
269 /* Process Unlocked */
274 #endif /* !(STM32F030x6) && !(STM32F030x8) && !(STM32F070x6) && !(STM32F070xB) && !(STM32F030xC) */
283 #endif /* HAL_I2C_MODULE_ENABLED */
292 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/