mbed library with additional peripherals for ST F401 board

Fork of mbed-src by mbed official

This mbed LIB has additional peripherals for ST F401 board

  • UART2 : PA_3 rx, PA_2 tx
  • UART3 : PC_7 rx, PC_6 tx
  • I2C2 : PB_3 SDA, PB_10 SCL
  • I2C3 : PB_4 SDA, PA_8 SCL
Committer:
mbed_official
Date:
Wed Feb 26 09:45:12 2014 +0000
Revision:
106:ced8cbb51063
Parent:
76:aeb1df146756
Synchronized with git revision 4222735eff5868389433f0e9271976b39c8115cd

Full URL: https://github.com/mbedmicro/mbed/commit/4222735eff5868389433f0e9271976b39c8115cd/

[NUCLEO_xxx] Update STM32CubeF4 driver V1.0.0 + update license

Who changed what in which revision?

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