stm32f30x_i2c.h
Go to the documentation of this file.
1 
29 /* Define to prevent recursive inclusion -------------------------------------*/
30 #ifndef __STM32F30x_I2C_H
31 #define __STM32F30x_I2C_H
32 
33 #ifdef __cplusplus
34  extern "C" {
35 #endif
36 
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f30x.h"
39 
48 /* Exported types ------------------------------------------------------------*/
49 
54 typedef struct
55 {
56  uint32_t I2C_Timing;
60  uint32_t I2C_AnalogFilter;
63  uint32_t I2C_DigitalFilter;
66  uint32_t I2C_Mode;
69  uint32_t I2C_OwnAddress1;
72  uint32_t I2C_Ack;
78 
79 /* Exported constants --------------------------------------------------------*/
80 
81 
86 #define IS_I2C_ALL_PERIPH(PERIPH) (((PERIPH) == I2C1) || \
87  ((PERIPH) == I2C2))
88 
93 #define I2C_AnalogFilter_Enable ((uint32_t)0x00000000)
94 #define I2C_AnalogFilter_Disable I2C_CR1_ANFOFF
95 
96 #define IS_I2C_ANALOG_FILTER(FILTER) (((FILTER) == I2C_AnalogFilter_Enable) || \
97  ((FILTER) == I2C_AnalogFilter_Disable))
98 
106 #define IS_I2C_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000F)
107 
115 #define I2C_Mode_I2C ((uint32_t)0x00000000)
116 #define I2C_Mode_SMBusDevice I2C_CR1_SMBDEN
117 #define I2C_Mode_SMBusHost I2C_CR1_SMBHEN
118 
119 #define IS_I2C_MODE(MODE) (((MODE) == I2C_Mode_I2C) || \
120  ((MODE) == I2C_Mode_SMBusDevice) || \
121  ((MODE) == I2C_Mode_SMBusHost))
122 
130 #define I2C_Ack_Enable ((uint32_t)0x00000000)
131 #define I2C_Ack_Disable I2C_CR2_NACK
132 
133 #define IS_I2C_ACK(ACK) (((ACK) == I2C_Ack_Enable) || \
134  ((ACK) == I2C_Ack_Disable))
135 
143 #define I2C_AcknowledgedAddress_7bit ((uint32_t)0x00000000)
144 #define I2C_AcknowledgedAddress_10bit I2C_OAR1_OA1MODE
145 
146 #define IS_I2C_ACKNOWLEDGE_ADDRESS(ADDRESS) (((ADDRESS) == I2C_AcknowledgedAddress_7bit) || \
147  ((ADDRESS) == I2C_AcknowledgedAddress_10bit))
148 
156 #define IS_I2C_OWN_ADDRESS1(ADDRESS1) ((ADDRESS1) <= (uint32_t)0x000003FF)
157 
165 #define I2C_Direction_Transmitter ((uint16_t)0x0000)
166 #define I2C_Direction_Receiver ((uint16_t)0x0400)
167 
168 #define IS_I2C_DIRECTION(DIRECTION) (((DIRECTION) == I2C_Direction_Transmitter) || \
169  ((DIRECTION) == I2C_Direction_Receiver))
170 
178 #define I2C_DMAReq_Tx I2C_CR1_TXDMAEN
179 #define I2C_DMAReq_Rx I2C_CR1_RXDMAEN
180 
181 #define IS_I2C_DMA_REQ(REQ) ((((REQ) & (uint32_t)0xFFFF3FFF) == 0x00) && ((REQ) != 0x00))
182 
190 #define IS_I2C_SLAVE_ADDRESS(ADDRESS) ((ADDRESS) <= (uint16_t)0x03FF)
191 
200 #define IS_I2C_OWN_ADDRESS2(ADDRESS2) ((ADDRESS2) <= (uint16_t)0x00FF)
201 
210 #define I2C_OA2_NoMask ((uint8_t)0x00)
211 #define I2C_OA2_Mask01 ((uint8_t)0x01)
212 #define I2C_OA2_Mask02 ((uint8_t)0x02)
213 #define I2C_OA2_Mask03 ((uint8_t)0x03)
214 #define I2C_OA2_Mask04 ((uint8_t)0x04)
215 #define I2C_OA2_Mask05 ((uint8_t)0x05)
216 #define I2C_OA2_Mask06 ((uint8_t)0x06)
217 #define I2C_OA2_Mask07 ((uint8_t)0x07)
218 
219 #define IS_I2C_OWN_ADDRESS2_MASK(MASK) (((MASK) == I2C_OA2_NoMask) || \
220  ((MASK) == I2C_OA2_Mask01) || \
221  ((MASK) == I2C_OA2_Mask02) || \
222  ((MASK) == I2C_OA2_Mask03) || \
223  ((MASK) == I2C_OA2_Mask04) || \
224  ((MASK) == I2C_OA2_Mask05) || \
225  ((MASK) == I2C_OA2_Mask06) || \
226  ((MASK) == I2C_OA2_Mask07))
227 
236 #define IS_I2C_TIMEOUT(TIMEOUT) ((TIMEOUT) <= (uint16_t)0x0FFF)
237 
246 #define I2C_Register_CR1 ((uint8_t)0x00)
247 #define I2C_Register_CR2 ((uint8_t)0x04)
248 #define I2C_Register_OAR1 ((uint8_t)0x08)
249 #define I2C_Register_OAR2 ((uint8_t)0x0C)
250 #define I2C_Register_TIMINGR ((uint8_t)0x10)
251 #define I2C_Register_TIMEOUTR ((uint8_t)0x14)
252 #define I2C_Register_ISR ((uint8_t)0x18)
253 #define I2C_Register_ICR ((uint8_t)0x1C)
254 #define I2C_Register_PECR ((uint8_t)0x20)
255 #define I2C_Register_RXDR ((uint8_t)0x24)
256 #define I2C_Register_TXDR ((uint8_t)0x28)
257 
258 #define IS_I2C_REGISTER(REGISTER) (((REGISTER) == I2C_Register_CR1) || \
259  ((REGISTER) == I2C_Register_CR2) || \
260  ((REGISTER) == I2C_Register_OAR1) || \
261  ((REGISTER) == I2C_Register_OAR2) || \
262  ((REGISTER) == I2C_Register_TIMINGR) || \
263  ((REGISTER) == I2C_Register_TIMEOUTR) || \
264  ((REGISTER) == I2C_Register_ISR) || \
265  ((REGISTER) == I2C_Register_ICR) || \
266  ((REGISTER) == I2C_Register_PECR) || \
267  ((REGISTER) == I2C_Register_RXDR) || \
268  ((REGISTER) == I2C_Register_TXDR))
269 
277 #define I2C_IT_ERRI I2C_CR1_ERRIE
278 #define I2C_IT_TCI I2C_CR1_TCIE
279 #define I2C_IT_STOPI I2C_CR1_STOPIE
280 #define I2C_IT_NACKI I2C_CR1_NACKIE
281 #define I2C_IT_ADDRI I2C_CR1_ADDRIE
282 #define I2C_IT_RXI I2C_CR1_RXIE
283 #define I2C_IT_TXI I2C_CR1_TXIE
284 
285 #define IS_I2C_CONFIG_IT(IT) ((((IT) & (uint32_t)0xFFFFFF01) == 0x00) && ((IT) != 0x00))
286 
295 #define I2C_FLAG_TXE I2C_ISR_TXE
296 #define I2C_FLAG_TXIS I2C_ISR_TXIS
297 #define I2C_FLAG_RXNE I2C_ISR_RXNE
298 #define I2C_FLAG_ADDR I2C_ISR_ADDR
299 #define I2C_FLAG_NACKF I2C_ISR_NACKF
300 #define I2C_FLAG_STOPF I2C_ISR_STOPF
301 #define I2C_FLAG_TC I2C_ISR_TC
302 #define I2C_FLAG_TCR I2C_ISR_TCR
303 #define I2C_FLAG_BERR I2C_ISR_BERR
304 #define I2C_FLAG_ARLO I2C_ISR_ARLO
305 #define I2C_FLAG_OVR I2C_ISR_OVR
306 #define I2C_FLAG_PECERR I2C_ISR_PECERR
307 #define I2C_FLAG_TIMEOUT I2C_ISR_TIMEOUT
308 #define I2C_FLAG_ALERT I2C_ISR_ALERT
309 #define I2C_FLAG_BUSY I2C_ISR_BUSY
310 
311 #define IS_I2C_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFF4000) == 0x00) && ((FLAG) != 0x00))
312 
313 #define IS_I2C_GET_FLAG(FLAG) (((FLAG) == I2C_FLAG_TXE) || ((FLAG) == I2C_FLAG_TXIS) || \
314  ((FLAG) == I2C_FLAG_RXNE) || ((FLAG) == I2C_FLAG_ADDR) || \
315  ((FLAG) == I2C_FLAG_NACKF) || ((FLAG) == I2C_FLAG_STOPF) || \
316  ((FLAG) == I2C_FLAG_TC) || ((FLAG) == I2C_FLAG_TCR) || \
317  ((FLAG) == I2C_FLAG_BERR) || ((FLAG) == I2C_FLAG_ARLO) || \
318  ((FLAG) == I2C_FLAG_OVR) || ((FLAG) == I2C_FLAG_PECERR) || \
319  ((FLAG) == I2C_FLAG_TIMEOUT) || ((FLAG) == I2C_FLAG_ALERT) || \
320  ((FLAG) == I2C_FLAG_BUSY))
321 
331 #define I2C_IT_TXIS I2C_ISR_TXIS
332 #define I2C_IT_RXNE I2C_ISR_RXNE
333 #define I2C_IT_ADDR I2C_ISR_ADDR
334 #define I2C_IT_NACKF I2C_ISR_NACKF
335 #define I2C_IT_STOPF I2C_ISR_STOPF
336 #define I2C_IT_TC I2C_ISR_TC
337 #define I2C_IT_TCR I2C_ISR_TCR
338 #define I2C_IT_BERR I2C_ISR_BERR
339 #define I2C_IT_ARLO I2C_ISR_ARLO
340 #define I2C_IT_OVR I2C_ISR_OVR
341 #define I2C_IT_PECERR I2C_ISR_PECERR
342 #define I2C_IT_TIMEOUT I2C_ISR_TIMEOUT
343 #define I2C_IT_ALERT I2C_ISR_ALERT
344 
345 #define IS_I2C_CLEAR_IT(IT) ((((IT) & (uint32_t)0xFFFFC001) == 0x00) && ((IT) != 0x00))
346 
347 #define IS_I2C_GET_IT(IT) (((IT) == I2C_IT_TXIS) || ((IT) == I2C_IT_RXNE) || \
348  ((IT) == I2C_IT_ADDR) || ((IT) == I2C_IT_NACKF) || \
349  ((IT) == I2C_IT_STOPF) || ((IT) == I2C_IT_TC) || \
350  ((IT) == I2C_IT_TCR) || ((IT) == I2C_IT_BERR) || \
351  ((IT) == I2C_IT_ARLO) || ((IT) == I2C_IT_OVR) || \
352  ((IT) == I2C_IT_PECERR) || ((IT) == I2C_IT_TIMEOUT) || \
353  ((IT) == I2C_IT_ALERT))
354 
355 
364 #define I2C_Reload_Mode I2C_CR2_RELOAD
365 #define I2C_AutoEnd_Mode I2C_CR2_AUTOEND
366 #define I2C_SoftEnd_Mode ((uint32_t)0x00000000)
367 
368 
369 #define IS_RELOAD_END_MODE(MODE) (((MODE) == I2C_Reload_Mode) || \
370  ((MODE) == I2C_AutoEnd_Mode) || \
371  ((MODE) == I2C_SoftEnd_Mode))
372 
373 
382 #define I2C_No_StartStop ((uint32_t)0x00000000)
383 #define I2C_Generate_Stop I2C_CR2_STOP
384 #define I2C_Generate_Start_Read (uint32_t)(I2C_CR2_START | I2C_CR2_RD_WRN)
385 #define I2C_Generate_Start_Write I2C_CR2_START
386 
387 
388 #define IS_START_STOP_MODE(MODE) (((MODE) == I2C_Generate_Stop) || \
389  ((MODE) == I2C_Generate_Start_Read) || \
390  ((MODE) == I2C_Generate_Start_Write) || \
391  ((MODE) == I2C_No_StartStop))
392 
393 
402 /* Exported macro ------------------------------------------------------------*/
403 /* Exported functions ------------------------------------------------------- */
404 
405 
406 /* Initialization and Configuration functions *********************************/
408 void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct);
409 void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct);
410 void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
412 void I2C_ITConfig(I2C_TypeDef* I2Cx, uint32_t I2C_IT, FunctionalState NewState);
416 void I2C_OwnAddress2Config(I2C_TypeDef* I2Cx, uint16_t Address, uint8_t Mask);
419 void I2C_SlaveAddressConfig(I2C_TypeDef* I2Cx, uint16_t Address);
421 
422 /* Communications handling functions ******************************************/
425 void I2C_NumberOfBytesConfig(I2C_TypeDef* I2Cx, uint8_t Number_Bytes);
426 void I2C_MasterRequestConfig(I2C_TypeDef* I2Cx, uint16_t I2C_Direction);
433 void I2C_TransferHandling(I2C_TypeDef* I2Cx, uint16_t Address, uint8_t Number_Bytes, uint32_t ReloadEndMode, uint32_t StartStopMode);
434 
435 /* SMBUS management functions ************************************************/
440 void I2C_TimeoutAConfig(I2C_TypeDef* I2Cx, uint16_t Timeout);
441 void I2C_TimeoutBConfig(I2C_TypeDef* I2Cx, uint16_t Timeout);
444 uint8_t I2C_GetPEC(I2C_TypeDef* I2Cx);
445 
446 /* I2C registers management functions *****************************************/
447 uint32_t I2C_ReadRegister(I2C_TypeDef* I2Cx, uint8_t I2C_Register);
448 
449 /* Data transfers management functions ****************************************/
450 void I2C_SendData(I2C_TypeDef* I2Cx, uint8_t Data);
452 
453 /* DMA transfers management functions *****************************************/
454 void I2C_DMACmd(I2C_TypeDef* I2Cx, uint32_t I2C_DMAReq, FunctionalState NewState);
455 
456 /* Interrupts and flags management functions **********************************/
457 FlagStatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG);
458 void I2C_ClearFlag(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG);
459 ITStatus I2C_GetITStatus(I2C_TypeDef* I2Cx, uint32_t I2C_IT);
460 void I2C_ClearITPendingBit(I2C_TypeDef* I2Cx, uint32_t I2C_IT);
461 
462 
463 #ifdef __cplusplus
464 }
465 #endif
466 
467 #endif /*__STM32F30x_I2C_H */
468 
477 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
void I2C_TimeoutAConfig(I2C_TypeDef *I2Cx, uint16_t Timeout)
Configures the I2C Bus Timeout A (SCL Timeout when TIDLE = 0 or Bus idle SCL and SDA high when TIDLE ...
FlagStatus
Definition: stm32f4xx.h:706
void I2C_ExtendedClockTimeoutCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables I2C Extended Clock Timeout (SCL cumulative Timeout detection).
FunctionalState
Definition: stm32f4xx.h:708
void I2C_SlaveAddressConfig(I2C_TypeDef *I2Cx, uint16_t Address)
Configures the slave address to be transmitted after start generation.
void I2C_ClearFlag(I2C_TypeDef *I2Cx, uint32_t I2C_FLAG)
Clears the I2Cx&#39;s pending flags.
void I2C_AcknowledgeConfig(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C acknowledge feature.
uint32_t I2C_Mode
Definition: stm32f30x_i2c.h:66
void I2C_SoftwareResetCmd(I2C_TypeDef *I2Cx)
Enables or disables the specified I2C software reset.
void I2C_GenerateSTART(I2C_TypeDef *I2Cx, FunctionalState NewState)
Generates I2Cx communication START condition.
uint8_t I2C_ReceiveData(I2C_TypeDef *I2Cx)
Returns the most recent received data by the I2Cx peripheral.
void I2C_TimeoutBConfig(I2C_TypeDef *I2Cx, uint16_t Timeout)
Configures the I2C Bus Timeout B (SCL cumulative Timeout).
void I2C_PECRequestCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables I2C PEC transmission/reception request.
void I2C_GenerateSTOP(I2C_TypeDef *I2Cx, FunctionalState NewState)
Generates I2Cx communication STOP condition.
void I2C_GeneralCallCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the I2C general call mode.
static I2C_TypeDef * I2Cx
Definition: drv_i2c.c:64
uint32_t I2C_OwnAddress1
Definition: stm32f30x_i2c.h:69
void I2C_StopModeCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables I2C wakeup from stop mode.
uint32_t I2C_DigitalFilter
Definition: stm32f30x_i2c.h:63
uint32_t I2C_Ack
Definition: stm32f30x_i2c.h:72
uint32_t I2C_AcknowledgedAddress
Definition: stm32f30x_i2c.h:75
void I2C_DeInit(I2C_TypeDef *I2Cx)
Deinitializes the I2Cx peripheral registers to their default reset values.
void I2C_ReloadCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the I2C nbytes reload mode.
void I2C_OwnAddress2Config(I2C_TypeDef *I2Cx, uint16_t Address, uint8_t Mask)
Configures the I2C slave own address 2 and mask.
enum FlagStatus ITStatus
void I2C_SMBusAlertCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables I2C SMBus alert.
ITStatus I2C_GetITStatus(I2C_TypeDef *I2Cx, uint32_t I2C_IT)
Checks whether the specified I2C interrupt has occurred or not.
void I2C_StructInit(I2C_InitTypeDef *I2C_InitStruct)
Fills each I2C_InitStruct member with its default value.
void I2C_Cmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C peripheral.
void I2C_CalculatePEC(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables I2C PEC calculation.
uint16_t I2C_GetTransferDirection(I2C_TypeDef *I2Cx)
Returns the I2C slave received request.
uint8_t I2C_GetPEC(I2C_TypeDef *I2Cx)
Returns the I2C PEC.
void I2C_TransferHandling(I2C_TypeDef *I2Cx, uint16_t Address, uint8_t Number_Bytes, uint32_t ReloadEndMode, uint32_t StartStopMode)
Handles I2Cx communication when starting transfer or during transfer (TC or TCR flag are set)...
void I2C_Init(I2C_TypeDef *I2Cx, I2C_InitTypeDef *I2C_InitStruct)
Initializes the I2Cx peripheral according to the specified parameters in the I2C_InitStruct.
void I2C_AutoEndCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the I2C automatic end mode (stop condition is automatically sent when nbytes data...
void I2C_10BitAddressHeaderCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the I2C 10-bit header only mode with read direction.
void I2C_ClearITPendingBit(I2C_TypeDef *I2Cx, uint32_t I2C_IT)
Clears the I2Cx&#39;s interrupt pending bits.
uint32_t I2C_Timing
Definition: stm32f30x_i2c.h:56
void I2C_DMACmd(I2C_TypeDef *I2Cx, uint32_t I2C_DMAReq, FunctionalState NewState)
Enables or disables the I2C DMA interface.
void I2C_DualAddressCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the I2C own address 2.
I2C Init structure definition.
Definition: stm32f4xx_i2c.h:54
void I2C_IdleClockTimeoutCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables I2C Idle Clock Timeout (Bus idle SCL and SDA high detection). ...
void I2C_NumberOfBytesConfig(I2C_TypeDef *I2Cx, uint8_t Number_Bytes)
Configures the number of bytes to be transmitted/received.
uint16_t I2C_ReadRegister(I2C_TypeDef *I2Cx, uint8_t I2C_Register)
Reads the specified I2C register and returns its value.
void I2C_MasterRequestConfig(I2C_TypeDef *I2Cx, uint16_t I2C_Direction)
Configures the type of transfer request for the master.
void I2C_StretchClockCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the I2C Clock stretching.
void I2C_ITConfig(I2C_TypeDef *I2Cx, uint32_t I2C_IT, FunctionalState NewState)
Enables or disables the specified I2C interrupts.
void I2C_SlaveByteControlCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the I2C slave byte control.
FlagStatus I2C_GetFlagStatus(I2C_TypeDef *I2Cx, uint32_t I2C_FLAG)
Checks whether the specified I2C flag is set or not.
Inter-integrated Circuit Interface.
Definition: stm32f4xx.h:1320
void I2C_10BitAddressingModeCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the I2C 10-bit addressing mode for the master.
void I2C_SendData(I2C_TypeDef *I2Cx, uint8_t Data)
Sends a data byte through the I2Cx peripheral.
void I2C_ClockTimeoutCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables I2C Clock Timeout (SCL Timeout detection).
uint32_t I2C_AnalogFilter
Definition: stm32f30x_i2c.h:60
uint8_t I2C_GetAddressMatched(I2C_TypeDef *I2Cx)
Returns the I2C slave matched address .


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Apr 15 2021 05:07:48