Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Space_Invaders_Demo neopixels gpio_test_stm32f3_discovery gpio_test_systimer ... more
stm32f30x_i2c.h
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f30x_i2c.h 00004 * @author MCD Application Team 00005 * @version V1.2.3 00006 * @date 10-July-2015 00007 * @brief This file contains all the functions prototypes for the I2C firmware 00008 * library. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2> 00013 * 00014 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00015 * You may not use this file except in compliance with the License. 00016 * You may obtain a copy of the License at: 00017 * 00018 * http://www.st.com/software_license_agreement_liberty_v2 00019 * 00020 * Unless required by applicable law or agreed to in writing, software 00021 * distributed under the License is distributed on an "AS IS" BASIS, 00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00023 * See the License for the specific language governing permissions and 00024 * limitations under the License. 00025 * 00026 ****************************************************************************** 00027 */ 00028 00029 /* Define to prevent recursive inclusion -------------------------------------*/ 00030 #ifndef __STM32F30x_I2C_H 00031 #define __STM32F30x_I2C_H 00032 00033 #ifdef __cplusplus 00034 extern "C" { 00035 #endif 00036 00037 /* Includes ------------------------------------------------------------------*/ 00038 #include "stm32f30x.h" 00039 00040 /** @addtogroup STM32F30x_StdPeriph_Driver 00041 * @{ 00042 */ 00043 00044 /** @addtogroup I2C 00045 * @{ 00046 */ 00047 00048 /* Exported types ------------------------------------------------------------*/ 00049 00050 /** 00051 * @brief I2C Init structure definition 00052 */ 00053 00054 typedef struct 00055 { 00056 uint32_t I2C_Timing; /*!< Specifies the I2C_TIMINGR_register value. 00057 This parameter calculated by referring to I2C initialization 00058 section in Reference manual*/ 00059 00060 uint32_t I2C_AnalogFilter; /*!< Enables or disables analog noise filter. 00061 This parameter can be a value of @ref I2C_Analog_Filter */ 00062 00063 uint32_t I2C_DigitalFilter; /*!< Configures the digital noise filter. 00064 This parameter can be a number between 0x00 and 0x0F */ 00065 00066 uint32_t I2C_Mode; /*!< Specifies the I2C mode. 00067 This parameter can be a value of @ref I2C_mode */ 00068 00069 uint32_t I2C_OwnAddress1; /*!< Specifies the device own address 1. 00070 This parameter can be a 7-bit or 10-bit address */ 00071 00072 uint32_t I2C_Ack; /*!< Enables or disables the acknowledgement. 00073 This parameter can be a value of @ref I2C_acknowledgement */ 00074 00075 uint32_t I2C_AcknowledgedAddress; /*!< Specifies if 7-bit or 10-bit address is acknowledged. 00076 This parameter can be a value of @ref I2C_acknowledged_address */ 00077 }I2C_InitTypeDef; 00078 00079 /* Exported constants --------------------------------------------------------*/ 00080 00081 00082 /** @defgroup I2C_Exported_Constants 00083 * @{ 00084 */ 00085 00086 #define IS_I2C_ALL_PERIPH(PERIPH) (((PERIPH) == I2C1) || \ 00087 ((PERIPH) == I2C2)) 00088 00089 /** @defgroup I2C_Analog_Filter 00090 * @{ 00091 */ 00092 00093 #define I2C_AnalogFilter_Enable ((uint32_t)0x00000000) 00094 #define I2C_AnalogFilter_Disable I2C_CR1_ANFOFF 00095 00096 #define IS_I2C_ANALOG_FILTER(FILTER) (((FILTER) == I2C_AnalogFilter_Enable) || \ 00097 ((FILTER) == I2C_AnalogFilter_Disable)) 00098 /** 00099 * @} 00100 */ 00101 00102 /** @defgroup I2C_Digital_Filter 00103 * @{ 00104 */ 00105 00106 #define IS_I2C_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000F) 00107 /** 00108 * @} 00109 */ 00110 00111 /** @defgroup I2C_mode 00112 * @{ 00113 */ 00114 00115 #define I2C_Mode_I2C ((uint32_t)0x00000000) 00116 #define I2C_Mode_SMBusDevice I2C_CR1_SMBDEN 00117 #define I2C_Mode_SMBusHost I2C_CR1_SMBHEN 00118 00119 #define IS_I2C_MODE(MODE) (((MODE) == I2C_Mode_I2C) || \ 00120 ((MODE) == I2C_Mode_SMBusDevice) || \ 00121 ((MODE) == I2C_Mode_SMBusHost)) 00122 /** 00123 * @} 00124 */ 00125 00126 /** @defgroup I2C_acknowledgement 00127 * @{ 00128 */ 00129 00130 #define I2C_Ack_Enable ((uint32_t)0x00000000) 00131 #define I2C_Ack_Disable I2C_CR2_NACK 00132 00133 #define IS_I2C_ACK(ACK) (((ACK) == I2C_Ack_Enable) || \ 00134 ((ACK) == I2C_Ack_Disable)) 00135 /** 00136 * @} 00137 */ 00138 00139 /** @defgroup I2C_acknowledged_address 00140 * @{ 00141 */ 00142 00143 #define I2C_AcknowledgedAddress_7bit ((uint32_t)0x00000000) 00144 #define I2C_AcknowledgedAddress_10bit I2C_OAR1_OA1MODE 00145 00146 #define IS_I2C_ACKNOWLEDGE_ADDRESS(ADDRESS) (((ADDRESS) == I2C_AcknowledgedAddress_7bit) || \ 00147 ((ADDRESS) == I2C_AcknowledgedAddress_10bit)) 00148 /** 00149 * @} 00150 */ 00151 00152 /** @defgroup I2C_own_address1 00153 * @{ 00154 */ 00155 00156 #define IS_I2C_OWN_ADDRESS1(ADDRESS1) ((ADDRESS1) <= (uint32_t)0x000003FF) 00157 /** 00158 * @} 00159 */ 00160 00161 /** @defgroup I2C_transfer_direction 00162 * @{ 00163 */ 00164 00165 #define I2C_Direction_Transmitter ((uint16_t)0x0000) 00166 #define I2C_Direction_Receiver ((uint16_t)0x0400) 00167 00168 #define IS_I2C_DIRECTION(DIRECTION) (((DIRECTION) == I2C_Direction_Transmitter) || \ 00169 ((DIRECTION) == I2C_Direction_Receiver)) 00170 /** 00171 * @} 00172 */ 00173 00174 /** @defgroup I2C_DMA_transfer_requests 00175 * @{ 00176 */ 00177 00178 #define I2C_DMAReq_Tx I2C_CR1_TXDMAEN 00179 #define I2C_DMAReq_Rx I2C_CR1_RXDMAEN 00180 00181 #define IS_I2C_DMA_REQ(REQ) ((((REQ) & (uint32_t)0xFFFF3FFF) == 0x00) && ((REQ) != 0x00)) 00182 /** 00183 * @} 00184 */ 00185 00186 /** @defgroup I2C_slave_address 00187 * @{ 00188 */ 00189 00190 #define IS_I2C_SLAVE_ADDRESS(ADDRESS) ((ADDRESS) <= (uint16_t)0x03FF) 00191 /** 00192 * @} 00193 */ 00194 00195 00196 /** @defgroup I2C_own_address2 00197 * @{ 00198 */ 00199 00200 #define IS_I2C_OWN_ADDRESS2(ADDRESS2) ((ADDRESS2) <= (uint16_t)0x00FF) 00201 00202 /** 00203 * @} 00204 */ 00205 00206 /** @defgroup I2C_own_address2_mask 00207 * @{ 00208 */ 00209 00210 #define I2C_OA2_NoMask ((uint8_t)0x00) 00211 #define I2C_OA2_Mask01 ((uint8_t)0x01) 00212 #define I2C_OA2_Mask02 ((uint8_t)0x02) 00213 #define I2C_OA2_Mask03 ((uint8_t)0x03) 00214 #define I2C_OA2_Mask04 ((uint8_t)0x04) 00215 #define I2C_OA2_Mask05 ((uint8_t)0x05) 00216 #define I2C_OA2_Mask06 ((uint8_t)0x06) 00217 #define I2C_OA2_Mask07 ((uint8_t)0x07) 00218 00219 #define IS_I2C_OWN_ADDRESS2_MASK(MASK) (((MASK) == I2C_OA2_NoMask) || \ 00220 ((MASK) == I2C_OA2_Mask01) || \ 00221 ((MASK) == I2C_OA2_Mask02) || \ 00222 ((MASK) == I2C_OA2_Mask03) || \ 00223 ((MASK) == I2C_OA2_Mask04) || \ 00224 ((MASK) == I2C_OA2_Mask05) || \ 00225 ((MASK) == I2C_OA2_Mask06) || \ 00226 ((MASK) == I2C_OA2_Mask07)) 00227 00228 /** 00229 * @} 00230 */ 00231 00232 /** @defgroup I2C_timeout 00233 * @{ 00234 */ 00235 00236 #define IS_I2C_TIMEOUT(TIMEOUT) ((TIMEOUT) <= (uint16_t)0x0FFF) 00237 00238 /** 00239 * @} 00240 */ 00241 00242 /** @defgroup I2C_registers 00243 * @{ 00244 */ 00245 00246 #define I2C_Register_CR1 ((uint8_t)0x00) 00247 #define I2C_Register_CR2 ((uint8_t)0x04) 00248 #define I2C_Register_OAR1 ((uint8_t)0x08) 00249 #define I2C_Register_OAR2 ((uint8_t)0x0C) 00250 #define I2C_Register_TIMINGR ((uint8_t)0x10) 00251 #define I2C_Register_TIMEOUTR ((uint8_t)0x14) 00252 #define I2C_Register_ISR ((uint8_t)0x18) 00253 #define I2C_Register_ICR ((uint8_t)0x1C) 00254 #define I2C_Register_PECR ((uint8_t)0x20) 00255 #define I2C_Register_RXDR ((uint8_t)0x24) 00256 #define I2C_Register_TXDR ((uint8_t)0x28) 00257 00258 #define IS_I2C_REGISTER(REGISTER) (((REGISTER) == I2C_Register_CR1) || \ 00259 ((REGISTER) == I2C_Register_CR2) || \ 00260 ((REGISTER) == I2C_Register_OAR1) || \ 00261 ((REGISTER) == I2C_Register_OAR2) || \ 00262 ((REGISTER) == I2C_Register_TIMINGR) || \ 00263 ((REGISTER) == I2C_Register_TIMEOUTR) || \ 00264 ((REGISTER) == I2C_Register_ISR) || \ 00265 ((REGISTER) == I2C_Register_ICR) || \ 00266 ((REGISTER) == I2C_Register_PECR) || \ 00267 ((REGISTER) == I2C_Register_RXDR) || \ 00268 ((REGISTER) == I2C_Register_TXDR)) 00269 /** 00270 * @} 00271 */ 00272 00273 /** @defgroup I2C_interrupts_definition 00274 * @{ 00275 */ 00276 00277 #define I2C_IT_ERRI I2C_CR1_ERRIE 00278 #define I2C_IT_TCI I2C_CR1_TCIE 00279 #define I2C_IT_STOPI I2C_CR1_STOPIE 00280 #define I2C_IT_NACKI I2C_CR1_NACKIE 00281 #define I2C_IT_ADDRI I2C_CR1_ADDRIE 00282 #define I2C_IT_RXI I2C_CR1_RXIE 00283 #define I2C_IT_TXI I2C_CR1_TXIE 00284 00285 #define IS_I2C_CONFIG_IT(IT) ((((IT) & (uint32_t)0xFFFFFF01) == 0x00) && ((IT) != 0x00)) 00286 00287 /** 00288 * @} 00289 */ 00290 00291 /** @defgroup I2C_flags_definition 00292 * @{ 00293 */ 00294 00295 #define I2C_FLAG_TXE I2C_ISR_TXE 00296 #define I2C_FLAG_TXIS I2C_ISR_TXIS 00297 #define I2C_FLAG_RXNE I2C_ISR_RXNE 00298 #define I2C_FLAG_ADDR I2C_ISR_ADDR 00299 #define I2C_FLAG_NACKF I2C_ISR_NACKF 00300 #define I2C_FLAG_STOPF I2C_ISR_STOPF 00301 #define I2C_FLAG_TC I2C_ISR_TC 00302 #define I2C_FLAG_TCR I2C_ISR_TCR 00303 #define I2C_FLAG_BERR I2C_ISR_BERR 00304 #define I2C_FLAG_ARLO I2C_ISR_ARLO 00305 #define I2C_FLAG_OVR I2C_ISR_OVR 00306 #define I2C_FLAG_PECERR I2C_ISR_PECERR 00307 #define I2C_FLAG_TIMEOUT I2C_ISR_TIMEOUT 00308 #define I2C_FLAG_ALERT I2C_ISR_ALERT 00309 #define I2C_FLAG_BUSY I2C_ISR_BUSY 00310 00311 #define IS_I2C_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFF4000) == 0x00) && ((FLAG) != 0x00)) 00312 00313 #define IS_I2C_GET_FLAG(FLAG) (((FLAG) == I2C_FLAG_TXE) || ((FLAG) == I2C_FLAG_TXIS) || \ 00314 ((FLAG) == I2C_FLAG_RXNE) || ((FLAG) == I2C_FLAG_ADDR) || \ 00315 ((FLAG) == I2C_FLAG_NACKF) || ((FLAG) == I2C_FLAG_STOPF) || \ 00316 ((FLAG) == I2C_FLAG_TC) || ((FLAG) == I2C_FLAG_TCR) || \ 00317 ((FLAG) == I2C_FLAG_BERR) || ((FLAG) == I2C_FLAG_ARLO) || \ 00318 ((FLAG) == I2C_FLAG_OVR) || ((FLAG) == I2C_FLAG_PECERR) || \ 00319 ((FLAG) == I2C_FLAG_TIMEOUT) || ((FLAG) == I2C_FLAG_ALERT) || \ 00320 ((FLAG) == I2C_FLAG_BUSY)) 00321 00322 /** 00323 * @} 00324 */ 00325 00326 00327 /** @defgroup I2C_interrupts_definition 00328 * @{ 00329 */ 00330 00331 #define I2C_IT_TXIS I2C_ISR_TXIS 00332 #define I2C_IT_RXNE I2C_ISR_RXNE 00333 #define I2C_IT_ADDR I2C_ISR_ADDR 00334 #define I2C_IT_NACKF I2C_ISR_NACKF 00335 #define I2C_IT_STOPF I2C_ISR_STOPF 00336 #define I2C_IT_TC I2C_ISR_TC 00337 #define I2C_IT_TCR I2C_ISR_TCR 00338 #define I2C_IT_BERR I2C_ISR_BERR 00339 #define I2C_IT_ARLO I2C_ISR_ARLO 00340 #define I2C_IT_OVR I2C_ISR_OVR 00341 #define I2C_IT_PECERR I2C_ISR_PECERR 00342 #define I2C_IT_TIMEOUT I2C_ISR_TIMEOUT 00343 #define I2C_IT_ALERT I2C_ISR_ALERT 00344 00345 #define IS_I2C_CLEAR_IT(IT) ((((IT) & (uint32_t)0xFFFFC001) == 0x00) && ((IT) != 0x00)) 00346 00347 #define IS_I2C_GET_IT(IT) (((IT) == I2C_IT_TXIS) || ((IT) == I2C_IT_RXNE) || \ 00348 ((IT) == I2C_IT_ADDR) || ((IT) == I2C_IT_NACKF) || \ 00349 ((IT) == I2C_IT_STOPF) || ((IT) == I2C_IT_TC) || \ 00350 ((IT) == I2C_IT_TCR) || ((IT) == I2C_IT_BERR) || \ 00351 ((IT) == I2C_IT_ARLO) || ((IT) == I2C_IT_OVR) || \ 00352 ((IT) == I2C_IT_PECERR) || ((IT) == I2C_IT_TIMEOUT) || \ 00353 ((IT) == I2C_IT_ALERT)) 00354 00355 00356 /** 00357 * @} 00358 */ 00359 00360 /** @defgroup I2C_ReloadEndMode_definition 00361 * @{ 00362 */ 00363 00364 #define I2C_Reload_Mode I2C_CR2_RELOAD 00365 #define I2C_AutoEnd_Mode I2C_CR2_AUTOEND 00366 #define I2C_SoftEnd_Mode ((uint32_t)0x00000000) 00367 00368 00369 #define IS_RELOAD_END_MODE(MODE) (((MODE) == I2C_Reload_Mode) || \ 00370 ((MODE) == I2C_AutoEnd_Mode) || \ 00371 ((MODE) == I2C_SoftEnd_Mode)) 00372 00373 00374 /** 00375 * @} 00376 */ 00377 00378 /** @defgroup I2C_StartStopMode_definition 00379 * @{ 00380 */ 00381 00382 #define I2C_No_StartStop ((uint32_t)0x00000000) 00383 #define I2C_Generate_Stop I2C_CR2_STOP 00384 #define I2C_Generate_Start_Read (uint32_t)(I2C_CR2_START | I2C_CR2_RD_WRN) 00385 #define I2C_Generate_Start_Write I2C_CR2_START 00386 00387 00388 #define IS_START_STOP_MODE(MODE) (((MODE) == I2C_Generate_Stop) || \ 00389 ((MODE) == I2C_Generate_Start_Read) || \ 00390 ((MODE) == I2C_Generate_Start_Write) || \ 00391 ((MODE) == I2C_No_StartStop)) 00392 00393 00394 /** 00395 * @} 00396 */ 00397 00398 /** 00399 * @} 00400 */ 00401 00402 /* Exported macro ------------------------------------------------------------*/ 00403 /* Exported functions ------------------------------------------------------- */ 00404 00405 00406 /* Initialization and Configuration functions *********************************/ 00407 void I2C_DeInit(I2C_TypeDef* I2Cx); 00408 void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct); 00409 void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct); 00410 void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState); 00411 void I2C_SoftwareResetCmd(I2C_TypeDef* I2Cx); 00412 void I2C_ITConfig(I2C_TypeDef* I2Cx, uint32_t I2C_IT, FunctionalState NewState); 00413 void I2C_StretchClockCmd(I2C_TypeDef* I2Cx, FunctionalState NewState); 00414 void I2C_StopModeCmd(I2C_TypeDef* I2Cx, FunctionalState NewState); 00415 void I2C_DualAddressCmd(I2C_TypeDef* I2Cx, FunctionalState NewState); 00416 void I2C_OwnAddress2Config(I2C_TypeDef* I2Cx, uint16_t Address, uint8_t Mask); 00417 void I2C_GeneralCallCmd(I2C_TypeDef* I2Cx, FunctionalState NewState); 00418 void I2C_SlaveByteControlCmd(I2C_TypeDef* I2Cx, FunctionalState NewState); 00419 void I2C_SlaveAddressConfig(I2C_TypeDef* I2Cx, uint16_t Address); 00420 void I2C_10BitAddressingModeCmd(I2C_TypeDef* I2Cx, FunctionalState NewState); 00421 00422 /* Communications handling functions ******************************************/ 00423 void I2C_AutoEndCmd(I2C_TypeDef* I2Cx, FunctionalState NewState); 00424 void I2C_ReloadCmd(I2C_TypeDef* I2Cx, FunctionalState NewState); 00425 void I2C_NumberOfBytesConfig(I2C_TypeDef* I2Cx, uint8_t Number_Bytes); 00426 void I2C_MasterRequestConfig(I2C_TypeDef* I2Cx, uint16_t I2C_Direction); 00427 void I2C_GenerateSTART(I2C_TypeDef* I2Cx, FunctionalState NewState); 00428 void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState); 00429 void I2C_10BitAddressHeaderCmd(I2C_TypeDef* I2Cx, FunctionalState NewState); 00430 void I2C_AcknowledgeConfig(I2C_TypeDef* I2Cx, FunctionalState NewState); 00431 uint8_t I2C_GetAddressMatched(I2C_TypeDef* I2Cx); 00432 uint16_t I2C_GetTransferDirection(I2C_TypeDef* I2Cx); 00433 void I2C_TransferHandling(I2C_TypeDef* I2Cx, uint16_t Address, uint8_t Number_Bytes, uint32_t ReloadEndMode, uint32_t StartStopMode); 00434 00435 /* SMBUS management functions ************************************************/ 00436 void I2C_SMBusAlertCmd(I2C_TypeDef* I2Cx, FunctionalState NewState); 00437 void I2C_ClockTimeoutCmd(I2C_TypeDef* I2Cx, FunctionalState NewState); 00438 void I2C_ExtendedClockTimeoutCmd(I2C_TypeDef* I2Cx, FunctionalState NewState); 00439 void I2C_IdleClockTimeoutCmd(I2C_TypeDef* I2Cx, FunctionalState NewState); 00440 void I2C_TimeoutAConfig(I2C_TypeDef* I2Cx, uint16_t Timeout); 00441 void I2C_TimeoutBConfig(I2C_TypeDef* I2Cx, uint16_t Timeout); 00442 void I2C_CalculatePEC(I2C_TypeDef* I2Cx, FunctionalState NewState); 00443 void I2C_PECRequestCmd(I2C_TypeDef* I2Cx, FunctionalState NewState); 00444 uint8_t I2C_GetPEC(I2C_TypeDef* I2Cx); 00445 00446 /* I2C registers management functions *****************************************/ 00447 uint32_t I2C_ReadRegister(I2C_TypeDef* I2Cx, uint8_t I2C_Register); 00448 00449 /* Data transfers management functions ****************************************/ 00450 void I2C_SendData(I2C_TypeDef* I2Cx, uint8_t Data); 00451 uint8_t I2C_ReceiveData(I2C_TypeDef* I2Cx); 00452 00453 /* DMA transfers management functions *****************************************/ 00454 void I2C_DMACmd(I2C_TypeDef* I2Cx, uint32_t I2C_DMAReq, FunctionalState NewState); 00455 00456 /* Interrupts and flags management functions **********************************/ 00457 FlagStatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG); 00458 void I2C_ClearFlag(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG); 00459 ITStatus I2C_GetITStatus(I2C_TypeDef* I2Cx, uint32_t I2C_IT); 00460 void I2C_ClearITPendingBit(I2C_TypeDef* I2Cx, uint32_t I2C_IT); 00461 00462 00463 #ifdef __cplusplus 00464 } 00465 #endif 00466 00467 #endif /*__STM32F30x_I2C_H */ 00468 00469 /** 00470 * @} 00471 */ 00472 00473 /** 00474 * @} 00475 */ 00476 00477 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 17:34:44 by
