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