mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F030R8/stm32f0xx_i2c.c@76:aeb1df146756, 2014-01-27 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Jan 27 14:30:07 2014 +0000
- Revision:
- 76:aeb1df146756
- Child:
- 106:ced8cbb51063
Synchronized with git revision a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd
Full URL: https://github.com/mbedmicro/mbed/commit/a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd/
Add NUCLEO_L152RE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 76:aeb1df146756 | 1 | /** |
mbed_official | 76:aeb1df146756 | 2 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 3 | * @file stm32f0xx_i2c.c |
mbed_official | 76:aeb1df146756 | 4 | * @author MCD Application Team |
mbed_official | 76:aeb1df146756 | 5 | * @version V1.3.0 |
mbed_official | 76:aeb1df146756 | 6 | * @date 16-January-2014 |
mbed_official | 76:aeb1df146756 | 7 | * @brief This file provides firmware functions to manage the following |
mbed_official | 76:aeb1df146756 | 8 | * functionalities of the Inter-Integrated circuit (I2C): |
mbed_official | 76:aeb1df146756 | 9 | * + Initialization and Configuration |
mbed_official | 76:aeb1df146756 | 10 | * + Communications handling |
mbed_official | 76:aeb1df146756 | 11 | * + SMBUS management |
mbed_official | 76:aeb1df146756 | 12 | * + I2C registers management |
mbed_official | 76:aeb1df146756 | 13 | * + Data transfers management |
mbed_official | 76:aeb1df146756 | 14 | * + DMA transfers management |
mbed_official | 76:aeb1df146756 | 15 | * + Interrupts and flags management |
mbed_official | 76:aeb1df146756 | 16 | * |
mbed_official | 76:aeb1df146756 | 17 | * @verbatim |
mbed_official | 76:aeb1df146756 | 18 | ============================================================================ |
mbed_official | 76:aeb1df146756 | 19 | ##### How to use this driver ##### |
mbed_official | 76:aeb1df146756 | 20 | ============================================================================ |
mbed_official | 76:aeb1df146756 | 21 | [..] |
mbed_official | 76:aeb1df146756 | 22 | (#) Enable peripheral clock using RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2Cx, ENABLE) |
mbed_official | 76:aeb1df146756 | 23 | function for I2C1 or I2C2. |
mbed_official | 76:aeb1df146756 | 24 | (#) Enable SDA, SCL and SMBA (when used) GPIO clocks using |
mbed_official | 76:aeb1df146756 | 25 | RCC_AHBPeriphClockCmd() function. |
mbed_official | 76:aeb1df146756 | 26 | (#) Peripherals alternate function: |
mbed_official | 76:aeb1df146756 | 27 | (++) Connect the pin to the desired peripherals' Alternate |
mbed_official | 76:aeb1df146756 | 28 | Function (AF) using GPIO_PinAFConfig() function. |
mbed_official | 76:aeb1df146756 | 29 | (++) Configure the desired pin in alternate function by: |
mbed_official | 76:aeb1df146756 | 30 | GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF |
mbed_official | 76:aeb1df146756 | 31 | (++) Select the type, OpenDrain and speed via |
mbed_official | 76:aeb1df146756 | 32 | GPIO_PuPd, GPIO_OType and GPIO_Speed members |
mbed_official | 76:aeb1df146756 | 33 | (++) Call GPIO_Init() function. |
mbed_official | 76:aeb1df146756 | 34 | (#) Program the Mode, Timing , Own address, Ack and Acknowledged Address |
mbed_official | 76:aeb1df146756 | 35 | using the I2C_Init() function. |
mbed_official | 76:aeb1df146756 | 36 | (#) Optionally you can enable/configure the following parameters without |
mbed_official | 76:aeb1df146756 | 37 | re-initialization (i.e there is no need to call again I2C_Init() function): |
mbed_official | 76:aeb1df146756 | 38 | (++) Enable the acknowledge feature using I2C_AcknowledgeConfig() function. |
mbed_official | 76:aeb1df146756 | 39 | (++) Enable the dual addressing mode using I2C_DualAddressCmd() function. |
mbed_official | 76:aeb1df146756 | 40 | (++) Enable the general call using the I2C_GeneralCallCmd() function. |
mbed_official | 76:aeb1df146756 | 41 | (++) Enable the clock stretching using I2C_StretchClockCmd() function. |
mbed_official | 76:aeb1df146756 | 42 | (++) Enable the PEC Calculation using I2C_CalculatePEC() function. |
mbed_official | 76:aeb1df146756 | 43 | (++) For SMBus Mode: |
mbed_official | 76:aeb1df146756 | 44 | (+++) Enable the SMBusAlert pin using I2C_SMBusAlertCmd() function. |
mbed_official | 76:aeb1df146756 | 45 | (#) Enable the NVIC and the corresponding interrupt using the function |
mbed_official | 76:aeb1df146756 | 46 | I2C_ITConfig() if you need to use interrupt mode. |
mbed_official | 76:aeb1df146756 | 47 | (#) When using the DMA mode |
mbed_official | 76:aeb1df146756 | 48 | (++) Configure the DMA using DMA_Init() function. |
mbed_official | 76:aeb1df146756 | 49 | (++) Active the needed channel Request using I2C_DMACmd() function. |
mbed_official | 76:aeb1df146756 | 50 | (#) Enable the I2C using the I2C_Cmd() function. |
mbed_official | 76:aeb1df146756 | 51 | (#) Enable the DMA using the DMA_Cmd() function when using DMA mode in the |
mbed_official | 76:aeb1df146756 | 52 | transfers. |
mbed_official | 76:aeb1df146756 | 53 | [..] |
mbed_official | 76:aeb1df146756 | 54 | (@) When using I2C in Fast Mode Plus, SCL and SDA pin 20mA current drive capability |
mbed_official | 76:aeb1df146756 | 55 | must be enabled by setting the driving capability control bit in SYSCFG. |
mbed_official | 76:aeb1df146756 | 56 | |
mbed_official | 76:aeb1df146756 | 57 | @endverbatim |
mbed_official | 76:aeb1df146756 | 58 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 59 | * @attention |
mbed_official | 76:aeb1df146756 | 60 | * |
mbed_official | 76:aeb1df146756 | 61 | * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> |
mbed_official | 76:aeb1df146756 | 62 | * |
mbed_official | 76:aeb1df146756 | 63 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
mbed_official | 76:aeb1df146756 | 64 | * You may not use this file except in compliance with the License. |
mbed_official | 76:aeb1df146756 | 65 | * You may obtain a copy of the License at: |
mbed_official | 76:aeb1df146756 | 66 | * |
mbed_official | 76:aeb1df146756 | 67 | * http://www.st.com/software_license_agreement_liberty_v2 |
mbed_official | 76:aeb1df146756 | 68 | * |
mbed_official | 76:aeb1df146756 | 69 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 76:aeb1df146756 | 70 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 76:aeb1df146756 | 71 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 76:aeb1df146756 | 72 | * See the License for the specific language governing permissions and |
mbed_official | 76:aeb1df146756 | 73 | * limitations under the License. |
mbed_official | 76:aeb1df146756 | 74 | * |
mbed_official | 76:aeb1df146756 | 75 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 76 | */ |
mbed_official | 76:aeb1df146756 | 77 | |
mbed_official | 76:aeb1df146756 | 78 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 79 | #include "stm32f0xx_i2c.h" |
mbed_official | 76:aeb1df146756 | 80 | #include "stm32f0xx_rcc.h" |
mbed_official | 76:aeb1df146756 | 81 | |
mbed_official | 76:aeb1df146756 | 82 | /** @addtogroup STM32F0xx_StdPeriph_Driver |
mbed_official | 76:aeb1df146756 | 83 | * @{ |
mbed_official | 76:aeb1df146756 | 84 | */ |
mbed_official | 76:aeb1df146756 | 85 | |
mbed_official | 76:aeb1df146756 | 86 | /** @defgroup I2C |
mbed_official | 76:aeb1df146756 | 87 | * @brief I2C driver modules |
mbed_official | 76:aeb1df146756 | 88 | * @{ |
mbed_official | 76:aeb1df146756 | 89 | */ |
mbed_official | 76:aeb1df146756 | 90 | |
mbed_official | 76:aeb1df146756 | 91 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 92 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 93 | |
mbed_official | 76:aeb1df146756 | 94 | #define CR1_CLEAR_MASK ((uint32_t)0x00CFE0FF) /*<! I2C CR1 clear register Mask */ |
mbed_official | 76:aeb1df146756 | 95 | #define CR2_CLEAR_MASK ((uint32_t)0x07FF7FFF) /*<! I2C CR2 clear register Mask */ |
mbed_official | 76:aeb1df146756 | 96 | #define TIMING_CLEAR_MASK ((uint32_t)0xF0FFFFFF) /*<! I2C TIMING clear register Mask */ |
mbed_official | 76:aeb1df146756 | 97 | #define ERROR_IT_MASK ((uint32_t)0x00003F00) /*<! I2C Error interrupt register Mask */ |
mbed_official | 76:aeb1df146756 | 98 | #define TC_IT_MASK ((uint32_t)0x000000C0) /*<! I2C TC interrupt register Mask */ |
mbed_official | 76:aeb1df146756 | 99 | |
mbed_official | 76:aeb1df146756 | 100 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 101 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 102 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 103 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 104 | |
mbed_official | 76:aeb1df146756 | 105 | /** @defgroup I2C_Private_Functions |
mbed_official | 76:aeb1df146756 | 106 | * @{ |
mbed_official | 76:aeb1df146756 | 107 | */ |
mbed_official | 76:aeb1df146756 | 108 | |
mbed_official | 76:aeb1df146756 | 109 | |
mbed_official | 76:aeb1df146756 | 110 | /** @defgroup I2C_Group1 Initialization and Configuration functions |
mbed_official | 76:aeb1df146756 | 111 | * @brief Initialization and Configuration functions |
mbed_official | 76:aeb1df146756 | 112 | * |
mbed_official | 76:aeb1df146756 | 113 | @verbatim |
mbed_official | 76:aeb1df146756 | 114 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 115 | ##### Initialization and Configuration functions ##### |
mbed_official | 76:aeb1df146756 | 116 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 117 | [..] This section provides a set of functions allowing to initialize the I2C Mode, |
mbed_official | 76:aeb1df146756 | 118 | I2C Timing, I2C filters, I2C Addressing mode, I2C OwnAddress1. |
mbed_official | 76:aeb1df146756 | 119 | |
mbed_official | 76:aeb1df146756 | 120 | [..] The I2C_Init() function follows the I2C configuration procedures (these procedures |
mbed_official | 76:aeb1df146756 | 121 | are available in reference manual). |
mbed_official | 76:aeb1df146756 | 122 | |
mbed_official | 76:aeb1df146756 | 123 | [..] When the Software Reset is performed using I2C_SoftwareResetCmd() function, the internal |
mbed_official | 76:aeb1df146756 | 124 | states machines are reset and communication control bits, as well as status bits come |
mbed_official | 76:aeb1df146756 | 125 | back to their reset value. |
mbed_official | 76:aeb1df146756 | 126 | |
mbed_official | 76:aeb1df146756 | 127 | [..] Before enabling Stop mode using I2C_StopModeCmd() I2C Clock source must be set to |
mbed_official | 76:aeb1df146756 | 128 | HSI and Digital filters must be disabled. |
mbed_official | 76:aeb1df146756 | 129 | |
mbed_official | 76:aeb1df146756 | 130 | [..] Before enabling Own Address 2 via I2C_DualAddressCmd() function, OA2 and mask should be |
mbed_official | 76:aeb1df146756 | 131 | configured using I2C_OwnAddress2Config() function. |
mbed_official | 76:aeb1df146756 | 132 | |
mbed_official | 76:aeb1df146756 | 133 | [..] I2C_SlaveByteControlCmd() enable Slave byte control that allow user to get control of |
mbed_official | 76:aeb1df146756 | 134 | each byte in slave mode when NBYTES is set to 0x01. |
mbed_official | 76:aeb1df146756 | 135 | |
mbed_official | 76:aeb1df146756 | 136 | @endverbatim |
mbed_official | 76:aeb1df146756 | 137 | * @{ |
mbed_official | 76:aeb1df146756 | 138 | */ |
mbed_official | 76:aeb1df146756 | 139 | |
mbed_official | 76:aeb1df146756 | 140 | /** |
mbed_official | 76:aeb1df146756 | 141 | * @brief Deinitializes the I2Cx peripheral registers to their default reset values. |
mbed_official | 76:aeb1df146756 | 142 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 143 | * @retval None |
mbed_official | 76:aeb1df146756 | 144 | */ |
mbed_official | 76:aeb1df146756 | 145 | void I2C_DeInit(I2C_TypeDef* I2Cx) |
mbed_official | 76:aeb1df146756 | 146 | { |
mbed_official | 76:aeb1df146756 | 147 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 148 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 149 | |
mbed_official | 76:aeb1df146756 | 150 | if (I2Cx == I2C1) |
mbed_official | 76:aeb1df146756 | 151 | { |
mbed_official | 76:aeb1df146756 | 152 | /* Enable I2C1 reset state */ |
mbed_official | 76:aeb1df146756 | 153 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE); |
mbed_official | 76:aeb1df146756 | 154 | /* Release I2C1 from reset state */ |
mbed_official | 76:aeb1df146756 | 155 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE); |
mbed_official | 76:aeb1df146756 | 156 | } |
mbed_official | 76:aeb1df146756 | 157 | else |
mbed_official | 76:aeb1df146756 | 158 | { |
mbed_official | 76:aeb1df146756 | 159 | /* Enable I2C2 reset state */ |
mbed_official | 76:aeb1df146756 | 160 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, ENABLE); |
mbed_official | 76:aeb1df146756 | 161 | /* Release I2C2 from reset state */ |
mbed_official | 76:aeb1df146756 | 162 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, DISABLE); |
mbed_official | 76:aeb1df146756 | 163 | } |
mbed_official | 76:aeb1df146756 | 164 | } |
mbed_official | 76:aeb1df146756 | 165 | |
mbed_official | 76:aeb1df146756 | 166 | /** |
mbed_official | 76:aeb1df146756 | 167 | * @brief Initializes the I2Cx peripheral according to the specified |
mbed_official | 76:aeb1df146756 | 168 | * parameters in the I2C_InitStruct. |
mbed_official | 76:aeb1df146756 | 169 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 170 | * @param I2C_InitStruct: pointer to a I2C_InitTypeDef structure that |
mbed_official | 76:aeb1df146756 | 171 | * contains the configuration information for the specified I2C peripheral. |
mbed_official | 76:aeb1df146756 | 172 | * @retval None |
mbed_official | 76:aeb1df146756 | 173 | */ |
mbed_official | 76:aeb1df146756 | 174 | void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct) |
mbed_official | 76:aeb1df146756 | 175 | { |
mbed_official | 76:aeb1df146756 | 176 | uint32_t tmpreg = 0; |
mbed_official | 76:aeb1df146756 | 177 | |
mbed_official | 76:aeb1df146756 | 178 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 179 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 180 | assert_param(IS_I2C_ANALOG_FILTER(I2C_InitStruct->I2C_AnalogFilter)); |
mbed_official | 76:aeb1df146756 | 181 | assert_param(IS_I2C_DIGITAL_FILTER(I2C_InitStruct->I2C_DigitalFilter)); |
mbed_official | 76:aeb1df146756 | 182 | assert_param(IS_I2C_MODE(I2C_InitStruct->I2C_Mode)); |
mbed_official | 76:aeb1df146756 | 183 | assert_param(IS_I2C_OWN_ADDRESS1(I2C_InitStruct->I2C_OwnAddress1)); |
mbed_official | 76:aeb1df146756 | 184 | assert_param(IS_I2C_ACK(I2C_InitStruct->I2C_Ack)); |
mbed_official | 76:aeb1df146756 | 185 | assert_param(IS_I2C_ACKNOWLEDGE_ADDRESS(I2C_InitStruct->I2C_AcknowledgedAddress)); |
mbed_official | 76:aeb1df146756 | 186 | |
mbed_official | 76:aeb1df146756 | 187 | /* Disable I2Cx Peripheral */ |
mbed_official | 76:aeb1df146756 | 188 | I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_PE); |
mbed_official | 76:aeb1df146756 | 189 | |
mbed_official | 76:aeb1df146756 | 190 | /*---------------------------- I2Cx FILTERS Configuration ------------------*/ |
mbed_official | 76:aeb1df146756 | 191 | /* Get the I2Cx CR1 value */ |
mbed_official | 76:aeb1df146756 | 192 | tmpreg = I2Cx->CR1; |
mbed_official | 76:aeb1df146756 | 193 | /* Clear I2Cx CR1 register */ |
mbed_official | 76:aeb1df146756 | 194 | tmpreg &= CR1_CLEAR_MASK; |
mbed_official | 76:aeb1df146756 | 195 | /* Configure I2Cx: analog and digital filter */ |
mbed_official | 76:aeb1df146756 | 196 | /* Set ANFOFF bit according to I2C_AnalogFilter value */ |
mbed_official | 76:aeb1df146756 | 197 | /* Set DFN bits according to I2C_DigitalFilter value */ |
mbed_official | 76:aeb1df146756 | 198 | tmpreg |= (uint32_t)I2C_InitStruct->I2C_AnalogFilter |(I2C_InitStruct->I2C_DigitalFilter << 8); |
mbed_official | 76:aeb1df146756 | 199 | |
mbed_official | 76:aeb1df146756 | 200 | /* Write to I2Cx CR1 */ |
mbed_official | 76:aeb1df146756 | 201 | I2Cx->CR1 = tmpreg; |
mbed_official | 76:aeb1df146756 | 202 | |
mbed_official | 76:aeb1df146756 | 203 | /*---------------------------- I2Cx TIMING Configuration -------------------*/ |
mbed_official | 76:aeb1df146756 | 204 | /* Configure I2Cx: Timing */ |
mbed_official | 76:aeb1df146756 | 205 | /* Set TIMINGR bits according to I2C_Timing */ |
mbed_official | 76:aeb1df146756 | 206 | /* Write to I2Cx TIMING */ |
mbed_official | 76:aeb1df146756 | 207 | I2Cx->TIMINGR = I2C_InitStruct->I2C_Timing & TIMING_CLEAR_MASK; |
mbed_official | 76:aeb1df146756 | 208 | |
mbed_official | 76:aeb1df146756 | 209 | /* Enable I2Cx Peripheral */ |
mbed_official | 76:aeb1df146756 | 210 | I2Cx->CR1 |= I2C_CR1_PE; |
mbed_official | 76:aeb1df146756 | 211 | |
mbed_official | 76:aeb1df146756 | 212 | /*---------------------------- I2Cx OAR1 Configuration ---------------------*/ |
mbed_official | 76:aeb1df146756 | 213 | /* Clear tmpreg local variable */ |
mbed_official | 76:aeb1df146756 | 214 | tmpreg = 0; |
mbed_official | 76:aeb1df146756 | 215 | /* Clear OAR1 register */ |
mbed_official | 76:aeb1df146756 | 216 | I2Cx->OAR1 = (uint32_t)tmpreg; |
mbed_official | 76:aeb1df146756 | 217 | /* Clear OAR2 register */ |
mbed_official | 76:aeb1df146756 | 218 | I2Cx->OAR2 = (uint32_t)tmpreg; |
mbed_official | 76:aeb1df146756 | 219 | /* Configure I2Cx: Own Address1 and acknowledged address */ |
mbed_official | 76:aeb1df146756 | 220 | /* Set OA1MODE bit according to I2C_AcknowledgedAddress value */ |
mbed_official | 76:aeb1df146756 | 221 | /* Set OA1 bits according to I2C_OwnAddress1 value */ |
mbed_official | 76:aeb1df146756 | 222 | tmpreg = (uint32_t)((uint32_t)I2C_InitStruct->I2C_AcknowledgedAddress | \ |
mbed_official | 76:aeb1df146756 | 223 | (uint32_t)I2C_InitStruct->I2C_OwnAddress1); |
mbed_official | 76:aeb1df146756 | 224 | /* Write to I2Cx OAR1 */ |
mbed_official | 76:aeb1df146756 | 225 | I2Cx->OAR1 = tmpreg; |
mbed_official | 76:aeb1df146756 | 226 | /* Enable Own Address1 acknowledgement */ |
mbed_official | 76:aeb1df146756 | 227 | I2Cx->OAR1 |= I2C_OAR1_OA1EN; |
mbed_official | 76:aeb1df146756 | 228 | |
mbed_official | 76:aeb1df146756 | 229 | /*---------------------------- I2Cx MODE Configuration ---------------------*/ |
mbed_official | 76:aeb1df146756 | 230 | /* Configure I2Cx: mode */ |
mbed_official | 76:aeb1df146756 | 231 | /* Set SMBDEN and SMBHEN bits according to I2C_Mode value */ |
mbed_official | 76:aeb1df146756 | 232 | tmpreg = I2C_InitStruct->I2C_Mode; |
mbed_official | 76:aeb1df146756 | 233 | /* Write to I2Cx CR1 */ |
mbed_official | 76:aeb1df146756 | 234 | I2Cx->CR1 |= tmpreg; |
mbed_official | 76:aeb1df146756 | 235 | |
mbed_official | 76:aeb1df146756 | 236 | /*---------------------------- I2Cx ACK Configuration ----------------------*/ |
mbed_official | 76:aeb1df146756 | 237 | /* Get the I2Cx CR2 value */ |
mbed_official | 76:aeb1df146756 | 238 | tmpreg = I2Cx->CR2; |
mbed_official | 76:aeb1df146756 | 239 | /* Clear I2Cx CR2 register */ |
mbed_official | 76:aeb1df146756 | 240 | tmpreg &= CR2_CLEAR_MASK; |
mbed_official | 76:aeb1df146756 | 241 | /* Configure I2Cx: acknowledgement */ |
mbed_official | 76:aeb1df146756 | 242 | /* Set NACK bit according to I2C_Ack value */ |
mbed_official | 76:aeb1df146756 | 243 | tmpreg |= I2C_InitStruct->I2C_Ack; |
mbed_official | 76:aeb1df146756 | 244 | /* Write to I2Cx CR2 */ |
mbed_official | 76:aeb1df146756 | 245 | I2Cx->CR2 = tmpreg; |
mbed_official | 76:aeb1df146756 | 246 | } |
mbed_official | 76:aeb1df146756 | 247 | |
mbed_official | 76:aeb1df146756 | 248 | /** |
mbed_official | 76:aeb1df146756 | 249 | * @brief Fills each I2C_InitStruct member with its default value. |
mbed_official | 76:aeb1df146756 | 250 | * @param I2C_InitStruct: pointer to an I2C_InitTypeDef structure which will be initialized. |
mbed_official | 76:aeb1df146756 | 251 | * @retval None |
mbed_official | 76:aeb1df146756 | 252 | */ |
mbed_official | 76:aeb1df146756 | 253 | void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct) |
mbed_official | 76:aeb1df146756 | 254 | { |
mbed_official | 76:aeb1df146756 | 255 | /*---------------- Reset I2C init structure parameters values --------------*/ |
mbed_official | 76:aeb1df146756 | 256 | /* Initialize the I2C_Timing member */ |
mbed_official | 76:aeb1df146756 | 257 | I2C_InitStruct->I2C_Timing = 0; |
mbed_official | 76:aeb1df146756 | 258 | /* Initialize the I2C_AnalogFilter member */ |
mbed_official | 76:aeb1df146756 | 259 | I2C_InitStruct->I2C_AnalogFilter = I2C_AnalogFilter_Enable; |
mbed_official | 76:aeb1df146756 | 260 | /* Initialize the I2C_DigitalFilter member */ |
mbed_official | 76:aeb1df146756 | 261 | I2C_InitStruct->I2C_DigitalFilter = 0; |
mbed_official | 76:aeb1df146756 | 262 | /* Initialize the I2C_Mode member */ |
mbed_official | 76:aeb1df146756 | 263 | I2C_InitStruct->I2C_Mode = I2C_Mode_I2C; |
mbed_official | 76:aeb1df146756 | 264 | /* Initialize the I2C_OwnAddress1 member */ |
mbed_official | 76:aeb1df146756 | 265 | I2C_InitStruct->I2C_OwnAddress1 = 0; |
mbed_official | 76:aeb1df146756 | 266 | /* Initialize the I2C_Ack member */ |
mbed_official | 76:aeb1df146756 | 267 | I2C_InitStruct->I2C_Ack = I2C_Ack_Disable; |
mbed_official | 76:aeb1df146756 | 268 | /* Initialize the I2C_AcknowledgedAddress member */ |
mbed_official | 76:aeb1df146756 | 269 | I2C_InitStruct->I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; |
mbed_official | 76:aeb1df146756 | 270 | } |
mbed_official | 76:aeb1df146756 | 271 | |
mbed_official | 76:aeb1df146756 | 272 | /** |
mbed_official | 76:aeb1df146756 | 273 | * @brief Enables or disables the specified I2C peripheral. |
mbed_official | 76:aeb1df146756 | 274 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 275 | * @param NewState: new state of the I2Cx peripheral. |
mbed_official | 76:aeb1df146756 | 276 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 277 | * @retval None |
mbed_official | 76:aeb1df146756 | 278 | */ |
mbed_official | 76:aeb1df146756 | 279 | void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 280 | { |
mbed_official | 76:aeb1df146756 | 281 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 282 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 283 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 284 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 285 | { |
mbed_official | 76:aeb1df146756 | 286 | /* Enable the selected I2C peripheral */ |
mbed_official | 76:aeb1df146756 | 287 | I2Cx->CR1 |= I2C_CR1_PE; |
mbed_official | 76:aeb1df146756 | 288 | } |
mbed_official | 76:aeb1df146756 | 289 | else |
mbed_official | 76:aeb1df146756 | 290 | { |
mbed_official | 76:aeb1df146756 | 291 | /* Disable the selected I2C peripheral */ |
mbed_official | 76:aeb1df146756 | 292 | I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_PE); |
mbed_official | 76:aeb1df146756 | 293 | } |
mbed_official | 76:aeb1df146756 | 294 | } |
mbed_official | 76:aeb1df146756 | 295 | |
mbed_official | 76:aeb1df146756 | 296 | /** |
mbed_official | 76:aeb1df146756 | 297 | * @brief Enables or disables the specified I2C software reset. |
mbed_official | 76:aeb1df146756 | 298 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 299 | * @retval None |
mbed_official | 76:aeb1df146756 | 300 | */ |
mbed_official | 76:aeb1df146756 | 301 | void I2C_SoftwareResetCmd(I2C_TypeDef* I2Cx) |
mbed_official | 76:aeb1df146756 | 302 | { |
mbed_official | 76:aeb1df146756 | 303 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 304 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 305 | |
mbed_official | 76:aeb1df146756 | 306 | /* Disable peripheral */ |
mbed_official | 76:aeb1df146756 | 307 | I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_PE); |
mbed_official | 76:aeb1df146756 | 308 | |
mbed_official | 76:aeb1df146756 | 309 | /* Perform a dummy read to delay the disable of peripheral for minimum |
mbed_official | 76:aeb1df146756 | 310 | 3 APB clock cycles to perform the software reset functionality */ |
mbed_official | 76:aeb1df146756 | 311 | *(__IO uint32_t *)(uint32_t)I2Cx; |
mbed_official | 76:aeb1df146756 | 312 | |
mbed_official | 76:aeb1df146756 | 313 | /* Enable peripheral */ |
mbed_official | 76:aeb1df146756 | 314 | I2Cx->CR1 |= I2C_CR1_PE; |
mbed_official | 76:aeb1df146756 | 315 | } |
mbed_official | 76:aeb1df146756 | 316 | |
mbed_official | 76:aeb1df146756 | 317 | /** |
mbed_official | 76:aeb1df146756 | 318 | * @brief Enables or disables the specified I2C interrupts. |
mbed_official | 76:aeb1df146756 | 319 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 320 | * @param I2C_IT: specifies the I2C interrupts sources to be enabled or disabled. |
mbed_official | 76:aeb1df146756 | 321 | * This parameter can be any combination of the following values: |
mbed_official | 76:aeb1df146756 | 322 | * @arg I2C_IT_ERRI: Error interrupt mask |
mbed_official | 76:aeb1df146756 | 323 | * @arg I2C_IT_TCI: Transfer Complete interrupt mask |
mbed_official | 76:aeb1df146756 | 324 | * @arg I2C_IT_STOPI: Stop Detection interrupt mask |
mbed_official | 76:aeb1df146756 | 325 | * @arg I2C_IT_NACKI: Not Acknowledge received interrupt mask |
mbed_official | 76:aeb1df146756 | 326 | * @arg I2C_IT_ADDRI: Address Match interrupt mask |
mbed_official | 76:aeb1df146756 | 327 | * @arg I2C_IT_RXI: RX interrupt mask |
mbed_official | 76:aeb1df146756 | 328 | * @arg I2C_IT_TXI: TX interrupt mask |
mbed_official | 76:aeb1df146756 | 329 | * @param NewState: new state of the specified I2C interrupts. |
mbed_official | 76:aeb1df146756 | 330 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 331 | * @retval None |
mbed_official | 76:aeb1df146756 | 332 | */ |
mbed_official | 76:aeb1df146756 | 333 | void I2C_ITConfig(I2C_TypeDef* I2Cx, uint32_t I2C_IT, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 334 | { |
mbed_official | 76:aeb1df146756 | 335 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 336 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 337 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 338 | assert_param(IS_I2C_CONFIG_IT(I2C_IT)); |
mbed_official | 76:aeb1df146756 | 339 | |
mbed_official | 76:aeb1df146756 | 340 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 341 | { |
mbed_official | 76:aeb1df146756 | 342 | /* Enable the selected I2C interrupts */ |
mbed_official | 76:aeb1df146756 | 343 | I2Cx->CR1 |= I2C_IT; |
mbed_official | 76:aeb1df146756 | 344 | } |
mbed_official | 76:aeb1df146756 | 345 | else |
mbed_official | 76:aeb1df146756 | 346 | { |
mbed_official | 76:aeb1df146756 | 347 | /* Disable the selected I2C interrupts */ |
mbed_official | 76:aeb1df146756 | 348 | I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_IT); |
mbed_official | 76:aeb1df146756 | 349 | } |
mbed_official | 76:aeb1df146756 | 350 | } |
mbed_official | 76:aeb1df146756 | 351 | |
mbed_official | 76:aeb1df146756 | 352 | /** |
mbed_official | 76:aeb1df146756 | 353 | * @brief Enables or disables the I2C Clock stretching. |
mbed_official | 76:aeb1df146756 | 354 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 355 | * @param NewState: new state of the I2Cx Clock stretching. |
mbed_official | 76:aeb1df146756 | 356 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 357 | * @retval None |
mbed_official | 76:aeb1df146756 | 358 | */ |
mbed_official | 76:aeb1df146756 | 359 | void I2C_StretchClockCmd(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 360 | { |
mbed_official | 76:aeb1df146756 | 361 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 362 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 363 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 364 | |
mbed_official | 76:aeb1df146756 | 365 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 366 | { |
mbed_official | 76:aeb1df146756 | 367 | /* Enable clock stretching */ |
mbed_official | 76:aeb1df146756 | 368 | I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_NOSTRETCH); |
mbed_official | 76:aeb1df146756 | 369 | } |
mbed_official | 76:aeb1df146756 | 370 | else |
mbed_official | 76:aeb1df146756 | 371 | { |
mbed_official | 76:aeb1df146756 | 372 | /* Disable clock stretching */ |
mbed_official | 76:aeb1df146756 | 373 | I2Cx->CR1 |= I2C_CR1_NOSTRETCH; |
mbed_official | 76:aeb1df146756 | 374 | } |
mbed_official | 76:aeb1df146756 | 375 | } |
mbed_official | 76:aeb1df146756 | 376 | |
mbed_official | 76:aeb1df146756 | 377 | /** |
mbed_official | 76:aeb1df146756 | 378 | * @brief Enables or disables I2C wakeup from stop mode. |
mbed_official | 76:aeb1df146756 | 379 | * This function is not applicable for STM32F030 devices. |
mbed_official | 76:aeb1df146756 | 380 | * @param I2Cx: where x can be 1 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 381 | * @param NewState: new state of the I2Cx stop mode. |
mbed_official | 76:aeb1df146756 | 382 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 383 | * @retval None |
mbed_official | 76:aeb1df146756 | 384 | */ |
mbed_official | 76:aeb1df146756 | 385 | void I2C_StopModeCmd(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 386 | { |
mbed_official | 76:aeb1df146756 | 387 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 388 | assert_param(IS_I2C_1_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 389 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 390 | |
mbed_official | 76:aeb1df146756 | 391 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 392 | { |
mbed_official | 76:aeb1df146756 | 393 | /* Enable wakeup from stop mode */ |
mbed_official | 76:aeb1df146756 | 394 | I2Cx->CR1 |= I2C_CR1_WUPEN; |
mbed_official | 76:aeb1df146756 | 395 | } |
mbed_official | 76:aeb1df146756 | 396 | else |
mbed_official | 76:aeb1df146756 | 397 | { |
mbed_official | 76:aeb1df146756 | 398 | /* Disable wakeup from stop mode */ |
mbed_official | 76:aeb1df146756 | 399 | I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_WUPEN); |
mbed_official | 76:aeb1df146756 | 400 | } |
mbed_official | 76:aeb1df146756 | 401 | } |
mbed_official | 76:aeb1df146756 | 402 | |
mbed_official | 76:aeb1df146756 | 403 | /** |
mbed_official | 76:aeb1df146756 | 404 | * @brief Enables or disables the I2C own address 2. |
mbed_official | 76:aeb1df146756 | 405 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 406 | * @param NewState: new state of the I2C own address 2. |
mbed_official | 76:aeb1df146756 | 407 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 408 | * @retval None |
mbed_official | 76:aeb1df146756 | 409 | */ |
mbed_official | 76:aeb1df146756 | 410 | void I2C_DualAddressCmd(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 411 | { |
mbed_official | 76:aeb1df146756 | 412 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 413 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 414 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 415 | |
mbed_official | 76:aeb1df146756 | 416 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 417 | { |
mbed_official | 76:aeb1df146756 | 418 | /* Enable own address 2 */ |
mbed_official | 76:aeb1df146756 | 419 | I2Cx->OAR2 |= I2C_OAR2_OA2EN; |
mbed_official | 76:aeb1df146756 | 420 | } |
mbed_official | 76:aeb1df146756 | 421 | else |
mbed_official | 76:aeb1df146756 | 422 | { |
mbed_official | 76:aeb1df146756 | 423 | /* Disable own address 2 */ |
mbed_official | 76:aeb1df146756 | 424 | I2Cx->OAR2 &= (uint32_t)~((uint32_t)I2C_OAR2_OA2EN); |
mbed_official | 76:aeb1df146756 | 425 | } |
mbed_official | 76:aeb1df146756 | 426 | } |
mbed_official | 76:aeb1df146756 | 427 | |
mbed_official | 76:aeb1df146756 | 428 | /** |
mbed_official | 76:aeb1df146756 | 429 | * @brief Configures the I2C slave own address 2 and mask. |
mbed_official | 76:aeb1df146756 | 430 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 431 | * @param Address: specifies the slave address to be programmed. |
mbed_official | 76:aeb1df146756 | 432 | * @param Mask: specifies own address 2 mask to be programmed. |
mbed_official | 76:aeb1df146756 | 433 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 434 | * @arg I2C_OA2_NoMask: no mask. |
mbed_official | 76:aeb1df146756 | 435 | * @arg I2C_OA2_Mask01: OA2[1] is masked and don't care. |
mbed_official | 76:aeb1df146756 | 436 | * @arg I2C_OA2_Mask02: OA2[2:1] are masked and don't care. |
mbed_official | 76:aeb1df146756 | 437 | * @arg I2C_OA2_Mask03: OA2[3:1] are masked and don't care. |
mbed_official | 76:aeb1df146756 | 438 | * @arg I2C_OA2_Mask04: OA2[4:1] are masked and don't care. |
mbed_official | 76:aeb1df146756 | 439 | * @arg I2C_OA2_Mask05: OA2[5:1] are masked and don't care. |
mbed_official | 76:aeb1df146756 | 440 | * @arg I2C_OA2_Mask06: OA2[6:1] are masked and don't care. |
mbed_official | 76:aeb1df146756 | 441 | * @arg I2C_OA2_Mask07: OA2[7:1] are masked and don't care. |
mbed_official | 76:aeb1df146756 | 442 | * @retval None |
mbed_official | 76:aeb1df146756 | 443 | */ |
mbed_official | 76:aeb1df146756 | 444 | void I2C_OwnAddress2Config(I2C_TypeDef* I2Cx, uint16_t Address, uint8_t Mask) |
mbed_official | 76:aeb1df146756 | 445 | { |
mbed_official | 76:aeb1df146756 | 446 | uint32_t tmpreg = 0; |
mbed_official | 76:aeb1df146756 | 447 | |
mbed_official | 76:aeb1df146756 | 448 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 449 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 450 | assert_param(IS_I2C_OWN_ADDRESS2(Address)); |
mbed_official | 76:aeb1df146756 | 451 | assert_param(IS_I2C_OWN_ADDRESS2_MASK(Mask)); |
mbed_official | 76:aeb1df146756 | 452 | |
mbed_official | 76:aeb1df146756 | 453 | /* Get the old register value */ |
mbed_official | 76:aeb1df146756 | 454 | tmpreg = I2Cx->OAR2; |
mbed_official | 76:aeb1df146756 | 455 | |
mbed_official | 76:aeb1df146756 | 456 | /* Reset I2Cx OA2 bit [7:1] and OA2MSK bit [1:0] */ |
mbed_official | 76:aeb1df146756 | 457 | tmpreg &= (uint32_t)~((uint32_t)(I2C_OAR2_OA2 | I2C_OAR2_OA2MSK)); |
mbed_official | 76:aeb1df146756 | 458 | |
mbed_official | 76:aeb1df146756 | 459 | /* Set I2Cx SADD */ |
mbed_official | 76:aeb1df146756 | 460 | tmpreg |= (uint32_t)(((uint32_t)Address & I2C_OAR2_OA2) | \ |
mbed_official | 76:aeb1df146756 | 461 | (((uint32_t)Mask << 8) & I2C_OAR2_OA2MSK)) ; |
mbed_official | 76:aeb1df146756 | 462 | |
mbed_official | 76:aeb1df146756 | 463 | /* Store the new register value */ |
mbed_official | 76:aeb1df146756 | 464 | I2Cx->OAR2 = tmpreg; |
mbed_official | 76:aeb1df146756 | 465 | } |
mbed_official | 76:aeb1df146756 | 466 | |
mbed_official | 76:aeb1df146756 | 467 | /** |
mbed_official | 76:aeb1df146756 | 468 | * @brief Enables or disables the I2C general call mode. |
mbed_official | 76:aeb1df146756 | 469 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 470 | * @param NewState: new state of the I2C general call mode. |
mbed_official | 76:aeb1df146756 | 471 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 472 | * @retval None |
mbed_official | 76:aeb1df146756 | 473 | */ |
mbed_official | 76:aeb1df146756 | 474 | void I2C_GeneralCallCmd(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 475 | { |
mbed_official | 76:aeb1df146756 | 476 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 477 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 478 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 479 | |
mbed_official | 76:aeb1df146756 | 480 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 481 | { |
mbed_official | 76:aeb1df146756 | 482 | /* Enable general call mode */ |
mbed_official | 76:aeb1df146756 | 483 | I2Cx->CR1 |= I2C_CR1_GCEN; |
mbed_official | 76:aeb1df146756 | 484 | } |
mbed_official | 76:aeb1df146756 | 485 | else |
mbed_official | 76:aeb1df146756 | 486 | { |
mbed_official | 76:aeb1df146756 | 487 | /* Disable general call mode */ |
mbed_official | 76:aeb1df146756 | 488 | I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_GCEN); |
mbed_official | 76:aeb1df146756 | 489 | } |
mbed_official | 76:aeb1df146756 | 490 | } |
mbed_official | 76:aeb1df146756 | 491 | |
mbed_official | 76:aeb1df146756 | 492 | /** |
mbed_official | 76:aeb1df146756 | 493 | * @brief Enables or disables the I2C slave byte control. |
mbed_official | 76:aeb1df146756 | 494 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 495 | * @param NewState: new state of the I2C slave byte control. |
mbed_official | 76:aeb1df146756 | 496 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 497 | * @retval None |
mbed_official | 76:aeb1df146756 | 498 | */ |
mbed_official | 76:aeb1df146756 | 499 | void I2C_SlaveByteControlCmd(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 500 | { |
mbed_official | 76:aeb1df146756 | 501 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 502 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 503 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 504 | |
mbed_official | 76:aeb1df146756 | 505 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 506 | { |
mbed_official | 76:aeb1df146756 | 507 | /* Enable slave byte control */ |
mbed_official | 76:aeb1df146756 | 508 | I2Cx->CR1 |= I2C_CR1_SBC; |
mbed_official | 76:aeb1df146756 | 509 | } |
mbed_official | 76:aeb1df146756 | 510 | else |
mbed_official | 76:aeb1df146756 | 511 | { |
mbed_official | 76:aeb1df146756 | 512 | /* Disable slave byte control */ |
mbed_official | 76:aeb1df146756 | 513 | I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_SBC); |
mbed_official | 76:aeb1df146756 | 514 | } |
mbed_official | 76:aeb1df146756 | 515 | } |
mbed_official | 76:aeb1df146756 | 516 | |
mbed_official | 76:aeb1df146756 | 517 | /** |
mbed_official | 76:aeb1df146756 | 518 | * @brief Configures the slave address to be transmitted after start generation. |
mbed_official | 76:aeb1df146756 | 519 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 520 | * @param Address: specifies the slave address to be programmed. |
mbed_official | 76:aeb1df146756 | 521 | * @note This function should be called before generating start condition. |
mbed_official | 76:aeb1df146756 | 522 | * @retval None |
mbed_official | 76:aeb1df146756 | 523 | */ |
mbed_official | 76:aeb1df146756 | 524 | void I2C_SlaveAddressConfig(I2C_TypeDef* I2Cx, uint16_t Address) |
mbed_official | 76:aeb1df146756 | 525 | { |
mbed_official | 76:aeb1df146756 | 526 | uint32_t tmpreg = 0; |
mbed_official | 76:aeb1df146756 | 527 | |
mbed_official | 76:aeb1df146756 | 528 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 529 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 530 | assert_param(IS_I2C_SLAVE_ADDRESS(Address)); |
mbed_official | 76:aeb1df146756 | 531 | |
mbed_official | 76:aeb1df146756 | 532 | /* Get the old register value */ |
mbed_official | 76:aeb1df146756 | 533 | tmpreg = I2Cx->CR2; |
mbed_official | 76:aeb1df146756 | 534 | |
mbed_official | 76:aeb1df146756 | 535 | /* Reset I2Cx SADD bit [9:0] */ |
mbed_official | 76:aeb1df146756 | 536 | tmpreg &= (uint32_t)~((uint32_t)I2C_CR2_SADD); |
mbed_official | 76:aeb1df146756 | 537 | |
mbed_official | 76:aeb1df146756 | 538 | /* Set I2Cx SADD */ |
mbed_official | 76:aeb1df146756 | 539 | tmpreg |= (uint32_t)((uint32_t)Address & I2C_CR2_SADD); |
mbed_official | 76:aeb1df146756 | 540 | |
mbed_official | 76:aeb1df146756 | 541 | /* Store the new register value */ |
mbed_official | 76:aeb1df146756 | 542 | I2Cx->CR2 = tmpreg; |
mbed_official | 76:aeb1df146756 | 543 | } |
mbed_official | 76:aeb1df146756 | 544 | |
mbed_official | 76:aeb1df146756 | 545 | /** |
mbed_official | 76:aeb1df146756 | 546 | * @brief Enables or disables the I2C 10-bit addressing mode for the master. |
mbed_official | 76:aeb1df146756 | 547 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 548 | * @param NewState: new state of the I2C 10-bit addressing mode. |
mbed_official | 76:aeb1df146756 | 549 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 550 | * @note This function should be called before generating start condition. |
mbed_official | 76:aeb1df146756 | 551 | * @retval None |
mbed_official | 76:aeb1df146756 | 552 | */ |
mbed_official | 76:aeb1df146756 | 553 | void I2C_10BitAddressingModeCmd(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 554 | { |
mbed_official | 76:aeb1df146756 | 555 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 556 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 557 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 558 | |
mbed_official | 76:aeb1df146756 | 559 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 560 | { |
mbed_official | 76:aeb1df146756 | 561 | /* Enable 10-bit addressing mode */ |
mbed_official | 76:aeb1df146756 | 562 | I2Cx->CR2 |= I2C_CR2_ADD10; |
mbed_official | 76:aeb1df146756 | 563 | } |
mbed_official | 76:aeb1df146756 | 564 | else |
mbed_official | 76:aeb1df146756 | 565 | { |
mbed_official | 76:aeb1df146756 | 566 | /* Disable 10-bit addressing mode */ |
mbed_official | 76:aeb1df146756 | 567 | I2Cx->CR2 &= (uint32_t)~((uint32_t)I2C_CR2_ADD10); |
mbed_official | 76:aeb1df146756 | 568 | } |
mbed_official | 76:aeb1df146756 | 569 | } |
mbed_official | 76:aeb1df146756 | 570 | |
mbed_official | 76:aeb1df146756 | 571 | /** |
mbed_official | 76:aeb1df146756 | 572 | * @} |
mbed_official | 76:aeb1df146756 | 573 | */ |
mbed_official | 76:aeb1df146756 | 574 | |
mbed_official | 76:aeb1df146756 | 575 | |
mbed_official | 76:aeb1df146756 | 576 | /** @defgroup I2C_Group2 Communications handling functions |
mbed_official | 76:aeb1df146756 | 577 | * @brief Communications handling functions |
mbed_official | 76:aeb1df146756 | 578 | * |
mbed_official | 76:aeb1df146756 | 579 | @verbatim |
mbed_official | 76:aeb1df146756 | 580 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 581 | ##### Communications handling functions ##### |
mbed_official | 76:aeb1df146756 | 582 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 583 | [..] This section provides a set of functions that handles I2C communication. |
mbed_official | 76:aeb1df146756 | 584 | |
mbed_official | 76:aeb1df146756 | 585 | [..] Automatic End mode is enabled using I2C_AutoEndCmd() function. When Reload |
mbed_official | 76:aeb1df146756 | 586 | mode is enabled via I2C_ReloadCmd() AutoEnd bit has no effect. |
mbed_official | 76:aeb1df146756 | 587 | |
mbed_official | 76:aeb1df146756 | 588 | [..] I2C_NumberOfBytesConfig() function set the number of bytes to be transferred, |
mbed_official | 76:aeb1df146756 | 589 | this configuration should be done before generating start condition in master |
mbed_official | 76:aeb1df146756 | 590 | mode. |
mbed_official | 76:aeb1df146756 | 591 | |
mbed_official | 76:aeb1df146756 | 592 | [..] When switching from master write operation to read operation in 10Bit addressing |
mbed_official | 76:aeb1df146756 | 593 | mode, master can only sends the 1st 7 bits of the 10 bit address, followed by |
mbed_official | 76:aeb1df146756 | 594 | Read direction by enabling HEADR bit using I2C_10BitAddressHeader() function. |
mbed_official | 76:aeb1df146756 | 595 | |
mbed_official | 76:aeb1df146756 | 596 | [..] In master mode, when transferring more than 255 bytes Reload mode should be used |
mbed_official | 76:aeb1df146756 | 597 | to handle communication. In the first phase of transfer, Nbytes should be set to |
mbed_official | 76:aeb1df146756 | 598 | 255. After transferring these bytes TCR flag is set and I2C_TransferHandling() |
mbed_official | 76:aeb1df146756 | 599 | function should be called to handle remaining communication. |
mbed_official | 76:aeb1df146756 | 600 | |
mbed_official | 76:aeb1df146756 | 601 | [..] In master mode, when software end mode is selected when all data is transferred |
mbed_official | 76:aeb1df146756 | 602 | TC flag is set I2C_TransferHandling() function should be called to generate STOP |
mbed_official | 76:aeb1df146756 | 603 | or generate ReStart. |
mbed_official | 76:aeb1df146756 | 604 | |
mbed_official | 76:aeb1df146756 | 605 | @endverbatim |
mbed_official | 76:aeb1df146756 | 606 | * @{ |
mbed_official | 76:aeb1df146756 | 607 | */ |
mbed_official | 76:aeb1df146756 | 608 | |
mbed_official | 76:aeb1df146756 | 609 | /** |
mbed_official | 76:aeb1df146756 | 610 | * @brief Enables or disables the I2C automatic end mode (stop condition is |
mbed_official | 76:aeb1df146756 | 611 | * automatically sent when nbytes data are transferred). |
mbed_official | 76:aeb1df146756 | 612 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 613 | * @param NewState: new state of the I2C automatic end mode. |
mbed_official | 76:aeb1df146756 | 614 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 615 | * @note This function has effect if Reload mode is disabled. |
mbed_official | 76:aeb1df146756 | 616 | * @retval None |
mbed_official | 76:aeb1df146756 | 617 | */ |
mbed_official | 76:aeb1df146756 | 618 | void I2C_AutoEndCmd(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 619 | { |
mbed_official | 76:aeb1df146756 | 620 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 621 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 622 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 623 | |
mbed_official | 76:aeb1df146756 | 624 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 625 | { |
mbed_official | 76:aeb1df146756 | 626 | /* Enable Auto end mode */ |
mbed_official | 76:aeb1df146756 | 627 | I2Cx->CR2 |= I2C_CR2_AUTOEND; |
mbed_official | 76:aeb1df146756 | 628 | } |
mbed_official | 76:aeb1df146756 | 629 | else |
mbed_official | 76:aeb1df146756 | 630 | { |
mbed_official | 76:aeb1df146756 | 631 | /* Disable Auto end mode */ |
mbed_official | 76:aeb1df146756 | 632 | I2Cx->CR2 &= (uint32_t)~((uint32_t)I2C_CR2_AUTOEND); |
mbed_official | 76:aeb1df146756 | 633 | } |
mbed_official | 76:aeb1df146756 | 634 | } |
mbed_official | 76:aeb1df146756 | 635 | |
mbed_official | 76:aeb1df146756 | 636 | /** |
mbed_official | 76:aeb1df146756 | 637 | * @brief Enables or disables the I2C nbytes reload mode. |
mbed_official | 76:aeb1df146756 | 638 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 639 | * @param NewState: new state of the nbytes reload mode. |
mbed_official | 76:aeb1df146756 | 640 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 641 | * @retval None |
mbed_official | 76:aeb1df146756 | 642 | */ |
mbed_official | 76:aeb1df146756 | 643 | void I2C_ReloadCmd(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 644 | { |
mbed_official | 76:aeb1df146756 | 645 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 646 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 647 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 648 | |
mbed_official | 76:aeb1df146756 | 649 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 650 | { |
mbed_official | 76:aeb1df146756 | 651 | /* Enable Auto Reload mode */ |
mbed_official | 76:aeb1df146756 | 652 | I2Cx->CR2 |= I2C_CR2_RELOAD; |
mbed_official | 76:aeb1df146756 | 653 | } |
mbed_official | 76:aeb1df146756 | 654 | else |
mbed_official | 76:aeb1df146756 | 655 | { |
mbed_official | 76:aeb1df146756 | 656 | /* Disable Auto Reload mode */ |
mbed_official | 76:aeb1df146756 | 657 | I2Cx->CR2 &= (uint32_t)~((uint32_t)I2C_CR2_RELOAD); |
mbed_official | 76:aeb1df146756 | 658 | } |
mbed_official | 76:aeb1df146756 | 659 | } |
mbed_official | 76:aeb1df146756 | 660 | |
mbed_official | 76:aeb1df146756 | 661 | /** |
mbed_official | 76:aeb1df146756 | 662 | * @brief Configures the number of bytes to be transmitted/received. |
mbed_official | 76:aeb1df146756 | 663 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 664 | * @param Number_Bytes: specifies the number of bytes to be programmed. |
mbed_official | 76:aeb1df146756 | 665 | * @retval None |
mbed_official | 76:aeb1df146756 | 666 | */ |
mbed_official | 76:aeb1df146756 | 667 | void I2C_NumberOfBytesConfig(I2C_TypeDef* I2Cx, uint8_t Number_Bytes) |
mbed_official | 76:aeb1df146756 | 668 | { |
mbed_official | 76:aeb1df146756 | 669 | uint32_t tmpreg = 0; |
mbed_official | 76:aeb1df146756 | 670 | |
mbed_official | 76:aeb1df146756 | 671 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 672 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 673 | |
mbed_official | 76:aeb1df146756 | 674 | /* Get the old register value */ |
mbed_official | 76:aeb1df146756 | 675 | tmpreg = I2Cx->CR2; |
mbed_official | 76:aeb1df146756 | 676 | |
mbed_official | 76:aeb1df146756 | 677 | /* Reset I2Cx Nbytes bit [7:0] */ |
mbed_official | 76:aeb1df146756 | 678 | tmpreg &= (uint32_t)~((uint32_t)I2C_CR2_NBYTES); |
mbed_official | 76:aeb1df146756 | 679 | |
mbed_official | 76:aeb1df146756 | 680 | /* Set I2Cx Nbytes */ |
mbed_official | 76:aeb1df146756 | 681 | tmpreg |= (uint32_t)(((uint32_t)Number_Bytes << 16 ) & I2C_CR2_NBYTES); |
mbed_official | 76:aeb1df146756 | 682 | |
mbed_official | 76:aeb1df146756 | 683 | /* Store the new register value */ |
mbed_official | 76:aeb1df146756 | 684 | I2Cx->CR2 = tmpreg; |
mbed_official | 76:aeb1df146756 | 685 | } |
mbed_official | 76:aeb1df146756 | 686 | |
mbed_official | 76:aeb1df146756 | 687 | /** |
mbed_official | 76:aeb1df146756 | 688 | * @brief Configures the type of transfer request for the master. |
mbed_official | 76:aeb1df146756 | 689 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 690 | * @param I2C_Direction: specifies the transfer request direction to be programmed. |
mbed_official | 76:aeb1df146756 | 691 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 692 | * @arg I2C_Direction_Transmitter: Master request a write transfer |
mbed_official | 76:aeb1df146756 | 693 | * @arg I2C_Direction_Receiver: Master request a read transfer |
mbed_official | 76:aeb1df146756 | 694 | * @retval None |
mbed_official | 76:aeb1df146756 | 695 | */ |
mbed_official | 76:aeb1df146756 | 696 | void I2C_MasterRequestConfig(I2C_TypeDef* I2Cx, uint16_t I2C_Direction) |
mbed_official | 76:aeb1df146756 | 697 | { |
mbed_official | 76:aeb1df146756 | 698 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 699 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 700 | assert_param(IS_I2C_DIRECTION(I2C_Direction)); |
mbed_official | 76:aeb1df146756 | 701 | |
mbed_official | 76:aeb1df146756 | 702 | /* Test on the direction to set/reset the read/write bit */ |
mbed_official | 76:aeb1df146756 | 703 | if (I2C_Direction == I2C_Direction_Transmitter) |
mbed_official | 76:aeb1df146756 | 704 | { |
mbed_official | 76:aeb1df146756 | 705 | /* Request a write Transfer */ |
mbed_official | 76:aeb1df146756 | 706 | I2Cx->CR2 &= (uint32_t)~((uint32_t)I2C_CR2_RD_WRN); |
mbed_official | 76:aeb1df146756 | 707 | } |
mbed_official | 76:aeb1df146756 | 708 | else |
mbed_official | 76:aeb1df146756 | 709 | { |
mbed_official | 76:aeb1df146756 | 710 | /* Request a read Transfer */ |
mbed_official | 76:aeb1df146756 | 711 | I2Cx->CR2 |= I2C_CR2_RD_WRN; |
mbed_official | 76:aeb1df146756 | 712 | } |
mbed_official | 76:aeb1df146756 | 713 | } |
mbed_official | 76:aeb1df146756 | 714 | |
mbed_official | 76:aeb1df146756 | 715 | /** |
mbed_official | 76:aeb1df146756 | 716 | * @brief Generates I2Cx communication START condition. |
mbed_official | 76:aeb1df146756 | 717 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 718 | * @param NewState: new state of the I2C START condition generation. |
mbed_official | 76:aeb1df146756 | 719 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 720 | * @retval None |
mbed_official | 76:aeb1df146756 | 721 | */ |
mbed_official | 76:aeb1df146756 | 722 | void I2C_GenerateSTART(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 723 | { |
mbed_official | 76:aeb1df146756 | 724 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 725 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 726 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 727 | |
mbed_official | 76:aeb1df146756 | 728 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 729 | { |
mbed_official | 76:aeb1df146756 | 730 | /* Generate a START condition */ |
mbed_official | 76:aeb1df146756 | 731 | I2Cx->CR2 |= I2C_CR2_START; |
mbed_official | 76:aeb1df146756 | 732 | } |
mbed_official | 76:aeb1df146756 | 733 | else |
mbed_official | 76:aeb1df146756 | 734 | { |
mbed_official | 76:aeb1df146756 | 735 | /* Disable the START condition generation */ |
mbed_official | 76:aeb1df146756 | 736 | I2Cx->CR2 &= (uint32_t)~((uint32_t)I2C_CR2_START); |
mbed_official | 76:aeb1df146756 | 737 | } |
mbed_official | 76:aeb1df146756 | 738 | } |
mbed_official | 76:aeb1df146756 | 739 | |
mbed_official | 76:aeb1df146756 | 740 | /** |
mbed_official | 76:aeb1df146756 | 741 | * @brief Generates I2Cx communication STOP condition. |
mbed_official | 76:aeb1df146756 | 742 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 743 | * @param NewState: new state of the I2C STOP condition generation. |
mbed_official | 76:aeb1df146756 | 744 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 745 | * @retval None |
mbed_official | 76:aeb1df146756 | 746 | */ |
mbed_official | 76:aeb1df146756 | 747 | void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 748 | { |
mbed_official | 76:aeb1df146756 | 749 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 750 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 751 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 752 | |
mbed_official | 76:aeb1df146756 | 753 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 754 | { |
mbed_official | 76:aeb1df146756 | 755 | /* Generate a STOP condition */ |
mbed_official | 76:aeb1df146756 | 756 | I2Cx->CR2 |= I2C_CR2_STOP; |
mbed_official | 76:aeb1df146756 | 757 | } |
mbed_official | 76:aeb1df146756 | 758 | else |
mbed_official | 76:aeb1df146756 | 759 | { |
mbed_official | 76:aeb1df146756 | 760 | /* Disable the STOP condition generation */ |
mbed_official | 76:aeb1df146756 | 761 | I2Cx->CR2 &= (uint32_t)~((uint32_t)I2C_CR2_STOP); |
mbed_official | 76:aeb1df146756 | 762 | } |
mbed_official | 76:aeb1df146756 | 763 | } |
mbed_official | 76:aeb1df146756 | 764 | |
mbed_official | 76:aeb1df146756 | 765 | /** |
mbed_official | 76:aeb1df146756 | 766 | * @brief Enables or disables the I2C 10-bit header only mode with read direction. |
mbed_official | 76:aeb1df146756 | 767 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 768 | * @param NewState: new state of the I2C 10-bit header only mode. |
mbed_official | 76:aeb1df146756 | 769 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 770 | * @note This mode can be used only when switching from master transmitter mode |
mbed_official | 76:aeb1df146756 | 771 | * to master receiver mode. |
mbed_official | 76:aeb1df146756 | 772 | * @retval None |
mbed_official | 76:aeb1df146756 | 773 | */ |
mbed_official | 76:aeb1df146756 | 774 | void I2C_10BitAddressHeaderCmd(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 775 | { |
mbed_official | 76:aeb1df146756 | 776 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 777 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 778 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 779 | |
mbed_official | 76:aeb1df146756 | 780 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 781 | { |
mbed_official | 76:aeb1df146756 | 782 | /* Enable 10-bit header only mode */ |
mbed_official | 76:aeb1df146756 | 783 | I2Cx->CR2 |= I2C_CR2_HEAD10R; |
mbed_official | 76:aeb1df146756 | 784 | } |
mbed_official | 76:aeb1df146756 | 785 | else |
mbed_official | 76:aeb1df146756 | 786 | { |
mbed_official | 76:aeb1df146756 | 787 | /* Disable 10-bit header only mode */ |
mbed_official | 76:aeb1df146756 | 788 | I2Cx->CR2 &= (uint32_t)~((uint32_t)I2C_CR2_HEAD10R); |
mbed_official | 76:aeb1df146756 | 789 | } |
mbed_official | 76:aeb1df146756 | 790 | } |
mbed_official | 76:aeb1df146756 | 791 | |
mbed_official | 76:aeb1df146756 | 792 | /** |
mbed_official | 76:aeb1df146756 | 793 | * @brief Generates I2C communication Acknowledge. |
mbed_official | 76:aeb1df146756 | 794 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 795 | * @param NewState: new state of the Acknowledge. |
mbed_official | 76:aeb1df146756 | 796 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 797 | * @retval None |
mbed_official | 76:aeb1df146756 | 798 | */ |
mbed_official | 76:aeb1df146756 | 799 | void I2C_AcknowledgeConfig(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 800 | { |
mbed_official | 76:aeb1df146756 | 801 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 802 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 803 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 804 | |
mbed_official | 76:aeb1df146756 | 805 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 806 | { |
mbed_official | 76:aeb1df146756 | 807 | /* Enable ACK generation */ |
mbed_official | 76:aeb1df146756 | 808 | I2Cx->CR2 &= (uint32_t)~((uint32_t)I2C_CR2_NACK); |
mbed_official | 76:aeb1df146756 | 809 | } |
mbed_official | 76:aeb1df146756 | 810 | else |
mbed_official | 76:aeb1df146756 | 811 | { |
mbed_official | 76:aeb1df146756 | 812 | /* Enable NACK generation */ |
mbed_official | 76:aeb1df146756 | 813 | I2Cx->CR2 |= I2C_CR2_NACK; |
mbed_official | 76:aeb1df146756 | 814 | } |
mbed_official | 76:aeb1df146756 | 815 | } |
mbed_official | 76:aeb1df146756 | 816 | |
mbed_official | 76:aeb1df146756 | 817 | /** |
mbed_official | 76:aeb1df146756 | 818 | * @brief Returns the I2C slave matched address . |
mbed_official | 76:aeb1df146756 | 819 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 820 | * @retval The value of the slave matched address . |
mbed_official | 76:aeb1df146756 | 821 | */ |
mbed_official | 76:aeb1df146756 | 822 | uint8_t I2C_GetAddressMatched(I2C_TypeDef* I2Cx) |
mbed_official | 76:aeb1df146756 | 823 | { |
mbed_official | 76:aeb1df146756 | 824 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 825 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 826 | |
mbed_official | 76:aeb1df146756 | 827 | /* Return the slave matched address in the SR1 register */ |
mbed_official | 76:aeb1df146756 | 828 | return (uint8_t)(((uint32_t)I2Cx->ISR & I2C_ISR_ADDCODE) >> 16) ; |
mbed_official | 76:aeb1df146756 | 829 | } |
mbed_official | 76:aeb1df146756 | 830 | |
mbed_official | 76:aeb1df146756 | 831 | /** |
mbed_official | 76:aeb1df146756 | 832 | * @brief Returns the I2C slave received request. |
mbed_official | 76:aeb1df146756 | 833 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 834 | * @retval The value of the received request. |
mbed_official | 76:aeb1df146756 | 835 | */ |
mbed_official | 76:aeb1df146756 | 836 | uint16_t I2C_GetTransferDirection(I2C_TypeDef* I2Cx) |
mbed_official | 76:aeb1df146756 | 837 | { |
mbed_official | 76:aeb1df146756 | 838 | uint32_t tmpreg = 0; |
mbed_official | 76:aeb1df146756 | 839 | uint16_t direction = 0; |
mbed_official | 76:aeb1df146756 | 840 | |
mbed_official | 76:aeb1df146756 | 841 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 842 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 843 | |
mbed_official | 76:aeb1df146756 | 844 | /* Return the slave matched address in the SR1 register */ |
mbed_official | 76:aeb1df146756 | 845 | tmpreg = (uint32_t)(I2Cx->ISR & I2C_ISR_DIR); |
mbed_official | 76:aeb1df146756 | 846 | |
mbed_official | 76:aeb1df146756 | 847 | /* If write transfer is requested */ |
mbed_official | 76:aeb1df146756 | 848 | if (tmpreg == 0) |
mbed_official | 76:aeb1df146756 | 849 | { |
mbed_official | 76:aeb1df146756 | 850 | /* write transfer is requested */ |
mbed_official | 76:aeb1df146756 | 851 | direction = I2C_Direction_Transmitter; |
mbed_official | 76:aeb1df146756 | 852 | } |
mbed_official | 76:aeb1df146756 | 853 | else |
mbed_official | 76:aeb1df146756 | 854 | { |
mbed_official | 76:aeb1df146756 | 855 | /* Read transfer is requested */ |
mbed_official | 76:aeb1df146756 | 856 | direction = I2C_Direction_Receiver; |
mbed_official | 76:aeb1df146756 | 857 | } |
mbed_official | 76:aeb1df146756 | 858 | return direction; |
mbed_official | 76:aeb1df146756 | 859 | } |
mbed_official | 76:aeb1df146756 | 860 | |
mbed_official | 76:aeb1df146756 | 861 | /** |
mbed_official | 76:aeb1df146756 | 862 | * @brief Handles I2Cx communication when starting transfer or during transfer (TC or TCR flag are set). |
mbed_official | 76:aeb1df146756 | 863 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 864 | * @param Address: specifies the slave address to be programmed. |
mbed_official | 76:aeb1df146756 | 865 | * @param Number_Bytes: specifies the number of bytes to be programmed. |
mbed_official | 76:aeb1df146756 | 866 | * This parameter must be a value between 0 and 255. |
mbed_official | 76:aeb1df146756 | 867 | * @param ReloadEndMode: new state of the I2C START condition generation. |
mbed_official | 76:aeb1df146756 | 868 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 869 | * @arg I2C_Reload_Mode: Enable Reload mode . |
mbed_official | 76:aeb1df146756 | 870 | * @arg I2C_AutoEnd_Mode: Enable Automatic end mode. |
mbed_official | 76:aeb1df146756 | 871 | * @arg I2C_SoftEnd_Mode: Enable Software end mode. |
mbed_official | 76:aeb1df146756 | 872 | * @param StartStopMode: new state of the I2C START condition generation. |
mbed_official | 76:aeb1df146756 | 873 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 874 | * @arg I2C_No_StartStop: Don't Generate stop and start condition. |
mbed_official | 76:aeb1df146756 | 875 | * @arg I2C_Generate_Stop: Generate stop condition (Number_Bytes should be set to 0). |
mbed_official | 76:aeb1df146756 | 876 | * @arg I2C_Generate_Start_Read: Generate Restart for read request. |
mbed_official | 76:aeb1df146756 | 877 | * @arg I2C_Generate_Start_Write: Generate Restart for write request. |
mbed_official | 76:aeb1df146756 | 878 | * @retval None |
mbed_official | 76:aeb1df146756 | 879 | */ |
mbed_official | 76:aeb1df146756 | 880 | void I2C_TransferHandling(I2C_TypeDef* I2Cx, uint16_t Address, uint8_t Number_Bytes, uint32_t ReloadEndMode, uint32_t StartStopMode) |
mbed_official | 76:aeb1df146756 | 881 | { |
mbed_official | 76:aeb1df146756 | 882 | uint32_t tmpreg = 0; |
mbed_official | 76:aeb1df146756 | 883 | |
mbed_official | 76:aeb1df146756 | 884 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 885 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 886 | assert_param(IS_I2C_SLAVE_ADDRESS(Address)); |
mbed_official | 76:aeb1df146756 | 887 | assert_param(IS_RELOAD_END_MODE(ReloadEndMode)); |
mbed_official | 76:aeb1df146756 | 888 | assert_param(IS_START_STOP_MODE(StartStopMode)); |
mbed_official | 76:aeb1df146756 | 889 | |
mbed_official | 76:aeb1df146756 | 890 | /* Get the CR2 register value */ |
mbed_official | 76:aeb1df146756 | 891 | tmpreg = I2Cx->CR2; |
mbed_official | 76:aeb1df146756 | 892 | |
mbed_official | 76:aeb1df146756 | 893 | /* clear tmpreg specific bits */ |
mbed_official | 76:aeb1df146756 | 894 | tmpreg &= (uint32_t)~((uint32_t)(I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_AUTOEND | I2C_CR2_RD_WRN | I2C_CR2_START | I2C_CR2_STOP)); |
mbed_official | 76:aeb1df146756 | 895 | |
mbed_official | 76:aeb1df146756 | 896 | /* update tmpreg */ |
mbed_official | 76:aeb1df146756 | 897 | tmpreg |= (uint32_t)(((uint32_t)Address & I2C_CR2_SADD) | (((uint32_t)Number_Bytes << 16 ) & I2C_CR2_NBYTES) | \ |
mbed_official | 76:aeb1df146756 | 898 | (uint32_t)ReloadEndMode | (uint32_t)StartStopMode); |
mbed_official | 76:aeb1df146756 | 899 | |
mbed_official | 76:aeb1df146756 | 900 | /* update CR2 register */ |
mbed_official | 76:aeb1df146756 | 901 | I2Cx->CR2 = tmpreg; |
mbed_official | 76:aeb1df146756 | 902 | } |
mbed_official | 76:aeb1df146756 | 903 | |
mbed_official | 76:aeb1df146756 | 904 | /** |
mbed_official | 76:aeb1df146756 | 905 | * @} |
mbed_official | 76:aeb1df146756 | 906 | */ |
mbed_official | 76:aeb1df146756 | 907 | |
mbed_official | 76:aeb1df146756 | 908 | |
mbed_official | 76:aeb1df146756 | 909 | /** @defgroup I2C_Group3 SMBUS management functions |
mbed_official | 76:aeb1df146756 | 910 | * @brief SMBUS management functions |
mbed_official | 76:aeb1df146756 | 911 | * |
mbed_official | 76:aeb1df146756 | 912 | @verbatim |
mbed_official | 76:aeb1df146756 | 913 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 914 | ##### SMBUS management functions ##### |
mbed_official | 76:aeb1df146756 | 915 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 916 | [..] This section provides a set of functions that handles SMBus communication |
mbed_official | 76:aeb1df146756 | 917 | and timeouts detection. |
mbed_official | 76:aeb1df146756 | 918 | |
mbed_official | 76:aeb1df146756 | 919 | [..] The SMBus Device default address (0b1100 001) is enabled by calling I2C_Init() |
mbed_official | 76:aeb1df146756 | 920 | function and setting I2C_Mode member of I2C_InitTypeDef() structure to |
mbed_official | 76:aeb1df146756 | 921 | I2C_Mode_SMBusDevice. |
mbed_official | 76:aeb1df146756 | 922 | |
mbed_official | 76:aeb1df146756 | 923 | [..] The SMBus Host address (0b0001 000) is enabled by calling I2C_Init() |
mbed_official | 76:aeb1df146756 | 924 | function and setting I2C_Mode member of I2C_InitTypeDef() structure to |
mbed_official | 76:aeb1df146756 | 925 | I2C_Mode_SMBusHost. |
mbed_official | 76:aeb1df146756 | 926 | |
mbed_official | 76:aeb1df146756 | 927 | [..] The Alert Response Address (0b0001 100) is enabled using I2C_SMBusAlertCmd() |
mbed_official | 76:aeb1df146756 | 928 | function. |
mbed_official | 76:aeb1df146756 | 929 | |
mbed_official | 76:aeb1df146756 | 930 | [..] To detect cumulative SCL stretch in master and slave mode, TIMEOUTB should be |
mbed_official | 76:aeb1df146756 | 931 | configured (in accordance to SMBus specification) using I2C_TimeoutBConfig() |
mbed_official | 76:aeb1df146756 | 932 | function then I2C_ExtendedClockTimeoutCmd() function should be called to enable |
mbed_official | 76:aeb1df146756 | 933 | the detection. |
mbed_official | 76:aeb1df146756 | 934 | |
mbed_official | 76:aeb1df146756 | 935 | [..] SCL low timeout is detected by configuring TIMEOUTB using I2C_TimeoutBConfig() |
mbed_official | 76:aeb1df146756 | 936 | function followed by the call of I2C_ClockTimeoutCmd(). When adding to this |
mbed_official | 76:aeb1df146756 | 937 | procedure the call of I2C_IdleClockTimeoutCmd() function, Bus Idle condition |
mbed_official | 76:aeb1df146756 | 938 | (both SCL and SDA high) is detected also. |
mbed_official | 76:aeb1df146756 | 939 | |
mbed_official | 76:aeb1df146756 | 940 | @endverbatim |
mbed_official | 76:aeb1df146756 | 941 | * @{ |
mbed_official | 76:aeb1df146756 | 942 | */ |
mbed_official | 76:aeb1df146756 | 943 | |
mbed_official | 76:aeb1df146756 | 944 | /** |
mbed_official | 76:aeb1df146756 | 945 | * @brief Enables or disables I2C SMBus alert. |
mbed_official | 76:aeb1df146756 | 946 | * @param I2Cx: where x can be 1 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 947 | * @param NewState: new state of the I2Cx SMBus alert. |
mbed_official | 76:aeb1df146756 | 948 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 949 | * @retval None |
mbed_official | 76:aeb1df146756 | 950 | */ |
mbed_official | 76:aeb1df146756 | 951 | void I2C_SMBusAlertCmd(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 952 | { |
mbed_official | 76:aeb1df146756 | 953 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 954 | assert_param(IS_I2C_1_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 955 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 956 | |
mbed_official | 76:aeb1df146756 | 957 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 958 | { |
mbed_official | 76:aeb1df146756 | 959 | /* Enable SMBus alert */ |
mbed_official | 76:aeb1df146756 | 960 | I2Cx->CR1 |= I2C_CR1_ALERTEN; |
mbed_official | 76:aeb1df146756 | 961 | } |
mbed_official | 76:aeb1df146756 | 962 | else |
mbed_official | 76:aeb1df146756 | 963 | { |
mbed_official | 76:aeb1df146756 | 964 | /* Disable SMBus alert */ |
mbed_official | 76:aeb1df146756 | 965 | I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_ALERTEN); |
mbed_official | 76:aeb1df146756 | 966 | } |
mbed_official | 76:aeb1df146756 | 967 | } |
mbed_official | 76:aeb1df146756 | 968 | |
mbed_official | 76:aeb1df146756 | 969 | /** |
mbed_official | 76:aeb1df146756 | 970 | * @brief Enables or disables I2C Clock Timeout (SCL Timeout detection). |
mbed_official | 76:aeb1df146756 | 971 | * @param I2Cx: where x can be 1 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 972 | * @param NewState: new state of the I2Cx clock Timeout. |
mbed_official | 76:aeb1df146756 | 973 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 974 | * @retval None |
mbed_official | 76:aeb1df146756 | 975 | */ |
mbed_official | 76:aeb1df146756 | 976 | void I2C_ClockTimeoutCmd(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 977 | { |
mbed_official | 76:aeb1df146756 | 978 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 979 | assert_param(IS_I2C_1_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 980 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 981 | |
mbed_official | 76:aeb1df146756 | 982 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 983 | { |
mbed_official | 76:aeb1df146756 | 984 | /* Enable Clock Timeout */ |
mbed_official | 76:aeb1df146756 | 985 | I2Cx->TIMEOUTR |= I2C_TIMEOUTR_TIMOUTEN; |
mbed_official | 76:aeb1df146756 | 986 | } |
mbed_official | 76:aeb1df146756 | 987 | else |
mbed_official | 76:aeb1df146756 | 988 | { |
mbed_official | 76:aeb1df146756 | 989 | /* Disable Clock Timeout */ |
mbed_official | 76:aeb1df146756 | 990 | I2Cx->TIMEOUTR &= (uint32_t)~((uint32_t)I2C_TIMEOUTR_TIMOUTEN); |
mbed_official | 76:aeb1df146756 | 991 | } |
mbed_official | 76:aeb1df146756 | 992 | } |
mbed_official | 76:aeb1df146756 | 993 | |
mbed_official | 76:aeb1df146756 | 994 | /** |
mbed_official | 76:aeb1df146756 | 995 | * @brief Enables or disables I2C Extended Clock Timeout (SCL cumulative Timeout detection). |
mbed_official | 76:aeb1df146756 | 996 | * @param I2Cx: where x can be 1 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 997 | * @param NewState: new state of the I2Cx Extended clock Timeout. |
mbed_official | 76:aeb1df146756 | 998 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 999 | * @retval None |
mbed_official | 76:aeb1df146756 | 1000 | */ |
mbed_official | 76:aeb1df146756 | 1001 | void I2C_ExtendedClockTimeoutCmd(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 1002 | { |
mbed_official | 76:aeb1df146756 | 1003 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1004 | assert_param(IS_I2C_1_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 1005 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 1006 | |
mbed_official | 76:aeb1df146756 | 1007 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 1008 | { |
mbed_official | 76:aeb1df146756 | 1009 | /* Enable Clock Timeout */ |
mbed_official | 76:aeb1df146756 | 1010 | I2Cx->TIMEOUTR |= I2C_TIMEOUTR_TEXTEN; |
mbed_official | 76:aeb1df146756 | 1011 | } |
mbed_official | 76:aeb1df146756 | 1012 | else |
mbed_official | 76:aeb1df146756 | 1013 | { |
mbed_official | 76:aeb1df146756 | 1014 | /* Disable Clock Timeout */ |
mbed_official | 76:aeb1df146756 | 1015 | I2Cx->TIMEOUTR &= (uint32_t)~((uint32_t)I2C_TIMEOUTR_TEXTEN); |
mbed_official | 76:aeb1df146756 | 1016 | } |
mbed_official | 76:aeb1df146756 | 1017 | } |
mbed_official | 76:aeb1df146756 | 1018 | |
mbed_official | 76:aeb1df146756 | 1019 | /** |
mbed_official | 76:aeb1df146756 | 1020 | * @brief Enables or disables I2C Idle Clock Timeout (Bus idle SCL and SDA |
mbed_official | 76:aeb1df146756 | 1021 | * high detection). |
mbed_official | 76:aeb1df146756 | 1022 | * @param I2Cx: where x can be 1 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 1023 | * @param NewState: new state of the I2Cx Idle clock Timeout. |
mbed_official | 76:aeb1df146756 | 1024 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 1025 | * @retval None |
mbed_official | 76:aeb1df146756 | 1026 | */ |
mbed_official | 76:aeb1df146756 | 1027 | void I2C_IdleClockTimeoutCmd(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 1028 | { |
mbed_official | 76:aeb1df146756 | 1029 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1030 | assert_param(IS_I2C_1_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 1031 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 1032 | |
mbed_official | 76:aeb1df146756 | 1033 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 1034 | { |
mbed_official | 76:aeb1df146756 | 1035 | /* Enable Clock Timeout */ |
mbed_official | 76:aeb1df146756 | 1036 | I2Cx->TIMEOUTR |= I2C_TIMEOUTR_TIDLE; |
mbed_official | 76:aeb1df146756 | 1037 | } |
mbed_official | 76:aeb1df146756 | 1038 | else |
mbed_official | 76:aeb1df146756 | 1039 | { |
mbed_official | 76:aeb1df146756 | 1040 | /* Disable Clock Timeout */ |
mbed_official | 76:aeb1df146756 | 1041 | I2Cx->TIMEOUTR &= (uint32_t)~((uint32_t)I2C_TIMEOUTR_TIDLE); |
mbed_official | 76:aeb1df146756 | 1042 | } |
mbed_official | 76:aeb1df146756 | 1043 | } |
mbed_official | 76:aeb1df146756 | 1044 | |
mbed_official | 76:aeb1df146756 | 1045 | /** |
mbed_official | 76:aeb1df146756 | 1046 | * @brief Configures the I2C Bus Timeout A (SCL Timeout when TIDLE = 0 or Bus |
mbed_official | 76:aeb1df146756 | 1047 | * idle SCL and SDA high when TIDLE = 1). |
mbed_official | 76:aeb1df146756 | 1048 | * @param I2Cx: where x can be 1 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 1049 | * @param Timeout: specifies the TimeoutA to be programmed. |
mbed_official | 76:aeb1df146756 | 1050 | * @retval None |
mbed_official | 76:aeb1df146756 | 1051 | */ |
mbed_official | 76:aeb1df146756 | 1052 | void I2C_TimeoutAConfig(I2C_TypeDef* I2Cx, uint16_t Timeout) |
mbed_official | 76:aeb1df146756 | 1053 | { |
mbed_official | 76:aeb1df146756 | 1054 | uint32_t tmpreg = 0; |
mbed_official | 76:aeb1df146756 | 1055 | |
mbed_official | 76:aeb1df146756 | 1056 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1057 | assert_param(IS_I2C_1_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 1058 | assert_param(IS_I2C_TIMEOUT(Timeout)); |
mbed_official | 76:aeb1df146756 | 1059 | |
mbed_official | 76:aeb1df146756 | 1060 | /* Get the old register value */ |
mbed_official | 76:aeb1df146756 | 1061 | tmpreg = I2Cx->TIMEOUTR; |
mbed_official | 76:aeb1df146756 | 1062 | |
mbed_official | 76:aeb1df146756 | 1063 | /* Reset I2Cx TIMEOUTA bit [11:0] */ |
mbed_official | 76:aeb1df146756 | 1064 | tmpreg &= (uint32_t)~((uint32_t)I2C_TIMEOUTR_TIMEOUTA); |
mbed_official | 76:aeb1df146756 | 1065 | |
mbed_official | 76:aeb1df146756 | 1066 | /* Set I2Cx TIMEOUTA */ |
mbed_official | 76:aeb1df146756 | 1067 | tmpreg |= (uint32_t)((uint32_t)Timeout & I2C_TIMEOUTR_TIMEOUTA) ; |
mbed_official | 76:aeb1df146756 | 1068 | |
mbed_official | 76:aeb1df146756 | 1069 | /* Store the new register value */ |
mbed_official | 76:aeb1df146756 | 1070 | I2Cx->TIMEOUTR = tmpreg; |
mbed_official | 76:aeb1df146756 | 1071 | } |
mbed_official | 76:aeb1df146756 | 1072 | |
mbed_official | 76:aeb1df146756 | 1073 | /** |
mbed_official | 76:aeb1df146756 | 1074 | * @brief Configures the I2C Bus Timeout B (SCL cumulative Timeout). |
mbed_official | 76:aeb1df146756 | 1075 | * @param I2Cx: where x can be 1 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 1076 | * @param Timeout: specifies the TimeoutB to be programmed. |
mbed_official | 76:aeb1df146756 | 1077 | * @retval None |
mbed_official | 76:aeb1df146756 | 1078 | */ |
mbed_official | 76:aeb1df146756 | 1079 | void I2C_TimeoutBConfig(I2C_TypeDef* I2Cx, uint16_t Timeout) |
mbed_official | 76:aeb1df146756 | 1080 | { |
mbed_official | 76:aeb1df146756 | 1081 | uint32_t tmpreg = 0; |
mbed_official | 76:aeb1df146756 | 1082 | |
mbed_official | 76:aeb1df146756 | 1083 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1084 | assert_param(IS_I2C_1_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 1085 | assert_param(IS_I2C_TIMEOUT(Timeout)); |
mbed_official | 76:aeb1df146756 | 1086 | |
mbed_official | 76:aeb1df146756 | 1087 | /* Get the old register value */ |
mbed_official | 76:aeb1df146756 | 1088 | tmpreg = I2Cx->TIMEOUTR; |
mbed_official | 76:aeb1df146756 | 1089 | |
mbed_official | 76:aeb1df146756 | 1090 | /* Reset I2Cx TIMEOUTB bit [11:0] */ |
mbed_official | 76:aeb1df146756 | 1091 | tmpreg &= (uint32_t)~((uint32_t)I2C_TIMEOUTR_TIMEOUTB); |
mbed_official | 76:aeb1df146756 | 1092 | |
mbed_official | 76:aeb1df146756 | 1093 | /* Set I2Cx TIMEOUTB */ |
mbed_official | 76:aeb1df146756 | 1094 | tmpreg |= (uint32_t)(((uint32_t)Timeout << 16) & I2C_TIMEOUTR_TIMEOUTB) ; |
mbed_official | 76:aeb1df146756 | 1095 | |
mbed_official | 76:aeb1df146756 | 1096 | /* Store the new register value */ |
mbed_official | 76:aeb1df146756 | 1097 | I2Cx->TIMEOUTR = tmpreg; |
mbed_official | 76:aeb1df146756 | 1098 | } |
mbed_official | 76:aeb1df146756 | 1099 | |
mbed_official | 76:aeb1df146756 | 1100 | /** |
mbed_official | 76:aeb1df146756 | 1101 | * @brief Enables or disables I2C PEC calculation. |
mbed_official | 76:aeb1df146756 | 1102 | * @param I2Cx: where x can be 1 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 1103 | * @param NewState: new state of the I2Cx PEC calculation. |
mbed_official | 76:aeb1df146756 | 1104 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 1105 | * @retval None |
mbed_official | 76:aeb1df146756 | 1106 | */ |
mbed_official | 76:aeb1df146756 | 1107 | void I2C_CalculatePEC(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 1108 | { |
mbed_official | 76:aeb1df146756 | 1109 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1110 | assert_param(IS_I2C_1_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 1111 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 1112 | |
mbed_official | 76:aeb1df146756 | 1113 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 1114 | { |
mbed_official | 76:aeb1df146756 | 1115 | /* Enable PEC calculation */ |
mbed_official | 76:aeb1df146756 | 1116 | I2Cx->CR1 |= I2C_CR1_PECEN; |
mbed_official | 76:aeb1df146756 | 1117 | } |
mbed_official | 76:aeb1df146756 | 1118 | else |
mbed_official | 76:aeb1df146756 | 1119 | { |
mbed_official | 76:aeb1df146756 | 1120 | /* Disable PEC calculation */ |
mbed_official | 76:aeb1df146756 | 1121 | I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_PECEN); |
mbed_official | 76:aeb1df146756 | 1122 | } |
mbed_official | 76:aeb1df146756 | 1123 | } |
mbed_official | 76:aeb1df146756 | 1124 | |
mbed_official | 76:aeb1df146756 | 1125 | /** |
mbed_official | 76:aeb1df146756 | 1126 | * @brief Enables or disables I2C PEC transmission/reception request. |
mbed_official | 76:aeb1df146756 | 1127 | * @param I2Cx: where x can be 1 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 1128 | * @param NewState: new state of the I2Cx PEC request. |
mbed_official | 76:aeb1df146756 | 1129 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 1130 | * @retval None |
mbed_official | 76:aeb1df146756 | 1131 | */ |
mbed_official | 76:aeb1df146756 | 1132 | void I2C_PECRequestCmd(I2C_TypeDef* I2Cx, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 1133 | { |
mbed_official | 76:aeb1df146756 | 1134 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1135 | assert_param(IS_I2C_1_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 1136 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 1137 | |
mbed_official | 76:aeb1df146756 | 1138 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 1139 | { |
mbed_official | 76:aeb1df146756 | 1140 | /* Enable PEC transmission/reception request */ |
mbed_official | 76:aeb1df146756 | 1141 | I2Cx->CR1 |= I2C_CR2_PECBYTE; |
mbed_official | 76:aeb1df146756 | 1142 | } |
mbed_official | 76:aeb1df146756 | 1143 | else |
mbed_official | 76:aeb1df146756 | 1144 | { |
mbed_official | 76:aeb1df146756 | 1145 | /* Disable PEC transmission/reception request */ |
mbed_official | 76:aeb1df146756 | 1146 | I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR2_PECBYTE); |
mbed_official | 76:aeb1df146756 | 1147 | } |
mbed_official | 76:aeb1df146756 | 1148 | } |
mbed_official | 76:aeb1df146756 | 1149 | |
mbed_official | 76:aeb1df146756 | 1150 | /** |
mbed_official | 76:aeb1df146756 | 1151 | * @brief Returns the I2C PEC. |
mbed_official | 76:aeb1df146756 | 1152 | * @param I2Cx: where x can be 1 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 1153 | * @retval The value of the PEC . |
mbed_official | 76:aeb1df146756 | 1154 | */ |
mbed_official | 76:aeb1df146756 | 1155 | uint8_t I2C_GetPEC(I2C_TypeDef* I2Cx) |
mbed_official | 76:aeb1df146756 | 1156 | { |
mbed_official | 76:aeb1df146756 | 1157 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1158 | assert_param(IS_I2C_1_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 1159 | |
mbed_official | 76:aeb1df146756 | 1160 | /* Return the slave matched address in the SR1 register */ |
mbed_official | 76:aeb1df146756 | 1161 | return (uint8_t)((uint32_t)I2Cx->PECR & I2C_PECR_PEC); |
mbed_official | 76:aeb1df146756 | 1162 | } |
mbed_official | 76:aeb1df146756 | 1163 | |
mbed_official | 76:aeb1df146756 | 1164 | /** |
mbed_official | 76:aeb1df146756 | 1165 | * @} |
mbed_official | 76:aeb1df146756 | 1166 | */ |
mbed_official | 76:aeb1df146756 | 1167 | |
mbed_official | 76:aeb1df146756 | 1168 | |
mbed_official | 76:aeb1df146756 | 1169 | /** @defgroup I2C_Group4 I2C registers management functions |
mbed_official | 76:aeb1df146756 | 1170 | * @brief I2C registers management functions |
mbed_official | 76:aeb1df146756 | 1171 | * |
mbed_official | 76:aeb1df146756 | 1172 | @verbatim |
mbed_official | 76:aeb1df146756 | 1173 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 1174 | ##### I2C registers management functions ##### |
mbed_official | 76:aeb1df146756 | 1175 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 1176 | [..] This section provides a functions that allow user the management of |
mbed_official | 76:aeb1df146756 | 1177 | I2C registers. |
mbed_official | 76:aeb1df146756 | 1178 | |
mbed_official | 76:aeb1df146756 | 1179 | @endverbatim |
mbed_official | 76:aeb1df146756 | 1180 | * @{ |
mbed_official | 76:aeb1df146756 | 1181 | */ |
mbed_official | 76:aeb1df146756 | 1182 | |
mbed_official | 76:aeb1df146756 | 1183 | /** |
mbed_official | 76:aeb1df146756 | 1184 | * @brief Reads the specified I2C register and returns its value. |
mbed_official | 76:aeb1df146756 | 1185 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 1186 | * @param I2C_Register: specifies the register to read. |
mbed_official | 76:aeb1df146756 | 1187 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 1188 | * @arg I2C_Register_CR1: CR1 register. |
mbed_official | 76:aeb1df146756 | 1189 | * @arg I2C_Register_CR2: CR2 register. |
mbed_official | 76:aeb1df146756 | 1190 | * @arg I2C_Register_OAR1: OAR1 register. |
mbed_official | 76:aeb1df146756 | 1191 | * @arg I2C_Register_OAR2: OAR2 register. |
mbed_official | 76:aeb1df146756 | 1192 | * @arg I2C_Register_TIMINGR: TIMING register. |
mbed_official | 76:aeb1df146756 | 1193 | * @arg I2C_Register_TIMEOUTR: TIMEOUTR register. |
mbed_official | 76:aeb1df146756 | 1194 | * @arg I2C_Register_ISR: ISR register. |
mbed_official | 76:aeb1df146756 | 1195 | * @arg I2C_Register_ICR: ICR register. |
mbed_official | 76:aeb1df146756 | 1196 | * @arg I2C_Register_PECR: PECR register. |
mbed_official | 76:aeb1df146756 | 1197 | * @arg I2C_Register_RXDR: RXDR register. |
mbed_official | 76:aeb1df146756 | 1198 | * @arg I2C_Register_TXDR: TXDR register. |
mbed_official | 76:aeb1df146756 | 1199 | * @retval The value of the read register. |
mbed_official | 76:aeb1df146756 | 1200 | */ |
mbed_official | 76:aeb1df146756 | 1201 | uint32_t I2C_ReadRegister(I2C_TypeDef* I2Cx, uint8_t I2C_Register) |
mbed_official | 76:aeb1df146756 | 1202 | { |
mbed_official | 76:aeb1df146756 | 1203 | __IO uint32_t tmp = 0; |
mbed_official | 76:aeb1df146756 | 1204 | |
mbed_official | 76:aeb1df146756 | 1205 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1206 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 1207 | assert_param(IS_I2C_REGISTER(I2C_Register)); |
mbed_official | 76:aeb1df146756 | 1208 | |
mbed_official | 76:aeb1df146756 | 1209 | tmp = (uint32_t)I2Cx; |
mbed_official | 76:aeb1df146756 | 1210 | tmp += I2C_Register; |
mbed_official | 76:aeb1df146756 | 1211 | |
mbed_official | 76:aeb1df146756 | 1212 | /* Return the selected register value */ |
mbed_official | 76:aeb1df146756 | 1213 | return (*(__IO uint32_t *) tmp); |
mbed_official | 76:aeb1df146756 | 1214 | } |
mbed_official | 76:aeb1df146756 | 1215 | |
mbed_official | 76:aeb1df146756 | 1216 | /** |
mbed_official | 76:aeb1df146756 | 1217 | * @} |
mbed_official | 76:aeb1df146756 | 1218 | */ |
mbed_official | 76:aeb1df146756 | 1219 | |
mbed_official | 76:aeb1df146756 | 1220 | /** @defgroup I2C_Group5 Data transfers management functions |
mbed_official | 76:aeb1df146756 | 1221 | * @brief Data transfers management functions |
mbed_official | 76:aeb1df146756 | 1222 | * |
mbed_official | 76:aeb1df146756 | 1223 | @verbatim |
mbed_official | 76:aeb1df146756 | 1224 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 1225 | ##### Data transfers management functions ##### |
mbed_official | 76:aeb1df146756 | 1226 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 1227 | [..] This subsection provides a set of functions allowing to manage |
mbed_official | 76:aeb1df146756 | 1228 | the I2C data transfers. |
mbed_official | 76:aeb1df146756 | 1229 | |
mbed_official | 76:aeb1df146756 | 1230 | [..] The read access of the I2C_RXDR register can be done using |
mbed_official | 76:aeb1df146756 | 1231 | the I2C_ReceiveData() function and returns the received value. |
mbed_official | 76:aeb1df146756 | 1232 | Whereas a write access to the I2C_TXDR can be done using I2C_SendData() |
mbed_official | 76:aeb1df146756 | 1233 | function and stores the written data into TXDR. |
mbed_official | 76:aeb1df146756 | 1234 | @endverbatim |
mbed_official | 76:aeb1df146756 | 1235 | * @{ |
mbed_official | 76:aeb1df146756 | 1236 | */ |
mbed_official | 76:aeb1df146756 | 1237 | |
mbed_official | 76:aeb1df146756 | 1238 | /** |
mbed_official | 76:aeb1df146756 | 1239 | * @brief Sends a data byte through the I2Cx peripheral. |
mbed_official | 76:aeb1df146756 | 1240 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 1241 | * @param Data: Byte to be transmitted.. |
mbed_official | 76:aeb1df146756 | 1242 | * @retval None |
mbed_official | 76:aeb1df146756 | 1243 | */ |
mbed_official | 76:aeb1df146756 | 1244 | void I2C_SendData(I2C_TypeDef* I2Cx, uint8_t Data) |
mbed_official | 76:aeb1df146756 | 1245 | { |
mbed_official | 76:aeb1df146756 | 1246 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1247 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 1248 | |
mbed_official | 76:aeb1df146756 | 1249 | /* Write in the DR register the data to be sent */ |
mbed_official | 76:aeb1df146756 | 1250 | I2Cx->TXDR = (uint8_t)Data; |
mbed_official | 76:aeb1df146756 | 1251 | } |
mbed_official | 76:aeb1df146756 | 1252 | |
mbed_official | 76:aeb1df146756 | 1253 | /** |
mbed_official | 76:aeb1df146756 | 1254 | * @brief Returns the most recent received data by the I2Cx peripheral. |
mbed_official | 76:aeb1df146756 | 1255 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 1256 | * @retval The value of the received data. |
mbed_official | 76:aeb1df146756 | 1257 | */ |
mbed_official | 76:aeb1df146756 | 1258 | uint8_t I2C_ReceiveData(I2C_TypeDef* I2Cx) |
mbed_official | 76:aeb1df146756 | 1259 | { |
mbed_official | 76:aeb1df146756 | 1260 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1261 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 1262 | |
mbed_official | 76:aeb1df146756 | 1263 | /* Return the data in the DR register */ |
mbed_official | 76:aeb1df146756 | 1264 | return (uint8_t)I2Cx->RXDR; |
mbed_official | 76:aeb1df146756 | 1265 | } |
mbed_official | 76:aeb1df146756 | 1266 | |
mbed_official | 76:aeb1df146756 | 1267 | /** |
mbed_official | 76:aeb1df146756 | 1268 | * @} |
mbed_official | 76:aeb1df146756 | 1269 | */ |
mbed_official | 76:aeb1df146756 | 1270 | |
mbed_official | 76:aeb1df146756 | 1271 | |
mbed_official | 76:aeb1df146756 | 1272 | /** @defgroup I2C_Group6 DMA transfers management functions |
mbed_official | 76:aeb1df146756 | 1273 | * @brief DMA transfers management functions |
mbed_official | 76:aeb1df146756 | 1274 | * |
mbed_official | 76:aeb1df146756 | 1275 | @verbatim |
mbed_official | 76:aeb1df146756 | 1276 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 1277 | ##### DMA transfers management functions ##### |
mbed_official | 76:aeb1df146756 | 1278 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 1279 | [..] This section provides two functions that can be used only in DMA mode. |
mbed_official | 76:aeb1df146756 | 1280 | [..] In DMA Mode, the I2C communication can be managed by 2 DMA Channel |
mbed_official | 76:aeb1df146756 | 1281 | requests: |
mbed_official | 76:aeb1df146756 | 1282 | (#) I2C_DMAReq_Tx: specifies the Tx buffer DMA transfer request. |
mbed_official | 76:aeb1df146756 | 1283 | (#) I2C_DMAReq_Rx: specifies the Rx buffer DMA transfer request. |
mbed_official | 76:aeb1df146756 | 1284 | [..] In this Mode it is advised to use the following function: |
mbed_official | 76:aeb1df146756 | 1285 | (+) I2C_DMACmd(I2C_TypeDef* I2Cx, uint32_t I2C_DMAReq, FunctionalState NewState); |
mbed_official | 76:aeb1df146756 | 1286 | @endverbatim |
mbed_official | 76:aeb1df146756 | 1287 | * @{ |
mbed_official | 76:aeb1df146756 | 1288 | */ |
mbed_official | 76:aeb1df146756 | 1289 | |
mbed_official | 76:aeb1df146756 | 1290 | /** |
mbed_official | 76:aeb1df146756 | 1291 | * @brief Enables or disables the I2C DMA interface. |
mbed_official | 76:aeb1df146756 | 1292 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 1293 | * @param I2C_DMAReq: specifies the I2C DMA transfer request to be enabled or disabled. |
mbed_official | 76:aeb1df146756 | 1294 | * This parameter can be any combination of the following values: |
mbed_official | 76:aeb1df146756 | 1295 | * @arg I2C_DMAReq_Tx: Tx DMA transfer request |
mbed_official | 76:aeb1df146756 | 1296 | * @arg I2C_DMAReq_Rx: Rx DMA transfer request |
mbed_official | 76:aeb1df146756 | 1297 | * @param NewState: new state of the selected I2C DMA transfer request. |
mbed_official | 76:aeb1df146756 | 1298 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 1299 | * @retval None |
mbed_official | 76:aeb1df146756 | 1300 | */ |
mbed_official | 76:aeb1df146756 | 1301 | void I2C_DMACmd(I2C_TypeDef* I2Cx, uint32_t I2C_DMAReq, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 1302 | { |
mbed_official | 76:aeb1df146756 | 1303 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1304 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 1305 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 1306 | assert_param(IS_I2C_DMA_REQ(I2C_DMAReq)); |
mbed_official | 76:aeb1df146756 | 1307 | |
mbed_official | 76:aeb1df146756 | 1308 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 1309 | { |
mbed_official | 76:aeb1df146756 | 1310 | /* Enable the selected I2C DMA requests */ |
mbed_official | 76:aeb1df146756 | 1311 | I2Cx->CR1 |= I2C_DMAReq; |
mbed_official | 76:aeb1df146756 | 1312 | } |
mbed_official | 76:aeb1df146756 | 1313 | else |
mbed_official | 76:aeb1df146756 | 1314 | { |
mbed_official | 76:aeb1df146756 | 1315 | /* Disable the selected I2C DMA requests */ |
mbed_official | 76:aeb1df146756 | 1316 | I2Cx->CR1 &= (uint32_t)~I2C_DMAReq; |
mbed_official | 76:aeb1df146756 | 1317 | } |
mbed_official | 76:aeb1df146756 | 1318 | } |
mbed_official | 76:aeb1df146756 | 1319 | /** |
mbed_official | 76:aeb1df146756 | 1320 | * @} |
mbed_official | 76:aeb1df146756 | 1321 | */ |
mbed_official | 76:aeb1df146756 | 1322 | |
mbed_official | 76:aeb1df146756 | 1323 | |
mbed_official | 76:aeb1df146756 | 1324 | /** @defgroup I2C_Group7 Interrupts and flags management functions |
mbed_official | 76:aeb1df146756 | 1325 | * @brief Interrupts and flags management functions |
mbed_official | 76:aeb1df146756 | 1326 | * |
mbed_official | 76:aeb1df146756 | 1327 | @verbatim |
mbed_official | 76:aeb1df146756 | 1328 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 1329 | ##### Interrupts and flags management functions ##### |
mbed_official | 76:aeb1df146756 | 1330 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 1331 | [..] This section provides functions allowing to configure the I2C Interrupts |
mbed_official | 76:aeb1df146756 | 1332 | sources and check or clear the flags or pending bits status. |
mbed_official | 76:aeb1df146756 | 1333 | The user should identify which mode will be used in his application to manage |
mbed_official | 76:aeb1df146756 | 1334 | the communication: Polling mode, Interrupt mode or DMA mode(refer I2C_Group6). |
mbed_official | 76:aeb1df146756 | 1335 | |
mbed_official | 76:aeb1df146756 | 1336 | *** Polling Mode *** |
mbed_official | 76:aeb1df146756 | 1337 | ==================== |
mbed_official | 76:aeb1df146756 | 1338 | [..] In Polling Mode, the I2C communication can be managed by 15 flags: |
mbed_official | 76:aeb1df146756 | 1339 | (#) I2C_FLAG_TXE: to indicate the status of Transmit data register empty flag. |
mbed_official | 76:aeb1df146756 | 1340 | (#) I2C_FLAG_TXIS: to indicate the status of Transmit interrupt status flag . |
mbed_official | 76:aeb1df146756 | 1341 | (#) I2C_FLAG_RXNE: to indicate the status of Receive data register not empty flag. |
mbed_official | 76:aeb1df146756 | 1342 | (#) I2C_FLAG_ADDR: to indicate the status of Address matched flag (slave mode). |
mbed_official | 76:aeb1df146756 | 1343 | (#) I2C_FLAG_NACKF: to indicate the status of NACK received flag. |
mbed_official | 76:aeb1df146756 | 1344 | (#) I2C_FLAG_STOPF: to indicate the status of STOP detection flag. |
mbed_official | 76:aeb1df146756 | 1345 | (#) I2C_FLAG_TC: to indicate the status of Transfer complete flag(master mode). |
mbed_official | 76:aeb1df146756 | 1346 | (#) I2C_FLAG_TCR: to indicate the status of Transfer complete reload flag. |
mbed_official | 76:aeb1df146756 | 1347 | (#) I2C_FLAG_BERR: to indicate the status of Bus error flag. |
mbed_official | 76:aeb1df146756 | 1348 | (#) I2C_FLAG_ARLO: to indicate the status of Arbitration lost flag. |
mbed_official | 76:aeb1df146756 | 1349 | (#) I2C_FLAG_OVR: to indicate the status of Overrun/Underrun flag. |
mbed_official | 76:aeb1df146756 | 1350 | (#) I2C_FLAG_PECERR: to indicate the status of PEC error in reception flag. |
mbed_official | 76:aeb1df146756 | 1351 | (#) I2C_FLAG_TIMEOUT: to indicate the status of Timeout or Tlow detection flag. |
mbed_official | 76:aeb1df146756 | 1352 | (#) I2C_FLAG_ALERT: to indicate the status of SMBus Alert flag. |
mbed_official | 76:aeb1df146756 | 1353 | (#) I2C_FLAG_BUSY: to indicate the status of Bus busy flag. |
mbed_official | 76:aeb1df146756 | 1354 | |
mbed_official | 76:aeb1df146756 | 1355 | [..] In this Mode it is advised to use the following functions: |
mbed_official | 76:aeb1df146756 | 1356 | (+) FlagStatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG); |
mbed_official | 76:aeb1df146756 | 1357 | (+) void I2C_ClearFlag(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG); |
mbed_official | 76:aeb1df146756 | 1358 | |
mbed_official | 76:aeb1df146756 | 1359 | [..] |
mbed_official | 76:aeb1df146756 | 1360 | (@)Do not use the BUSY flag to handle each data transmission or reception.It is |
mbed_official | 76:aeb1df146756 | 1361 | better to use the TXIS and RXNE flags instead. |
mbed_official | 76:aeb1df146756 | 1362 | |
mbed_official | 76:aeb1df146756 | 1363 | *** Interrupt Mode *** |
mbed_official | 76:aeb1df146756 | 1364 | ====================== |
mbed_official | 76:aeb1df146756 | 1365 | [..] In Interrupt Mode, the I2C communication can be managed by 7 interrupt sources |
mbed_official | 76:aeb1df146756 | 1366 | and 15 pending bits: |
mbed_official | 76:aeb1df146756 | 1367 | [..] Interrupt Source: |
mbed_official | 76:aeb1df146756 | 1368 | (#) I2C_IT_ERRI: specifies the interrupt source for the Error interrupt. |
mbed_official | 76:aeb1df146756 | 1369 | (#) I2C_IT_TCI: specifies the interrupt source for the Transfer Complete interrupt. |
mbed_official | 76:aeb1df146756 | 1370 | (#) I2C_IT_STOPI: specifies the interrupt source for the Stop Detection interrupt. |
mbed_official | 76:aeb1df146756 | 1371 | (#) I2C_IT_NACKI: specifies the interrupt source for the Not Acknowledge received interrupt. |
mbed_official | 76:aeb1df146756 | 1372 | (#) I2C_IT_ADDRI: specifies the interrupt source for the Address Match interrupt. |
mbed_official | 76:aeb1df146756 | 1373 | (#) I2C_IT_RXI: specifies the interrupt source for the RX interrupt. |
mbed_official | 76:aeb1df146756 | 1374 | (#) I2C_IT_TXI: specifies the interrupt source for the TX interrupt. |
mbed_official | 76:aeb1df146756 | 1375 | |
mbed_official | 76:aeb1df146756 | 1376 | [..] Pending Bits: |
mbed_official | 76:aeb1df146756 | 1377 | (#) I2C_IT_TXIS: to indicate the status of Transmit interrupt status flag. |
mbed_official | 76:aeb1df146756 | 1378 | (#) I2C_IT_RXNE: to indicate the status of Receive data register not empty flag. |
mbed_official | 76:aeb1df146756 | 1379 | (#) I2C_IT_ADDR: to indicate the status of Address matched flag (slave mode). |
mbed_official | 76:aeb1df146756 | 1380 | (#) I2C_IT_NACKF: to indicate the status of NACK received flag. |
mbed_official | 76:aeb1df146756 | 1381 | (#) I2C_IT_STOPF: to indicate the status of STOP detection flag. |
mbed_official | 76:aeb1df146756 | 1382 | (#) I2C_IT_TC: to indicate the status of Transfer complete flag (master mode). |
mbed_official | 76:aeb1df146756 | 1383 | (#) I2C_IT_TCR: to indicate the status of Transfer complete reload flag. |
mbed_official | 76:aeb1df146756 | 1384 | (#) I2C_IT_BERR: to indicate the status of Bus error flag. |
mbed_official | 76:aeb1df146756 | 1385 | (#) I2C_IT_ARLO: to indicate the status of Arbitration lost flag. |
mbed_official | 76:aeb1df146756 | 1386 | (#) I2C_IT_OVR: to indicate the status of Overrun/Underrun flag. |
mbed_official | 76:aeb1df146756 | 1387 | (#) I2C_IT_PECERR: to indicate the status of PEC error in reception flag. |
mbed_official | 76:aeb1df146756 | 1388 | (#) I2C_IT_TIMEOUT: to indicate the status of Timeout or Tlow detection flag. |
mbed_official | 76:aeb1df146756 | 1389 | (#) I2C_IT_ALERT: to indicate the status of SMBus Alert flag. |
mbed_official | 76:aeb1df146756 | 1390 | |
mbed_official | 76:aeb1df146756 | 1391 | [..] In this Mode it is advised to use the following functions: |
mbed_official | 76:aeb1df146756 | 1392 | (+) void I2C_ClearITPendingBit(I2C_TypeDef* I2Cx, uint32_t I2C_IT); |
mbed_official | 76:aeb1df146756 | 1393 | (+) ITStatus I2C_GetITStatus(I2C_TypeDef* I2Cx, uint32_t I2C_IT); |
mbed_official | 76:aeb1df146756 | 1394 | |
mbed_official | 76:aeb1df146756 | 1395 | @endverbatim |
mbed_official | 76:aeb1df146756 | 1396 | * @{ |
mbed_official | 76:aeb1df146756 | 1397 | */ |
mbed_official | 76:aeb1df146756 | 1398 | |
mbed_official | 76:aeb1df146756 | 1399 | /** |
mbed_official | 76:aeb1df146756 | 1400 | * @brief Checks whether the specified I2C flag is set or not. |
mbed_official | 76:aeb1df146756 | 1401 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 1402 | * @param I2C_FLAG: specifies the flag to check. |
mbed_official | 76:aeb1df146756 | 1403 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 1404 | * @arg I2C_FLAG_TXE: Transmit data register empty |
mbed_official | 76:aeb1df146756 | 1405 | * @arg I2C_FLAG_TXIS: Transmit interrupt status |
mbed_official | 76:aeb1df146756 | 1406 | * @arg I2C_FLAG_RXNE: Receive data register not empty |
mbed_official | 76:aeb1df146756 | 1407 | * @arg I2C_FLAG_ADDR: Address matched (slave mode) |
mbed_official | 76:aeb1df146756 | 1408 | * @arg I2C_FLAG_NACKF: NACK received flag |
mbed_official | 76:aeb1df146756 | 1409 | * @arg I2C_FLAG_STOPF: STOP detection flag |
mbed_official | 76:aeb1df146756 | 1410 | * @arg I2C_FLAG_TC: Transfer complete (master mode) |
mbed_official | 76:aeb1df146756 | 1411 | * @arg I2C_FLAG_TCR: Transfer complete reload |
mbed_official | 76:aeb1df146756 | 1412 | * @arg I2C_FLAG_BERR: Bus error |
mbed_official | 76:aeb1df146756 | 1413 | * @arg I2C_FLAG_ARLO: Arbitration lost |
mbed_official | 76:aeb1df146756 | 1414 | * @arg I2C_FLAG_OVR: Overrun/Underrun |
mbed_official | 76:aeb1df146756 | 1415 | * @arg I2C_FLAG_PECERR: PEC error in reception |
mbed_official | 76:aeb1df146756 | 1416 | * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow detection flag |
mbed_official | 76:aeb1df146756 | 1417 | * @arg I2C_FLAG_ALERT: SMBus Alert |
mbed_official | 76:aeb1df146756 | 1418 | * @arg I2C_FLAG_BUSY: Bus busy |
mbed_official | 76:aeb1df146756 | 1419 | * @retval The new state of I2C_FLAG (SET or RESET). |
mbed_official | 76:aeb1df146756 | 1420 | */ |
mbed_official | 76:aeb1df146756 | 1421 | FlagStatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG) |
mbed_official | 76:aeb1df146756 | 1422 | { |
mbed_official | 76:aeb1df146756 | 1423 | uint32_t tmpreg = 0; |
mbed_official | 76:aeb1df146756 | 1424 | FlagStatus bitstatus = RESET; |
mbed_official | 76:aeb1df146756 | 1425 | |
mbed_official | 76:aeb1df146756 | 1426 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1427 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 1428 | assert_param(IS_I2C_GET_FLAG(I2C_FLAG)); |
mbed_official | 76:aeb1df146756 | 1429 | |
mbed_official | 76:aeb1df146756 | 1430 | /* Get the ISR register value */ |
mbed_official | 76:aeb1df146756 | 1431 | tmpreg = I2Cx->ISR; |
mbed_official | 76:aeb1df146756 | 1432 | |
mbed_official | 76:aeb1df146756 | 1433 | /* Get flag status */ |
mbed_official | 76:aeb1df146756 | 1434 | tmpreg &= I2C_FLAG; |
mbed_official | 76:aeb1df146756 | 1435 | |
mbed_official | 76:aeb1df146756 | 1436 | if(tmpreg != 0) |
mbed_official | 76:aeb1df146756 | 1437 | { |
mbed_official | 76:aeb1df146756 | 1438 | /* I2C_FLAG is set */ |
mbed_official | 76:aeb1df146756 | 1439 | bitstatus = SET; |
mbed_official | 76:aeb1df146756 | 1440 | } |
mbed_official | 76:aeb1df146756 | 1441 | else |
mbed_official | 76:aeb1df146756 | 1442 | { |
mbed_official | 76:aeb1df146756 | 1443 | /* I2C_FLAG is reset */ |
mbed_official | 76:aeb1df146756 | 1444 | bitstatus = RESET; |
mbed_official | 76:aeb1df146756 | 1445 | } |
mbed_official | 76:aeb1df146756 | 1446 | return bitstatus; |
mbed_official | 76:aeb1df146756 | 1447 | } |
mbed_official | 76:aeb1df146756 | 1448 | |
mbed_official | 76:aeb1df146756 | 1449 | /** |
mbed_official | 76:aeb1df146756 | 1450 | * @brief Clears the I2Cx's pending flags. |
mbed_official | 76:aeb1df146756 | 1451 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 1452 | * @param I2C_FLAG: specifies the flag to clear. |
mbed_official | 76:aeb1df146756 | 1453 | * This parameter can be any combination of the following values: |
mbed_official | 76:aeb1df146756 | 1454 | * @arg I2C_FLAG_ADDR: Address matched (slave mode) |
mbed_official | 76:aeb1df146756 | 1455 | * @arg I2C_FLAG_NACKF: NACK received flag |
mbed_official | 76:aeb1df146756 | 1456 | * @arg I2C_FLAG_STOPF: STOP detection flag |
mbed_official | 76:aeb1df146756 | 1457 | * @arg I2C_FLAG_BERR: Bus error |
mbed_official | 76:aeb1df146756 | 1458 | * @arg I2C_FLAG_ARLO: Arbitration lost |
mbed_official | 76:aeb1df146756 | 1459 | * @arg I2C_FLAG_OVR: Overrun/Underrun |
mbed_official | 76:aeb1df146756 | 1460 | * @arg I2C_FLAG_PECERR: PEC error in reception |
mbed_official | 76:aeb1df146756 | 1461 | * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow detection flag |
mbed_official | 76:aeb1df146756 | 1462 | * @arg I2C_FLAG_ALERT: SMBus Alert |
mbed_official | 76:aeb1df146756 | 1463 | * @retval The new state of I2C_FLAG (SET or RESET). |
mbed_official | 76:aeb1df146756 | 1464 | */ |
mbed_official | 76:aeb1df146756 | 1465 | void I2C_ClearFlag(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG) |
mbed_official | 76:aeb1df146756 | 1466 | { |
mbed_official | 76:aeb1df146756 | 1467 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1468 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 1469 | assert_param(IS_I2C_CLEAR_FLAG(I2C_FLAG)); |
mbed_official | 76:aeb1df146756 | 1470 | |
mbed_official | 76:aeb1df146756 | 1471 | /* Clear the selected flag */ |
mbed_official | 76:aeb1df146756 | 1472 | I2Cx->ICR = I2C_FLAG; |
mbed_official | 76:aeb1df146756 | 1473 | } |
mbed_official | 76:aeb1df146756 | 1474 | |
mbed_official | 76:aeb1df146756 | 1475 | /** |
mbed_official | 76:aeb1df146756 | 1476 | * @brief Checks whether the specified I2C interrupt has occurred or not. |
mbed_official | 76:aeb1df146756 | 1477 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 1478 | * @param I2C_IT: specifies the interrupt source to check. |
mbed_official | 76:aeb1df146756 | 1479 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 1480 | * @arg I2C_IT_TXIS: Transmit interrupt status |
mbed_official | 76:aeb1df146756 | 1481 | * @arg I2C_IT_RXNE: Receive data register not empty |
mbed_official | 76:aeb1df146756 | 1482 | * @arg I2C_IT_ADDR: Address matched (slave mode) |
mbed_official | 76:aeb1df146756 | 1483 | * @arg I2C_IT_NACKF: NACK received flag |
mbed_official | 76:aeb1df146756 | 1484 | * @arg I2C_IT_STOPF: STOP detection flag |
mbed_official | 76:aeb1df146756 | 1485 | * @arg I2C_IT_TC: Transfer complete (master mode) |
mbed_official | 76:aeb1df146756 | 1486 | * @arg I2C_IT_TCR: Transfer complete reload |
mbed_official | 76:aeb1df146756 | 1487 | * @arg I2C_IT_BERR: Bus error |
mbed_official | 76:aeb1df146756 | 1488 | * @arg I2C_IT_ARLO: Arbitration lost |
mbed_official | 76:aeb1df146756 | 1489 | * @arg I2C_IT_OVR: Overrun/Underrun |
mbed_official | 76:aeb1df146756 | 1490 | * @arg I2C_IT_PECERR: PEC error in reception |
mbed_official | 76:aeb1df146756 | 1491 | * @arg I2C_IT_TIMEOUT: Timeout or Tlow detection flag |
mbed_official | 76:aeb1df146756 | 1492 | * @arg I2C_IT_ALERT: SMBus Alert |
mbed_official | 76:aeb1df146756 | 1493 | * @retval The new state of I2C_IT (SET or RESET). |
mbed_official | 76:aeb1df146756 | 1494 | */ |
mbed_official | 76:aeb1df146756 | 1495 | ITStatus I2C_GetITStatus(I2C_TypeDef* I2Cx, uint32_t I2C_IT) |
mbed_official | 76:aeb1df146756 | 1496 | { |
mbed_official | 76:aeb1df146756 | 1497 | uint32_t tmpreg = 0; |
mbed_official | 76:aeb1df146756 | 1498 | ITStatus bitstatus = RESET; |
mbed_official | 76:aeb1df146756 | 1499 | uint32_t enablestatus = 0; |
mbed_official | 76:aeb1df146756 | 1500 | |
mbed_official | 76:aeb1df146756 | 1501 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1502 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 1503 | assert_param(IS_I2C_GET_IT(I2C_IT)); |
mbed_official | 76:aeb1df146756 | 1504 | |
mbed_official | 76:aeb1df146756 | 1505 | /* Check if the interrupt source is enabled or not */ |
mbed_official | 76:aeb1df146756 | 1506 | /* If Error interrupt */ |
mbed_official | 76:aeb1df146756 | 1507 | if ((uint32_t)(I2C_IT & ERROR_IT_MASK)) |
mbed_official | 76:aeb1df146756 | 1508 | { |
mbed_official | 76:aeb1df146756 | 1509 | enablestatus = (uint32_t)((I2C_CR1_ERRIE) & (I2Cx->CR1)); |
mbed_official | 76:aeb1df146756 | 1510 | } |
mbed_official | 76:aeb1df146756 | 1511 | /* If TC interrupt */ |
mbed_official | 76:aeb1df146756 | 1512 | else if ((uint32_t)(I2C_IT & TC_IT_MASK)) |
mbed_official | 76:aeb1df146756 | 1513 | { |
mbed_official | 76:aeb1df146756 | 1514 | enablestatus = (uint32_t)((I2C_CR1_TCIE) & (I2Cx->CR1)); |
mbed_official | 76:aeb1df146756 | 1515 | } |
mbed_official | 76:aeb1df146756 | 1516 | else |
mbed_official | 76:aeb1df146756 | 1517 | { |
mbed_official | 76:aeb1df146756 | 1518 | enablestatus = (uint32_t)((I2C_IT) & (I2Cx->CR1)); |
mbed_official | 76:aeb1df146756 | 1519 | } |
mbed_official | 76:aeb1df146756 | 1520 | |
mbed_official | 76:aeb1df146756 | 1521 | /* Get the ISR register value */ |
mbed_official | 76:aeb1df146756 | 1522 | tmpreg = I2Cx->ISR; |
mbed_official | 76:aeb1df146756 | 1523 | |
mbed_official | 76:aeb1df146756 | 1524 | /* Get flag status */ |
mbed_official | 76:aeb1df146756 | 1525 | tmpreg &= I2C_IT; |
mbed_official | 76:aeb1df146756 | 1526 | |
mbed_official | 76:aeb1df146756 | 1527 | /* Check the status of the specified I2C flag */ |
mbed_official | 76:aeb1df146756 | 1528 | if((tmpreg != RESET) && enablestatus) |
mbed_official | 76:aeb1df146756 | 1529 | { |
mbed_official | 76:aeb1df146756 | 1530 | /* I2C_IT is set */ |
mbed_official | 76:aeb1df146756 | 1531 | bitstatus = SET; |
mbed_official | 76:aeb1df146756 | 1532 | } |
mbed_official | 76:aeb1df146756 | 1533 | else |
mbed_official | 76:aeb1df146756 | 1534 | { |
mbed_official | 76:aeb1df146756 | 1535 | /* I2C_IT is reset */ |
mbed_official | 76:aeb1df146756 | 1536 | bitstatus = RESET; |
mbed_official | 76:aeb1df146756 | 1537 | } |
mbed_official | 76:aeb1df146756 | 1538 | |
mbed_official | 76:aeb1df146756 | 1539 | /* Return the I2C_IT status */ |
mbed_official | 76:aeb1df146756 | 1540 | return bitstatus; |
mbed_official | 76:aeb1df146756 | 1541 | } |
mbed_official | 76:aeb1df146756 | 1542 | |
mbed_official | 76:aeb1df146756 | 1543 | /** |
mbed_official | 76:aeb1df146756 | 1544 | * @brief Clears the I2Cx's interrupt pending bits. |
mbed_official | 76:aeb1df146756 | 1545 | * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. |
mbed_official | 76:aeb1df146756 | 1546 | * @param I2C_IT: specifies the interrupt pending bit to clear. |
mbed_official | 76:aeb1df146756 | 1547 | * This parameter can be any combination of the following values: |
mbed_official | 76:aeb1df146756 | 1548 | * @arg I2C_IT_ADDR: Address matched (slave mode) |
mbed_official | 76:aeb1df146756 | 1549 | * @arg I2C_IT_NACKF: NACK received flag |
mbed_official | 76:aeb1df146756 | 1550 | * @arg I2C_IT_STOPF: STOP detection flag |
mbed_official | 76:aeb1df146756 | 1551 | * @arg I2C_IT_BERR: Bus error |
mbed_official | 76:aeb1df146756 | 1552 | * @arg I2C_IT_ARLO: Arbitration lost |
mbed_official | 76:aeb1df146756 | 1553 | * @arg I2C_IT_OVR: Overrun/Underrun |
mbed_official | 76:aeb1df146756 | 1554 | * @arg I2C_IT_PECERR: PEC error in reception |
mbed_official | 76:aeb1df146756 | 1555 | * @arg I2C_IT_TIMEOUT: Timeout or Tlow detection flag |
mbed_official | 76:aeb1df146756 | 1556 | * @arg I2C_IT_ALERT: SMBus Alert |
mbed_official | 76:aeb1df146756 | 1557 | * @retval The new state of I2C_IT (SET or RESET). |
mbed_official | 76:aeb1df146756 | 1558 | */ |
mbed_official | 76:aeb1df146756 | 1559 | void I2C_ClearITPendingBit(I2C_TypeDef* I2Cx, uint32_t I2C_IT) |
mbed_official | 76:aeb1df146756 | 1560 | { |
mbed_official | 76:aeb1df146756 | 1561 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 1562 | assert_param(IS_I2C_ALL_PERIPH(I2Cx)); |
mbed_official | 76:aeb1df146756 | 1563 | assert_param(IS_I2C_CLEAR_IT(I2C_IT)); |
mbed_official | 76:aeb1df146756 | 1564 | |
mbed_official | 76:aeb1df146756 | 1565 | /* Clear the selected flag */ |
mbed_official | 76:aeb1df146756 | 1566 | I2Cx->ICR = I2C_IT; |
mbed_official | 76:aeb1df146756 | 1567 | } |
mbed_official | 76:aeb1df146756 | 1568 | |
mbed_official | 76:aeb1df146756 | 1569 | /** |
mbed_official | 76:aeb1df146756 | 1570 | * @} |
mbed_official | 76:aeb1df146756 | 1571 | */ |
mbed_official | 76:aeb1df146756 | 1572 | |
mbed_official | 76:aeb1df146756 | 1573 | /** |
mbed_official | 76:aeb1df146756 | 1574 | * @} |
mbed_official | 76:aeb1df146756 | 1575 | */ |
mbed_official | 76:aeb1df146756 | 1576 | |
mbed_official | 76:aeb1df146756 | 1577 | /** |
mbed_official | 76:aeb1df146756 | 1578 | * @} |
mbed_official | 76:aeb1df146756 | 1579 | */ |
mbed_official | 76:aeb1df146756 | 1580 | |
mbed_official | 76:aeb1df146756 | 1581 | /** |
mbed_official | 76:aeb1df146756 | 1582 | * @} |
mbed_official | 76:aeb1df146756 | 1583 | */ |
mbed_official | 76:aeb1df146756 | 1584 | |
mbed_official | 76:aeb1df146756 | 1585 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |