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