mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Dec 02 11:30:05 2013 +0000
Revision:
52:a51c77007319
Child:
70:c1fbde68b492
Synchronized with git revision 49df530ae72ce97ccc773d1f2c13b38e868e6abd

Full URL: https://github.com/mbedmicro/mbed/commit/49df530ae72ce97ccc773d1f2c13b38e868e6abd/

Add STMicroelectronics NUCLEO_F103RB target

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 52:a51c77007319 1 /**
mbed_official 52:a51c77007319 2 ******************************************************************************
mbed_official 52:a51c77007319 3 * @file stm32f10x_i2c.h
mbed_official 52:a51c77007319 4 * @author MCD Application Team
mbed_official 52:a51c77007319 5 * @version V3.5.0
mbed_official 52:a51c77007319 6 * @date 11-March-2011
mbed_official 52:a51c77007319 7 * @brief This file contains all the functions prototypes for the I2C firmware
mbed_official 52:a51c77007319 8 * library.
mbed_official 52:a51c77007319 9 ******************************************************************************
mbed_official 52:a51c77007319 10 * @attention
mbed_official 52:a51c77007319 11 *
mbed_official 52:a51c77007319 12 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
mbed_official 52:a51c77007319 13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
mbed_official 52:a51c77007319 14 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
mbed_official 52:a51c77007319 15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
mbed_official 52:a51c77007319 16 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
mbed_official 52:a51c77007319 17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
mbed_official 52:a51c77007319 18 *
mbed_official 52:a51c77007319 19 * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
mbed_official 52:a51c77007319 20 ******************************************************************************
mbed_official 52:a51c77007319 21 */
mbed_official 52:a51c77007319 22
mbed_official 52:a51c77007319 23 /* Define to prevent recursive inclusion -------------------------------------*/
mbed_official 52:a51c77007319 24 #ifndef __STM32F10x_I2C_H
mbed_official 52:a51c77007319 25 #define __STM32F10x_I2C_H
mbed_official 52:a51c77007319 26
mbed_official 52:a51c77007319 27 #ifdef __cplusplus
mbed_official 52:a51c77007319 28 extern "C" {
mbed_official 52:a51c77007319 29 #endif
mbed_official 52:a51c77007319 30
mbed_official 52:a51c77007319 31 /* Includes ------------------------------------------------------------------*/
mbed_official 52:a51c77007319 32 #include "stm32f10x.h"
mbed_official 52:a51c77007319 33
mbed_official 52:a51c77007319 34 /** @addtogroup STM32F10x_StdPeriph_Driver
mbed_official 52:a51c77007319 35 * @{
mbed_official 52:a51c77007319 36 */
mbed_official 52:a51c77007319 37
mbed_official 52:a51c77007319 38 /** @addtogroup I2C
mbed_official 52:a51c77007319 39 * @{
mbed_official 52:a51c77007319 40 */
mbed_official 52:a51c77007319 41
mbed_official 52:a51c77007319 42 /** @defgroup I2C_Exported_Types
mbed_official 52:a51c77007319 43 * @{
mbed_official 52:a51c77007319 44 */
mbed_official 52:a51c77007319 45
mbed_official 52:a51c77007319 46 /**
mbed_official 52:a51c77007319 47 * @brief I2C Init structure definition
mbed_official 52:a51c77007319 48 */
mbed_official 52:a51c77007319 49
mbed_official 52:a51c77007319 50 typedef struct
mbed_official 52:a51c77007319 51 {
mbed_official 52:a51c77007319 52 uint32_t I2C_ClockSpeed; /*!< Specifies the clock frequency.
mbed_official 52:a51c77007319 53 This parameter must be set to a value lower than 400kHz */
mbed_official 52:a51c77007319 54
mbed_official 52:a51c77007319 55 uint16_t I2C_Mode; /*!< Specifies the I2C mode.
mbed_official 52:a51c77007319 56 This parameter can be a value of @ref I2C_mode */
mbed_official 52:a51c77007319 57
mbed_official 52:a51c77007319 58 uint16_t I2C_DutyCycle; /*!< Specifies the I2C fast mode duty cycle.
mbed_official 52:a51c77007319 59 This parameter can be a value of @ref I2C_duty_cycle_in_fast_mode */
mbed_official 52:a51c77007319 60
mbed_official 52:a51c77007319 61 uint16_t I2C_OwnAddress1; /*!< Specifies the first device own address.
mbed_official 52:a51c77007319 62 This parameter can be a 7-bit or 10-bit address. */
mbed_official 52:a51c77007319 63
mbed_official 52:a51c77007319 64 uint16_t I2C_Ack; /*!< Enables or disables the acknowledgement.
mbed_official 52:a51c77007319 65 This parameter can be a value of @ref I2C_acknowledgement */
mbed_official 52:a51c77007319 66
mbed_official 52:a51c77007319 67 uint16_t I2C_AcknowledgedAddress; /*!< Specifies if 7-bit or 10-bit address is acknowledged.
mbed_official 52:a51c77007319 68 This parameter can be a value of @ref I2C_acknowledged_address */
mbed_official 52:a51c77007319 69 }I2C_InitTypeDef;
mbed_official 52:a51c77007319 70
mbed_official 52:a51c77007319 71 /**
mbed_official 52:a51c77007319 72 * @}
mbed_official 52:a51c77007319 73 */
mbed_official 52:a51c77007319 74
mbed_official 52:a51c77007319 75
mbed_official 52:a51c77007319 76 /** @defgroup I2C_Exported_Constants
mbed_official 52:a51c77007319 77 * @{
mbed_official 52:a51c77007319 78 */
mbed_official 52:a51c77007319 79
mbed_official 52:a51c77007319 80 #define IS_I2C_ALL_PERIPH(PERIPH) (((PERIPH) == I2C1) || \
mbed_official 52:a51c77007319 81 ((PERIPH) == I2C2))
mbed_official 52:a51c77007319 82 /** @defgroup I2C_mode
mbed_official 52:a51c77007319 83 * @{
mbed_official 52:a51c77007319 84 */
mbed_official 52:a51c77007319 85
mbed_official 52:a51c77007319 86 #define I2C_Mode_I2C ((uint16_t)0x0000)
mbed_official 52:a51c77007319 87 #define I2C_Mode_SMBusDevice ((uint16_t)0x0002)
mbed_official 52:a51c77007319 88 #define I2C_Mode_SMBusHost ((uint16_t)0x000A)
mbed_official 52:a51c77007319 89 #define IS_I2C_MODE(MODE) (((MODE) == I2C_Mode_I2C) || \
mbed_official 52:a51c77007319 90 ((MODE) == I2C_Mode_SMBusDevice) || \
mbed_official 52:a51c77007319 91 ((MODE) == I2C_Mode_SMBusHost))
mbed_official 52:a51c77007319 92 /**
mbed_official 52:a51c77007319 93 * @}
mbed_official 52:a51c77007319 94 */
mbed_official 52:a51c77007319 95
mbed_official 52:a51c77007319 96 /** @defgroup I2C_duty_cycle_in_fast_mode
mbed_official 52:a51c77007319 97 * @{
mbed_official 52:a51c77007319 98 */
mbed_official 52:a51c77007319 99
mbed_official 52:a51c77007319 100 #define I2C_DutyCycle_16_9 ((uint16_t)0x4000) /*!< I2C fast mode Tlow/Thigh = 16/9 */
mbed_official 52:a51c77007319 101 #define I2C_DutyCycle_2 ((uint16_t)0xBFFF) /*!< I2C fast mode Tlow/Thigh = 2 */
mbed_official 52:a51c77007319 102 #define IS_I2C_DUTY_CYCLE(CYCLE) (((CYCLE) == I2C_DutyCycle_16_9) || \
mbed_official 52:a51c77007319 103 ((CYCLE) == I2C_DutyCycle_2))
mbed_official 52:a51c77007319 104 /**
mbed_official 52:a51c77007319 105 * @}
mbed_official 52:a51c77007319 106 */
mbed_official 52:a51c77007319 107
mbed_official 52:a51c77007319 108 /** @defgroup I2C_acknowledgement
mbed_official 52:a51c77007319 109 * @{
mbed_official 52:a51c77007319 110 */
mbed_official 52:a51c77007319 111
mbed_official 52:a51c77007319 112 #define I2C_Ack_Enable ((uint16_t)0x0400)
mbed_official 52:a51c77007319 113 #define I2C_Ack_Disable ((uint16_t)0x0000)
mbed_official 52:a51c77007319 114 #define IS_I2C_ACK_STATE(STATE) (((STATE) == I2C_Ack_Enable) || \
mbed_official 52:a51c77007319 115 ((STATE) == I2C_Ack_Disable))
mbed_official 52:a51c77007319 116 /**
mbed_official 52:a51c77007319 117 * @}
mbed_official 52:a51c77007319 118 */
mbed_official 52:a51c77007319 119
mbed_official 52:a51c77007319 120 /** @defgroup I2C_transfer_direction
mbed_official 52:a51c77007319 121 * @{
mbed_official 52:a51c77007319 122 */
mbed_official 52:a51c77007319 123
mbed_official 52:a51c77007319 124 #define I2C_Direction_Transmitter ((uint8_t)0x00)
mbed_official 52:a51c77007319 125 #define I2C_Direction_Receiver ((uint8_t)0x01)
mbed_official 52:a51c77007319 126 #define IS_I2C_DIRECTION(DIRECTION) (((DIRECTION) == I2C_Direction_Transmitter) || \
mbed_official 52:a51c77007319 127 ((DIRECTION) == I2C_Direction_Receiver))
mbed_official 52:a51c77007319 128 /**
mbed_official 52:a51c77007319 129 * @}
mbed_official 52:a51c77007319 130 */
mbed_official 52:a51c77007319 131
mbed_official 52:a51c77007319 132 /** @defgroup I2C_acknowledged_address
mbed_official 52:a51c77007319 133 * @{
mbed_official 52:a51c77007319 134 */
mbed_official 52:a51c77007319 135
mbed_official 52:a51c77007319 136 #define I2C_AcknowledgedAddress_7bit ((uint16_t)0x4000)
mbed_official 52:a51c77007319 137 #define I2C_AcknowledgedAddress_10bit ((uint16_t)0xC000)
mbed_official 52:a51c77007319 138 #define IS_I2C_ACKNOWLEDGE_ADDRESS(ADDRESS) (((ADDRESS) == I2C_AcknowledgedAddress_7bit) || \
mbed_official 52:a51c77007319 139 ((ADDRESS) == I2C_AcknowledgedAddress_10bit))
mbed_official 52:a51c77007319 140 /**
mbed_official 52:a51c77007319 141 * @}
mbed_official 52:a51c77007319 142 */
mbed_official 52:a51c77007319 143
mbed_official 52:a51c77007319 144 /** @defgroup I2C_registers
mbed_official 52:a51c77007319 145 * @{
mbed_official 52:a51c77007319 146 */
mbed_official 52:a51c77007319 147
mbed_official 52:a51c77007319 148 #define I2C_Register_CR1 ((uint8_t)0x00)
mbed_official 52:a51c77007319 149 #define I2C_Register_CR2 ((uint8_t)0x04)
mbed_official 52:a51c77007319 150 #define I2C_Register_OAR1 ((uint8_t)0x08)
mbed_official 52:a51c77007319 151 #define I2C_Register_OAR2 ((uint8_t)0x0C)
mbed_official 52:a51c77007319 152 #define I2C_Register_DR ((uint8_t)0x10)
mbed_official 52:a51c77007319 153 #define I2C_Register_SR1 ((uint8_t)0x14)
mbed_official 52:a51c77007319 154 #define I2C_Register_SR2 ((uint8_t)0x18)
mbed_official 52:a51c77007319 155 #define I2C_Register_CCR ((uint8_t)0x1C)
mbed_official 52:a51c77007319 156 #define I2C_Register_TRISE ((uint8_t)0x20)
mbed_official 52:a51c77007319 157 #define IS_I2C_REGISTER(REGISTER) (((REGISTER) == I2C_Register_CR1) || \
mbed_official 52:a51c77007319 158 ((REGISTER) == I2C_Register_CR2) || \
mbed_official 52:a51c77007319 159 ((REGISTER) == I2C_Register_OAR1) || \
mbed_official 52:a51c77007319 160 ((REGISTER) == I2C_Register_OAR2) || \
mbed_official 52:a51c77007319 161 ((REGISTER) == I2C_Register_DR) || \
mbed_official 52:a51c77007319 162 ((REGISTER) == I2C_Register_SR1) || \
mbed_official 52:a51c77007319 163 ((REGISTER) == I2C_Register_SR2) || \
mbed_official 52:a51c77007319 164 ((REGISTER) == I2C_Register_CCR) || \
mbed_official 52:a51c77007319 165 ((REGISTER) == I2C_Register_TRISE))
mbed_official 52:a51c77007319 166 /**
mbed_official 52:a51c77007319 167 * @}
mbed_official 52:a51c77007319 168 */
mbed_official 52:a51c77007319 169
mbed_official 52:a51c77007319 170 /** @defgroup I2C_SMBus_alert_pin_level
mbed_official 52:a51c77007319 171 * @{
mbed_official 52:a51c77007319 172 */
mbed_official 52:a51c77007319 173
mbed_official 52:a51c77007319 174 #define I2C_SMBusAlert_Low ((uint16_t)0x2000)
mbed_official 52:a51c77007319 175 #define I2C_SMBusAlert_High ((uint16_t)0xDFFF)
mbed_official 52:a51c77007319 176 #define IS_I2C_SMBUS_ALERT(ALERT) (((ALERT) == I2C_SMBusAlert_Low) || \
mbed_official 52:a51c77007319 177 ((ALERT) == I2C_SMBusAlert_High))
mbed_official 52:a51c77007319 178 /**
mbed_official 52:a51c77007319 179 * @}
mbed_official 52:a51c77007319 180 */
mbed_official 52:a51c77007319 181
mbed_official 52:a51c77007319 182 /** @defgroup I2C_PEC_position
mbed_official 52:a51c77007319 183 * @{
mbed_official 52:a51c77007319 184 */
mbed_official 52:a51c77007319 185
mbed_official 52:a51c77007319 186 #define I2C_PECPosition_Next ((uint16_t)0x0800)
mbed_official 52:a51c77007319 187 #define I2C_PECPosition_Current ((uint16_t)0xF7FF)
mbed_official 52:a51c77007319 188 #define IS_I2C_PEC_POSITION(POSITION) (((POSITION) == I2C_PECPosition_Next) || \
mbed_official 52:a51c77007319 189 ((POSITION) == I2C_PECPosition_Current))
mbed_official 52:a51c77007319 190 /**
mbed_official 52:a51c77007319 191 * @}
mbed_official 52:a51c77007319 192 */
mbed_official 52:a51c77007319 193
mbed_official 52:a51c77007319 194 /** @defgroup I2C_NCAK_position
mbed_official 52:a51c77007319 195 * @{
mbed_official 52:a51c77007319 196 */
mbed_official 52:a51c77007319 197
mbed_official 52:a51c77007319 198 #define I2C_NACKPosition_Next ((uint16_t)0x0800)
mbed_official 52:a51c77007319 199 #define I2C_NACKPosition_Current ((uint16_t)0xF7FF)
mbed_official 52:a51c77007319 200 #define IS_I2C_NACK_POSITION(POSITION) (((POSITION) == I2C_NACKPosition_Next) || \
mbed_official 52:a51c77007319 201 ((POSITION) == I2C_NACKPosition_Current))
mbed_official 52:a51c77007319 202 /**
mbed_official 52:a51c77007319 203 * @}
mbed_official 52:a51c77007319 204 */
mbed_official 52:a51c77007319 205
mbed_official 52:a51c77007319 206 /** @defgroup I2C_interrupts_definition
mbed_official 52:a51c77007319 207 * @{
mbed_official 52:a51c77007319 208 */
mbed_official 52:a51c77007319 209
mbed_official 52:a51c77007319 210 #define I2C_IT_BUF ((uint16_t)0x0400)
mbed_official 52:a51c77007319 211 #define I2C_IT_EVT ((uint16_t)0x0200)
mbed_official 52:a51c77007319 212 #define I2C_IT_ERR ((uint16_t)0x0100)
mbed_official 52:a51c77007319 213 #define IS_I2C_CONFIG_IT(IT) ((((IT) & (uint16_t)0xF8FF) == 0x00) && ((IT) != 0x00))
mbed_official 52:a51c77007319 214 /**
mbed_official 52:a51c77007319 215 * @}
mbed_official 52:a51c77007319 216 */
mbed_official 52:a51c77007319 217
mbed_official 52:a51c77007319 218 /** @defgroup I2C_interrupts_definition
mbed_official 52:a51c77007319 219 * @{
mbed_official 52:a51c77007319 220 */
mbed_official 52:a51c77007319 221
mbed_official 52:a51c77007319 222 #define I2C_IT_SMBALERT ((uint32_t)0x01008000)
mbed_official 52:a51c77007319 223 #define I2C_IT_TIMEOUT ((uint32_t)0x01004000)
mbed_official 52:a51c77007319 224 #define I2C_IT_PECERR ((uint32_t)0x01001000)
mbed_official 52:a51c77007319 225 #define I2C_IT_OVR ((uint32_t)0x01000800)
mbed_official 52:a51c77007319 226 #define I2C_IT_AF ((uint32_t)0x01000400)
mbed_official 52:a51c77007319 227 #define I2C_IT_ARLO ((uint32_t)0x01000200)
mbed_official 52:a51c77007319 228 #define I2C_IT_BERR ((uint32_t)0x01000100)
mbed_official 52:a51c77007319 229 #define I2C_IT_TXE ((uint32_t)0x06000080)
mbed_official 52:a51c77007319 230 #define I2C_IT_RXNE ((uint32_t)0x06000040)
mbed_official 52:a51c77007319 231 #define I2C_IT_STOPF ((uint32_t)0x02000010)
mbed_official 52:a51c77007319 232 #define I2C_IT_ADD10 ((uint32_t)0x02000008)
mbed_official 52:a51c77007319 233 #define I2C_IT_BTF ((uint32_t)0x02000004)
mbed_official 52:a51c77007319 234 #define I2C_IT_ADDR ((uint32_t)0x02000002)
mbed_official 52:a51c77007319 235 #define I2C_IT_SB ((uint32_t)0x02000001)
mbed_official 52:a51c77007319 236
mbed_official 52:a51c77007319 237 #define IS_I2C_CLEAR_IT(IT) ((((IT) & (uint16_t)0x20FF) == 0x00) && ((IT) != (uint16_t)0x00))
mbed_official 52:a51c77007319 238
mbed_official 52:a51c77007319 239 #define IS_I2C_GET_IT(IT) (((IT) == I2C_IT_SMBALERT) || ((IT) == I2C_IT_TIMEOUT) || \
mbed_official 52:a51c77007319 240 ((IT) == I2C_IT_PECERR) || ((IT) == I2C_IT_OVR) || \
mbed_official 52:a51c77007319 241 ((IT) == I2C_IT_AF) || ((IT) == I2C_IT_ARLO) || \
mbed_official 52:a51c77007319 242 ((IT) == I2C_IT_BERR) || ((IT) == I2C_IT_TXE) || \
mbed_official 52:a51c77007319 243 ((IT) == I2C_IT_RXNE) || ((IT) == I2C_IT_STOPF) || \
mbed_official 52:a51c77007319 244 ((IT) == I2C_IT_ADD10) || ((IT) == I2C_IT_BTF) || \
mbed_official 52:a51c77007319 245 ((IT) == I2C_IT_ADDR) || ((IT) == I2C_IT_SB))
mbed_official 52:a51c77007319 246 /**
mbed_official 52:a51c77007319 247 * @}
mbed_official 52:a51c77007319 248 */
mbed_official 52:a51c77007319 249
mbed_official 52:a51c77007319 250 /** @defgroup I2C_flags_definition
mbed_official 52:a51c77007319 251 * @{
mbed_official 52:a51c77007319 252 */
mbed_official 52:a51c77007319 253
mbed_official 52:a51c77007319 254 /**
mbed_official 52:a51c77007319 255 * @brief SR2 register flags
mbed_official 52:a51c77007319 256 */
mbed_official 52:a51c77007319 257
mbed_official 52:a51c77007319 258 #define I2C_FLAG_DUALF ((uint32_t)0x00800000)
mbed_official 52:a51c77007319 259 #define I2C_FLAG_SMBHOST ((uint32_t)0x00400000)
mbed_official 52:a51c77007319 260 #define I2C_FLAG_SMBDEFAULT ((uint32_t)0x00200000)
mbed_official 52:a51c77007319 261 #define I2C_FLAG_GENCALL ((uint32_t)0x00100000)
mbed_official 52:a51c77007319 262 #define I2C_FLAG_TRA ((uint32_t)0x00040000)
mbed_official 52:a51c77007319 263 #define I2C_FLAG_BUSY ((uint32_t)0x00020000)
mbed_official 52:a51c77007319 264 #define I2C_FLAG_MSL ((uint32_t)0x00010000)
mbed_official 52:a51c77007319 265
mbed_official 52:a51c77007319 266 /**
mbed_official 52:a51c77007319 267 * @brief SR1 register flags
mbed_official 52:a51c77007319 268 */
mbed_official 52:a51c77007319 269
mbed_official 52:a51c77007319 270 #define I2C_FLAG_SMBALERT ((uint32_t)0x10008000)
mbed_official 52:a51c77007319 271 #define I2C_FLAG_TIMEOUT ((uint32_t)0x10004000)
mbed_official 52:a51c77007319 272 #define I2C_FLAG_PECERR ((uint32_t)0x10001000)
mbed_official 52:a51c77007319 273 #define I2C_FLAG_OVR ((uint32_t)0x10000800)
mbed_official 52:a51c77007319 274 #define I2C_FLAG_AF ((uint32_t)0x10000400)
mbed_official 52:a51c77007319 275 #define I2C_FLAG_ARLO ((uint32_t)0x10000200)
mbed_official 52:a51c77007319 276 #define I2C_FLAG_BERR ((uint32_t)0x10000100)
mbed_official 52:a51c77007319 277 #define I2C_FLAG_TXE ((uint32_t)0x10000080)
mbed_official 52:a51c77007319 278 #define I2C_FLAG_RXNE ((uint32_t)0x10000040)
mbed_official 52:a51c77007319 279 #define I2C_FLAG_STOPF ((uint32_t)0x10000010)
mbed_official 52:a51c77007319 280 #define I2C_FLAG_ADD10 ((uint32_t)0x10000008)
mbed_official 52:a51c77007319 281 #define I2C_FLAG_BTF ((uint32_t)0x10000004)
mbed_official 52:a51c77007319 282 #define I2C_FLAG_ADDR ((uint32_t)0x10000002)
mbed_official 52:a51c77007319 283 #define I2C_FLAG_SB ((uint32_t)0x10000001)
mbed_official 52:a51c77007319 284
mbed_official 52:a51c77007319 285 #define IS_I2C_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0x20FF) == 0x00) && ((FLAG) != (uint16_t)0x00))
mbed_official 52:a51c77007319 286
mbed_official 52:a51c77007319 287 #define IS_I2C_GET_FLAG(FLAG) (((FLAG) == I2C_FLAG_DUALF) || ((FLAG) == I2C_FLAG_SMBHOST) || \
mbed_official 52:a51c77007319 288 ((FLAG) == I2C_FLAG_SMBDEFAULT) || ((FLAG) == I2C_FLAG_GENCALL) || \
mbed_official 52:a51c77007319 289 ((FLAG) == I2C_FLAG_TRA) || ((FLAG) == I2C_FLAG_BUSY) || \
mbed_official 52:a51c77007319 290 ((FLAG) == I2C_FLAG_MSL) || ((FLAG) == I2C_FLAG_SMBALERT) || \
mbed_official 52:a51c77007319 291 ((FLAG) == I2C_FLAG_TIMEOUT) || ((FLAG) == I2C_FLAG_PECERR) || \
mbed_official 52:a51c77007319 292 ((FLAG) == I2C_FLAG_OVR) || ((FLAG) == I2C_FLAG_AF) || \
mbed_official 52:a51c77007319 293 ((FLAG) == I2C_FLAG_ARLO) || ((FLAG) == I2C_FLAG_BERR) || \
mbed_official 52:a51c77007319 294 ((FLAG) == I2C_FLAG_TXE) || ((FLAG) == I2C_FLAG_RXNE) || \
mbed_official 52:a51c77007319 295 ((FLAG) == I2C_FLAG_STOPF) || ((FLAG) == I2C_FLAG_ADD10) || \
mbed_official 52:a51c77007319 296 ((FLAG) == I2C_FLAG_BTF) || ((FLAG) == I2C_FLAG_ADDR) || \
mbed_official 52:a51c77007319 297 ((FLAG) == I2C_FLAG_SB))
mbed_official 52:a51c77007319 298 /**
mbed_official 52:a51c77007319 299 * @}
mbed_official 52:a51c77007319 300 */
mbed_official 52:a51c77007319 301
mbed_official 52:a51c77007319 302 /** @defgroup I2C_Events
mbed_official 52:a51c77007319 303 * @{
mbed_official 52:a51c77007319 304 */
mbed_official 52:a51c77007319 305
mbed_official 52:a51c77007319 306 /*========================================
mbed_official 52:a51c77007319 307
mbed_official 52:a51c77007319 308 I2C Master Events (Events grouped in order of communication)
mbed_official 52:a51c77007319 309 ==========================================*/
mbed_official 52:a51c77007319 310 /**
mbed_official 52:a51c77007319 311 * @brief Communication start
mbed_official 52:a51c77007319 312 *
mbed_official 52:a51c77007319 313 * After sending the START condition (I2C_GenerateSTART() function) the master
mbed_official 52:a51c77007319 314 * has to wait for this event. It means that the Start condition has been correctly
mbed_official 52:a51c77007319 315 * released on the I2C bus (the bus is free, no other devices is communicating).
mbed_official 52:a51c77007319 316 *
mbed_official 52:a51c77007319 317 */
mbed_official 52:a51c77007319 318 /* --EV5 */
mbed_official 52:a51c77007319 319 #define I2C_EVENT_MASTER_MODE_SELECT ((uint32_t)0x00030001) /* BUSY, MSL and SB flag */
mbed_official 52:a51c77007319 320
mbed_official 52:a51c77007319 321 /**
mbed_official 52:a51c77007319 322 * @brief Address Acknowledge
mbed_official 52:a51c77007319 323 *
mbed_official 52:a51c77007319 324 * After checking on EV5 (start condition correctly released on the bus), the
mbed_official 52:a51c77007319 325 * master sends the address of the slave(s) with which it will communicate
mbed_official 52:a51c77007319 326 * (I2C_Send7bitAddress() function, it also determines the direction of the communication:
mbed_official 52:a51c77007319 327 * Master transmitter or Receiver). Then the master has to wait that a slave acknowledges
mbed_official 52:a51c77007319 328 * his address. If an acknowledge is sent on the bus, one of the following events will
mbed_official 52:a51c77007319 329 * be set:
mbed_official 52:a51c77007319 330 *
mbed_official 52:a51c77007319 331 * 1) In case of Master Receiver (7-bit addressing): the I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED
mbed_official 52:a51c77007319 332 * event is set.
mbed_official 52:a51c77007319 333 *
mbed_official 52:a51c77007319 334 * 2) In case of Master Transmitter (7-bit addressing): the I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED
mbed_official 52:a51c77007319 335 * is set
mbed_official 52:a51c77007319 336 *
mbed_official 52:a51c77007319 337 * 3) In case of 10-Bit addressing mode, the master (just after generating the START
mbed_official 52:a51c77007319 338 * and checking on EV5) has to send the header of 10-bit addressing mode (I2C_SendData()
mbed_official 52:a51c77007319 339 * function). Then master should wait on EV9. It means that the 10-bit addressing
mbed_official 52:a51c77007319 340 * header has been correctly sent on the bus. Then master should send the second part of
mbed_official 52:a51c77007319 341 * the 10-bit address (LSB) using the function I2C_Send7bitAddress(). Then master
mbed_official 52:a51c77007319 342 * should wait for event EV6.
mbed_official 52:a51c77007319 343 *
mbed_official 52:a51c77007319 344 */
mbed_official 52:a51c77007319 345
mbed_official 52:a51c77007319 346 /* --EV6 */
mbed_official 52:a51c77007319 347 #define I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED ((uint32_t)0x00070082) /* BUSY, MSL, ADDR, TXE and TRA flags */
mbed_official 52:a51c77007319 348 #define I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED ((uint32_t)0x00030002) /* BUSY, MSL and ADDR flags */
mbed_official 52:a51c77007319 349 /* --EV9 */
mbed_official 52:a51c77007319 350 #define I2C_EVENT_MASTER_MODE_ADDRESS10 ((uint32_t)0x00030008) /* BUSY, MSL and ADD10 flags */
mbed_official 52:a51c77007319 351
mbed_official 52:a51c77007319 352 /**
mbed_official 52:a51c77007319 353 * @brief Communication events
mbed_official 52:a51c77007319 354 *
mbed_official 52:a51c77007319 355 * If a communication is established (START condition generated and slave address
mbed_official 52:a51c77007319 356 * acknowledged) then the master has to check on one of the following events for
mbed_official 52:a51c77007319 357 * communication procedures:
mbed_official 52:a51c77007319 358 *
mbed_official 52:a51c77007319 359 * 1) Master Receiver mode: The master has to wait on the event EV7 then to read
mbed_official 52:a51c77007319 360 * the data received from the slave (I2C_ReceiveData() function).
mbed_official 52:a51c77007319 361 *
mbed_official 52:a51c77007319 362 * 2) Master Transmitter mode: The master has to send data (I2C_SendData()
mbed_official 52:a51c77007319 363 * function) then to wait on event EV8 or EV8_2.
mbed_official 52:a51c77007319 364 * These two events are similar:
mbed_official 52:a51c77007319 365 * - EV8 means that the data has been written in the data register and is
mbed_official 52:a51c77007319 366 * being shifted out.
mbed_official 52:a51c77007319 367 * - EV8_2 means that the data has been physically shifted out and output
mbed_official 52:a51c77007319 368 * on the bus.
mbed_official 52:a51c77007319 369 * In most cases, using EV8 is sufficient for the application.
mbed_official 52:a51c77007319 370 * Using EV8_2 leads to a slower communication but ensure more reliable test.
mbed_official 52:a51c77007319 371 * EV8_2 is also more suitable than EV8 for testing on the last data transmission
mbed_official 52:a51c77007319 372 * (before Stop condition generation).
mbed_official 52:a51c77007319 373 *
mbed_official 52:a51c77007319 374 * @note In case the user software does not guarantee that this event EV7 is
mbed_official 52:a51c77007319 375 * managed before the current byte end of transfer, then user may check on EV7
mbed_official 52:a51c77007319 376 * and BTF flag at the same time (ie. (I2C_EVENT_MASTER_BYTE_RECEIVED | I2C_FLAG_BTF)).
mbed_official 52:a51c77007319 377 * In this case the communication may be slower.
mbed_official 52:a51c77007319 378 *
mbed_official 52:a51c77007319 379 */
mbed_official 52:a51c77007319 380
mbed_official 52:a51c77007319 381 /* Master RECEIVER mode -----------------------------*/
mbed_official 52:a51c77007319 382 /* --EV7 */
mbed_official 52:a51c77007319 383 #define I2C_EVENT_MASTER_BYTE_RECEIVED ((uint32_t)0x00030040) /* BUSY, MSL and RXNE flags */
mbed_official 52:a51c77007319 384
mbed_official 52:a51c77007319 385 /* Master TRANSMITTER mode --------------------------*/
mbed_official 52:a51c77007319 386 /* --EV8 */
mbed_official 52:a51c77007319 387 #define I2C_EVENT_MASTER_BYTE_TRANSMITTING ((uint32_t)0x00070080) /* TRA, BUSY, MSL, TXE flags */
mbed_official 52:a51c77007319 388 /* --EV8_2 */
mbed_official 52:a51c77007319 389 #define I2C_EVENT_MASTER_BYTE_TRANSMITTED ((uint32_t)0x00070084) /* TRA, BUSY, MSL, TXE and BTF flags */
mbed_official 52:a51c77007319 390
mbed_official 52:a51c77007319 391
mbed_official 52:a51c77007319 392 /*========================================
mbed_official 52:a51c77007319 393
mbed_official 52:a51c77007319 394 I2C Slave Events (Events grouped in order of communication)
mbed_official 52:a51c77007319 395 ==========================================*/
mbed_official 52:a51c77007319 396
mbed_official 52:a51c77007319 397 /**
mbed_official 52:a51c77007319 398 * @brief Communication start events
mbed_official 52:a51c77007319 399 *
mbed_official 52:a51c77007319 400 * Wait on one of these events at the start of the communication. It means that
mbed_official 52:a51c77007319 401 * the I2C peripheral detected a Start condition on the bus (generated by master
mbed_official 52:a51c77007319 402 * device) followed by the peripheral address. The peripheral generates an ACK
mbed_official 52:a51c77007319 403 * condition on the bus (if the acknowledge feature is enabled through function
mbed_official 52:a51c77007319 404 * I2C_AcknowledgeConfig()) and the events listed above are set :
mbed_official 52:a51c77007319 405 *
mbed_official 52:a51c77007319 406 * 1) In normal case (only one address managed by the slave), when the address
mbed_official 52:a51c77007319 407 * sent by the master matches the own address of the peripheral (configured by
mbed_official 52:a51c77007319 408 * I2C_OwnAddress1 field) the I2C_EVENT_SLAVE_XXX_ADDRESS_MATCHED event is set
mbed_official 52:a51c77007319 409 * (where XXX could be TRANSMITTER or RECEIVER).
mbed_official 52:a51c77007319 410 *
mbed_official 52:a51c77007319 411 * 2) In case the address sent by the master matches the second address of the
mbed_official 52:a51c77007319 412 * peripheral (configured by the function I2C_OwnAddress2Config() and enabled
mbed_official 52:a51c77007319 413 * by the function I2C_DualAddressCmd()) the events I2C_EVENT_SLAVE_XXX_SECONDADDRESS_MATCHED
mbed_official 52:a51c77007319 414 * (where XXX could be TRANSMITTER or RECEIVER) are set.
mbed_official 52:a51c77007319 415 *
mbed_official 52:a51c77007319 416 * 3) In case the address sent by the master is General Call (address 0x00) and
mbed_official 52:a51c77007319 417 * if the General Call is enabled for the peripheral (using function I2C_GeneralCallCmd())
mbed_official 52:a51c77007319 418 * the following event is set I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED.
mbed_official 52:a51c77007319 419 *
mbed_official 52:a51c77007319 420 */
mbed_official 52:a51c77007319 421
mbed_official 52:a51c77007319 422 /* --EV1 (all the events below are variants of EV1) */
mbed_official 52:a51c77007319 423 /* 1) Case of One Single Address managed by the slave */
mbed_official 52:a51c77007319 424 #define I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED ((uint32_t)0x00020002) /* BUSY and ADDR flags */
mbed_official 52:a51c77007319 425 #define I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED ((uint32_t)0x00060082) /* TRA, BUSY, TXE and ADDR flags */
mbed_official 52:a51c77007319 426
mbed_official 52:a51c77007319 427 /* 2) Case of Dual address managed by the slave */
mbed_official 52:a51c77007319 428 #define I2C_EVENT_SLAVE_RECEIVER_SECONDADDRESS_MATCHED ((uint32_t)0x00820000) /* DUALF and BUSY flags */
mbed_official 52:a51c77007319 429 #define I2C_EVENT_SLAVE_TRANSMITTER_SECONDADDRESS_MATCHED ((uint32_t)0x00860080) /* DUALF, TRA, BUSY and TXE flags */
mbed_official 52:a51c77007319 430
mbed_official 52:a51c77007319 431 /* 3) Case of General Call enabled for the slave */
mbed_official 52:a51c77007319 432 #define I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED ((uint32_t)0x00120000) /* GENCALL and BUSY flags */
mbed_official 52:a51c77007319 433
mbed_official 52:a51c77007319 434 /**
mbed_official 52:a51c77007319 435 * @brief Communication events
mbed_official 52:a51c77007319 436 *
mbed_official 52:a51c77007319 437 * Wait on one of these events when EV1 has already been checked and:
mbed_official 52:a51c77007319 438 *
mbed_official 52:a51c77007319 439 * - Slave RECEIVER mode:
mbed_official 52:a51c77007319 440 * - EV2: When the application is expecting a data byte to be received.
mbed_official 52:a51c77007319 441 * - EV4: When the application is expecting the end of the communication: master
mbed_official 52:a51c77007319 442 * sends a stop condition and data transmission is stopped.
mbed_official 52:a51c77007319 443 *
mbed_official 52:a51c77007319 444 * - Slave Transmitter mode:
mbed_official 52:a51c77007319 445 * - EV3: When a byte has been transmitted by the slave and the application is expecting
mbed_official 52:a51c77007319 446 * the end of the byte transmission. The two events I2C_EVENT_SLAVE_BYTE_TRANSMITTED and
mbed_official 52:a51c77007319 447 * I2C_EVENT_SLAVE_BYTE_TRANSMITTING are similar. The second one can optionally be
mbed_official 52:a51c77007319 448 * used when the user software doesn't guarantee the EV3 is managed before the
mbed_official 52:a51c77007319 449 * current byte end of transfer.
mbed_official 52:a51c77007319 450 * - EV3_2: When the master sends a NACK in order to tell slave that data transmission
mbed_official 52:a51c77007319 451 * shall end (before sending the STOP condition). In this case slave has to stop sending
mbed_official 52:a51c77007319 452 * data bytes and expect a Stop condition on the bus.
mbed_official 52:a51c77007319 453 *
mbed_official 52:a51c77007319 454 * @note In case the user software does not guarantee that the event EV2 is
mbed_official 52:a51c77007319 455 * managed before the current byte end of transfer, then user may check on EV2
mbed_official 52:a51c77007319 456 * and BTF flag at the same time (ie. (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_BTF)).
mbed_official 52:a51c77007319 457 * In this case the communication may be slower.
mbed_official 52:a51c77007319 458 *
mbed_official 52:a51c77007319 459 */
mbed_official 52:a51c77007319 460
mbed_official 52:a51c77007319 461 /* Slave RECEIVER mode --------------------------*/
mbed_official 52:a51c77007319 462 /* --EV2 */
mbed_official 52:a51c77007319 463 #define I2C_EVENT_SLAVE_BYTE_RECEIVED ((uint32_t)0x00020040) /* BUSY and RXNE flags */
mbed_official 52:a51c77007319 464 /* --EV4 */
mbed_official 52:a51c77007319 465 #define I2C_EVENT_SLAVE_STOP_DETECTED ((uint32_t)0x00000010) /* STOPF flag */
mbed_official 52:a51c77007319 466
mbed_official 52:a51c77007319 467 /* Slave TRANSMITTER mode -----------------------*/
mbed_official 52:a51c77007319 468 /* --EV3 */
mbed_official 52:a51c77007319 469 #define I2C_EVENT_SLAVE_BYTE_TRANSMITTED ((uint32_t)0x00060084) /* TRA, BUSY, TXE and BTF flags */
mbed_official 52:a51c77007319 470 #define I2C_EVENT_SLAVE_BYTE_TRANSMITTING ((uint32_t)0x00060080) /* TRA, BUSY and TXE flags */
mbed_official 52:a51c77007319 471 /* --EV3_2 */
mbed_official 52:a51c77007319 472 #define I2C_EVENT_SLAVE_ACK_FAILURE ((uint32_t)0x00000400) /* AF flag */
mbed_official 52:a51c77007319 473
mbed_official 52:a51c77007319 474 /*=========================== End of Events Description ==========================================*/
mbed_official 52:a51c77007319 475
mbed_official 52:a51c77007319 476 #define IS_I2C_EVENT(EVENT) (((EVENT) == I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED) || \
mbed_official 52:a51c77007319 477 ((EVENT) == I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED) || \
mbed_official 52:a51c77007319 478 ((EVENT) == I2C_EVENT_SLAVE_TRANSMITTER_SECONDADDRESS_MATCHED) || \
mbed_official 52:a51c77007319 479 ((EVENT) == I2C_EVENT_SLAVE_RECEIVER_SECONDADDRESS_MATCHED) || \
mbed_official 52:a51c77007319 480 ((EVENT) == I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED) || \
mbed_official 52:a51c77007319 481 ((EVENT) == I2C_EVENT_SLAVE_BYTE_RECEIVED) || \
mbed_official 52:a51c77007319 482 ((EVENT) == (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_DUALF)) || \
mbed_official 52:a51c77007319 483 ((EVENT) == (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_GENCALL)) || \
mbed_official 52:a51c77007319 484 ((EVENT) == I2C_EVENT_SLAVE_BYTE_TRANSMITTED) || \
mbed_official 52:a51c77007319 485 ((EVENT) == (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_DUALF)) || \
mbed_official 52:a51c77007319 486 ((EVENT) == (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_GENCALL)) || \
mbed_official 52:a51c77007319 487 ((EVENT) == I2C_EVENT_SLAVE_STOP_DETECTED) || \
mbed_official 52:a51c77007319 488 ((EVENT) == I2C_EVENT_MASTER_MODE_SELECT) || \
mbed_official 52:a51c77007319 489 ((EVENT) == I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED) || \
mbed_official 52:a51c77007319 490 ((EVENT) == I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED) || \
mbed_official 52:a51c77007319 491 ((EVENT) == I2C_EVENT_MASTER_BYTE_RECEIVED) || \
mbed_official 52:a51c77007319 492 ((EVENT) == I2C_EVENT_MASTER_BYTE_TRANSMITTED) || \
mbed_official 52:a51c77007319 493 ((EVENT) == I2C_EVENT_MASTER_BYTE_TRANSMITTING) || \
mbed_official 52:a51c77007319 494 ((EVENT) == I2C_EVENT_MASTER_MODE_ADDRESS10) || \
mbed_official 52:a51c77007319 495 ((EVENT) == I2C_EVENT_SLAVE_ACK_FAILURE))
mbed_official 52:a51c77007319 496 /**
mbed_official 52:a51c77007319 497 * @}
mbed_official 52:a51c77007319 498 */
mbed_official 52:a51c77007319 499
mbed_official 52:a51c77007319 500 /** @defgroup I2C_own_address1
mbed_official 52:a51c77007319 501 * @{
mbed_official 52:a51c77007319 502 */
mbed_official 52:a51c77007319 503
mbed_official 52:a51c77007319 504 #define IS_I2C_OWN_ADDRESS1(ADDRESS1) ((ADDRESS1) <= 0x3FF)
mbed_official 52:a51c77007319 505 /**
mbed_official 52:a51c77007319 506 * @}
mbed_official 52:a51c77007319 507 */
mbed_official 52:a51c77007319 508
mbed_official 52:a51c77007319 509 /** @defgroup I2C_clock_speed
mbed_official 52:a51c77007319 510 * @{
mbed_official 52:a51c77007319 511 */
mbed_official 52:a51c77007319 512
mbed_official 52:a51c77007319 513 #define IS_I2C_CLOCK_SPEED(SPEED) (((SPEED) >= 0x1) && ((SPEED) <= 400000))
mbed_official 52:a51c77007319 514 /**
mbed_official 52:a51c77007319 515 * @}
mbed_official 52:a51c77007319 516 */
mbed_official 52:a51c77007319 517
mbed_official 52:a51c77007319 518 /**
mbed_official 52:a51c77007319 519 * @}
mbed_official 52:a51c77007319 520 */
mbed_official 52:a51c77007319 521
mbed_official 52:a51c77007319 522 /** @defgroup I2C_Exported_Macros
mbed_official 52:a51c77007319 523 * @{
mbed_official 52:a51c77007319 524 */
mbed_official 52:a51c77007319 525
mbed_official 52:a51c77007319 526 /**
mbed_official 52:a51c77007319 527 * @}
mbed_official 52:a51c77007319 528 */
mbed_official 52:a51c77007319 529
mbed_official 52:a51c77007319 530 /** @defgroup I2C_Exported_Functions
mbed_official 52:a51c77007319 531 * @{
mbed_official 52:a51c77007319 532 */
mbed_official 52:a51c77007319 533
mbed_official 52:a51c77007319 534 void I2C_DeInit(I2C_TypeDef* I2Cx);
mbed_official 52:a51c77007319 535 void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct);
mbed_official 52:a51c77007319 536 void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct);
mbed_official 52:a51c77007319 537 void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 52:a51c77007319 538 void I2C_DMACmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 52:a51c77007319 539 void I2C_DMALastTransferCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 52:a51c77007319 540 void I2C_GenerateSTART(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 52:a51c77007319 541 void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 52:a51c77007319 542 void I2C_AcknowledgeConfig(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 52:a51c77007319 543 void I2C_OwnAddress2Config(I2C_TypeDef* I2Cx, uint8_t Address);
mbed_official 52:a51c77007319 544 void I2C_DualAddressCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 52:a51c77007319 545 void I2C_GeneralCallCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 52:a51c77007319 546 void I2C_ITConfig(I2C_TypeDef* I2Cx, uint16_t I2C_IT, FunctionalState NewState);
mbed_official 52:a51c77007319 547 void I2C_SendData(I2C_TypeDef* I2Cx, uint8_t Data);
mbed_official 52:a51c77007319 548 uint8_t I2C_ReceiveData(I2C_TypeDef* I2Cx);
mbed_official 52:a51c77007319 549 void I2C_Send7bitAddress(I2C_TypeDef* I2Cx, uint8_t Address, uint8_t I2C_Direction);
mbed_official 52:a51c77007319 550 uint16_t I2C_ReadRegister(I2C_TypeDef* I2Cx, uint8_t I2C_Register);
mbed_official 52:a51c77007319 551 void I2C_SoftwareResetCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 52:a51c77007319 552 void I2C_NACKPositionConfig(I2C_TypeDef* I2Cx, uint16_t I2C_NACKPosition);
mbed_official 52:a51c77007319 553 void I2C_SMBusAlertConfig(I2C_TypeDef* I2Cx, uint16_t I2C_SMBusAlert);
mbed_official 52:a51c77007319 554 void I2C_TransmitPEC(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 52:a51c77007319 555 void I2C_PECPositionConfig(I2C_TypeDef* I2Cx, uint16_t I2C_PECPosition);
mbed_official 52:a51c77007319 556 void I2C_CalculatePEC(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 52:a51c77007319 557 uint8_t I2C_GetPEC(I2C_TypeDef* I2Cx);
mbed_official 52:a51c77007319 558 void I2C_ARPCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 52:a51c77007319 559 void I2C_StretchClockCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 52:a51c77007319 560 void I2C_FastModeDutyCycleConfig(I2C_TypeDef* I2Cx, uint16_t I2C_DutyCycle);
mbed_official 52:a51c77007319 561
mbed_official 52:a51c77007319 562 /**
mbed_official 52:a51c77007319 563 * @brief
mbed_official 52:a51c77007319 564 ****************************************************************************************
mbed_official 52:a51c77007319 565 *
mbed_official 52:a51c77007319 566 * I2C State Monitoring Functions
mbed_official 52:a51c77007319 567 *
mbed_official 52:a51c77007319 568 ****************************************************************************************
mbed_official 52:a51c77007319 569 * This I2C driver provides three different ways for I2C state monitoring
mbed_official 52:a51c77007319 570 * depending on the application requirements and constraints:
mbed_official 52:a51c77007319 571 *
mbed_official 52:a51c77007319 572 *
mbed_official 52:a51c77007319 573 * 1) Basic state monitoring:
mbed_official 52:a51c77007319 574 * Using I2C_CheckEvent() function:
mbed_official 52:a51c77007319 575 * It compares the status registers (SR1 and SR2) content to a given event
mbed_official 52:a51c77007319 576 * (can be the combination of one or more flags).
mbed_official 52:a51c77007319 577 * It returns SUCCESS if the current status includes the given flags
mbed_official 52:a51c77007319 578 * and returns ERROR if one or more flags are missing in the current status.
mbed_official 52:a51c77007319 579 * - When to use:
mbed_official 52:a51c77007319 580 * - This function is suitable for most applications as well as for startup
mbed_official 52:a51c77007319 581 * activity since the events are fully described in the product reference manual
mbed_official 52:a51c77007319 582 * (RM0008).
mbed_official 52:a51c77007319 583 * - It is also suitable for users who need to define their own events.
mbed_official 52:a51c77007319 584 * - Limitations:
mbed_official 52:a51c77007319 585 * - If an error occurs (ie. error flags are set besides to the monitored flags),
mbed_official 52:a51c77007319 586 * the I2C_CheckEvent() function may return SUCCESS despite the communication
mbed_official 52:a51c77007319 587 * hold or corrupted real state.
mbed_official 52:a51c77007319 588 * In this case, it is advised to use error interrupts to monitor the error
mbed_official 52:a51c77007319 589 * events and handle them in the interrupt IRQ handler.
mbed_official 52:a51c77007319 590 *
mbed_official 52:a51c77007319 591 * @note
mbed_official 52:a51c77007319 592 * For error management, it is advised to use the following functions:
mbed_official 52:a51c77007319 593 * - I2C_ITConfig() to configure and enable the error interrupts (I2C_IT_ERR).
mbed_official 52:a51c77007319 594 * - I2Cx_ER_IRQHandler() which is called when the error interrupt occurs.
mbed_official 52:a51c77007319 595 * Where x is the peripheral instance (I2C1, I2C2 ...)
mbed_official 52:a51c77007319 596 * - I2C_GetFlagStatus() or I2C_GetITStatus() to be called into I2Cx_ER_IRQHandler()
mbed_official 52:a51c77007319 597 * in order to determine which error occurred.
mbed_official 52:a51c77007319 598 * - I2C_ClearFlag() or I2C_ClearITPendingBit() and/or I2C_SoftwareResetCmd()
mbed_official 52:a51c77007319 599 * and/or I2C_GenerateStop() in order to clear the error flag and source,
mbed_official 52:a51c77007319 600 * and return to correct communication status.
mbed_official 52:a51c77007319 601 *
mbed_official 52:a51c77007319 602 *
mbed_official 52:a51c77007319 603 * 2) Advanced state monitoring:
mbed_official 52:a51c77007319 604 * Using the function I2C_GetLastEvent() which returns the image of both status
mbed_official 52:a51c77007319 605 * registers in a single word (uint32_t) (Status Register 2 value is shifted left
mbed_official 52:a51c77007319 606 * by 16 bits and concatenated to Status Register 1).
mbed_official 52:a51c77007319 607 * - When to use:
mbed_official 52:a51c77007319 608 * - This function is suitable for the same applications above but it allows to
mbed_official 52:a51c77007319 609 * overcome the limitations of I2C_GetFlagStatus() function (see below).
mbed_official 52:a51c77007319 610 * The returned value could be compared to events already defined in the
mbed_official 52:a51c77007319 611 * library (stm32f10x_i2c.h) or to custom values defined by user.
mbed_official 52:a51c77007319 612 * - This function is suitable when multiple flags are monitored at the same time.
mbed_official 52:a51c77007319 613 * - At the opposite of I2C_CheckEvent() function, this function allows user to
mbed_official 52:a51c77007319 614 * choose when an event is accepted (when all events flags are set and no
mbed_official 52:a51c77007319 615 * other flags are set or just when the needed flags are set like
mbed_official 52:a51c77007319 616 * I2C_CheckEvent() function).
mbed_official 52:a51c77007319 617 * - Limitations:
mbed_official 52:a51c77007319 618 * - User may need to define his own events.
mbed_official 52:a51c77007319 619 * - Same remark concerning the error management is applicable for this
mbed_official 52:a51c77007319 620 * function if user decides to check only regular communication flags (and
mbed_official 52:a51c77007319 621 * ignores error flags).
mbed_official 52:a51c77007319 622 *
mbed_official 52:a51c77007319 623 *
mbed_official 52:a51c77007319 624 * 3) Flag-based state monitoring:
mbed_official 52:a51c77007319 625 * Using the function I2C_GetFlagStatus() which simply returns the status of
mbed_official 52:a51c77007319 626 * one single flag (ie. I2C_FLAG_RXNE ...).
mbed_official 52:a51c77007319 627 * - When to use:
mbed_official 52:a51c77007319 628 * - This function could be used for specific applications or in debug phase.
mbed_official 52:a51c77007319 629 * - It is suitable when only one flag checking is needed (most I2C events
mbed_official 52:a51c77007319 630 * are monitored through multiple flags).
mbed_official 52:a51c77007319 631 * - Limitations:
mbed_official 52:a51c77007319 632 * - When calling this function, the Status register is accessed. Some flags are
mbed_official 52:a51c77007319 633 * cleared when the status register is accessed. So checking the status
mbed_official 52:a51c77007319 634 * of one Flag, may clear other ones.
mbed_official 52:a51c77007319 635 * - Function may need to be called twice or more in order to monitor one
mbed_official 52:a51c77007319 636 * single event.
mbed_official 52:a51c77007319 637 *
mbed_official 52:a51c77007319 638 */
mbed_official 52:a51c77007319 639
mbed_official 52:a51c77007319 640 /**
mbed_official 52:a51c77007319 641 *
mbed_official 52:a51c77007319 642 * 1) Basic state monitoring
mbed_official 52:a51c77007319 643 *******************************************************************************
mbed_official 52:a51c77007319 644 */
mbed_official 52:a51c77007319 645 ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx, uint32_t I2C_EVENT);
mbed_official 52:a51c77007319 646 /**
mbed_official 52:a51c77007319 647 *
mbed_official 52:a51c77007319 648 * 2) Advanced state monitoring
mbed_official 52:a51c77007319 649 *******************************************************************************
mbed_official 52:a51c77007319 650 */
mbed_official 52:a51c77007319 651 uint32_t I2C_GetLastEvent(I2C_TypeDef* I2Cx);
mbed_official 52:a51c77007319 652 /**
mbed_official 52:a51c77007319 653 *
mbed_official 52:a51c77007319 654 * 3) Flag-based state monitoring
mbed_official 52:a51c77007319 655 *******************************************************************************
mbed_official 52:a51c77007319 656 */
mbed_official 52:a51c77007319 657 FlagStatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG);
mbed_official 52:a51c77007319 658 /**
mbed_official 52:a51c77007319 659 *
mbed_official 52:a51c77007319 660 *******************************************************************************
mbed_official 52:a51c77007319 661 */
mbed_official 52:a51c77007319 662
mbed_official 52:a51c77007319 663 void I2C_ClearFlag(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG);
mbed_official 52:a51c77007319 664 ITStatus I2C_GetITStatus(I2C_TypeDef* I2Cx, uint32_t I2C_IT);
mbed_official 52:a51c77007319 665 void I2C_ClearITPendingBit(I2C_TypeDef* I2Cx, uint32_t I2C_IT);
mbed_official 52:a51c77007319 666
mbed_official 52:a51c77007319 667 #ifdef __cplusplus
mbed_official 52:a51c77007319 668 }
mbed_official 52:a51c77007319 669 #endif
mbed_official 52:a51c77007319 670
mbed_official 52:a51c77007319 671 #endif /*__STM32F10x_I2C_H */
mbed_official 52:a51c77007319 672 /**
mbed_official 52:a51c77007319 673 * @}
mbed_official 52:a51c77007319 674 */
mbed_official 52:a51c77007319 675
mbed_official 52:a51c77007319 676 /**
mbed_official 52:a51c77007319 677 * @}
mbed_official 52:a51c77007319 678 */
mbed_official 52:a51c77007319 679
mbed_official 52:a51c77007319 680 /**
mbed_official 52:a51c77007319 681 * @}
mbed_official 52:a51c77007319 682 */
mbed_official 52:a51c77007319 683
mbed_official 52:a51c77007319 684 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/