Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 5 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /** |
1 | /** |
2 | ****************************************************************************** |
2 | ****************************************************************************** |
3 | * @file stm32f1xx_hal_i2c.h |
3 | * @file stm32f1xx_hal_i2c.h |
4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
5 | * @version V1.0.1 |
5 | * @version V1.0.4 |
6 | * @date 31-July-2015 |
6 | * @date 29-April-2016 |
7 | * @brief Header file of I2C HAL module. |
7 | * @brief Header file of I2C HAL module. |
8 | ****************************************************************************** |
8 | ****************************************************************************** |
9 | * @attention |
9 | * @attention |
10 | * |
10 | * |
11 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
11 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
12 | * |
12 | * |
13 | * Redistribution and use in source and binary forms, with or without modification, |
13 | * Redistribution and use in source and binary forms, with or without modification, |
14 | * are permitted provided that the following conditions are met: |
14 | * are permitted provided that the following conditions are met: |
15 | * 1. Redistributions of source code must retain the above copyright notice, |
15 | * 1. Redistributions of source code must retain the above copyright notice, |
16 | * this list of conditions and the following disclaimer. |
16 | * this list of conditions and the following disclaimer. |
Line 100... | Line 100... | ||
100 | * @{ |
100 | * @{ |
101 | */ |
101 | */ |
102 | 102 | ||
103 | typedef enum |
103 | typedef enum |
104 | { |
104 | { |
105 | HAL_I2C_STATE_RESET = 0x00, /*!< I2C not yet initialized or disabled */ |
105 | HAL_I2C_STATE_RESET = 0x00, /*!< Peripheral is not yet Initialized */ |
106 | HAL_I2C_STATE_READY = 0x01, /*!< I2C initialized and ready for use */ |
106 | HAL_I2C_STATE_READY = 0x20, /*!< Peripheral Initialized and ready for use */ |
107 | HAL_I2C_STATE_BUSY = 0x02, /*!< I2C internal process is ongoing */ |
107 | HAL_I2C_STATE_BUSY = 0x24, /*!< An internal process is ongoing */ |
108 | HAL_I2C_STATE_BUSY_TX = 0x12, /*!< Data Transmission process is ongoing */ |
108 | HAL_I2C_STATE_BUSY_TX = 0x21, /*!< Data Transmission process is ongoing */ |
109 | HAL_I2C_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */ |
109 | HAL_I2C_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */ |
110 | HAL_I2C_STATE_MEM_BUSY_TX = 0x32, /*!< Memory Data Transmission process is ongoing */ |
- | |
111 | HAL_I2C_STATE_MEM_BUSY_RX = 0x42, /*!< Memory Data Reception process is ongoing */ |
- | |
112 | HAL_I2C_STATE_TIMEOUT = 0x03, /*!< I2C timeout state */ |
110 | HAL_I2C_STATE_TIMEOUT = 0xA0, /*!< Timeout state */ |
113 | HAL_I2C_STATE_ERROR = 0x04 /*!< I2C error state */ |
111 | HAL_I2C_STATE_ERROR = 0xE0 /*!< Error */ |
114 | 112 | ||
115 | }HAL_I2C_StateTypeDef; |
113 | }HAL_I2C_StateTypeDef; |
116 | 114 | ||
117 | /** |
115 | /** |
118 | * @} |
116 | * @} |
119 | */ |
117 | */ |
120 | 118 | ||
- | 119 | /** @defgroup HAL_mode_structure_definition HAL mode structure definition |
|
- | 120 | * @brief HAL Mode structure definition |
|
- | 121 | * @{ |
|
- | 122 | */ |
|
- | 123 | typedef enum |
|
- | 124 | { |
|
- | 125 | HAL_I2C_MODE_NONE = 0x00, /*!< No I2C communication on going */ |
|
- | 126 | HAL_I2C_MODE_MASTER = 0x10, /*!< I2C communication is in Master Mode */ |
|
- | 127 | HAL_I2C_MODE_SLAVE = 0x20, /*!< I2C communication is in Slave Mode */ |
|
- | 128 | HAL_I2C_MODE_MEM = 0x40 /*!< I2C communication is in Memory Mode */ |
|
- | 129 | ||
- | 130 | }HAL_I2C_ModeTypeDef; |
|
- | 131 | ||
- | 132 | /** |
|
- | 133 | * @} |
|
- | 134 | */ |
|
- | 135 | ||
121 | /** @defgroup I2C_handle_Structure_definition I2C handle Structure definition |
136 | /** @defgroup I2C_handle_Structure_definition I2C handle Structure definition |
122 | * @brief I2C handle Structure definition |
137 | * @brief I2C handle Structure definition |
123 | * @{ |
138 | * @{ |
124 | */ |
139 | */ |
125 | typedef struct |
140 | typedef struct |
Line 140... | Line 155... | ||
140 | 155 | ||
141 | HAL_LockTypeDef Lock; /*!< I2C locking object */ |
156 | HAL_LockTypeDef Lock; /*!< I2C locking object */ |
142 | 157 | ||
143 | __IO HAL_I2C_StateTypeDef State; /*!< I2C communication state */ |
158 | __IO HAL_I2C_StateTypeDef State; /*!< I2C communication state */ |
144 | 159 | ||
- | 160 | __IO HAL_I2C_ModeTypeDef Mode; /*!< I2C communication mode */ |
|
- | 161 | ||
145 | __IO uint32_t ErrorCode; /* I2C Error code */ |
162 | __IO uint32_t ErrorCode; /*!< I2C Error code */ |
146 | 163 | ||
147 | }I2C_HandleTypeDef; |
164 | }I2C_HandleTypeDef; |
148 | /** |
165 | /** |
149 | * @} |
166 | * @} |
150 | */ |
167 | */ |
Line 280... | Line 297... | ||
280 | 297 | ||
281 | /** @defgroup I2C_Exported_Macros I2C Exported Macros |
298 | /** @defgroup I2C_Exported_Macros I2C Exported Macros |
282 | * @{ |
299 | * @{ |
283 | */ |
300 | */ |
284 | 301 | ||
285 | /** @brief Reset I2C handle state |
302 | /** @brief Reset I2C handle state. |
286 | * @param __HANDLE__: specifies the I2C Handle. |
303 | * @param __HANDLE__ specifies the I2C Handle. |
287 | * @retval None |
304 | * @retval None |
288 | */ |
305 | */ |
289 | #define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2C_STATE_RESET) |
306 | #define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2C_STATE_RESET) |
290 | 307 | ||
291 | /** @brief Enable the specified I2C interrupts. |
308 | /** @brief Enable the specified I2C interrupt. |
292 | * @param __HANDLE__: specifies the I2C Handle. |
309 | * @param __HANDLE__ specifies the I2C Handle. |
293 | * @param __INTERRUPT__: specifies the interrupt source to enable. |
310 | * @param __INTERRUPT__: specifies the interrupt source to enable. |
294 | * This parameter can be one of the following values: |
311 | * This parameter can be one of the following values: |
295 | * @arg I2C_IT_BUF: Buffer interrupt enable |
312 | * @arg @ref I2C_IT_BUF Buffer interrupt enable |
296 | * @arg I2C_IT_EVT: Event interrupt enable |
313 | * @arg @ref I2C_IT_EVT Event interrupt enable |
297 | * @arg I2C_IT_ERR: Error interrupt enable |
314 | * @arg @ref I2C_IT_ERR Error interrupt enable |
298 | * @retval None |
315 | * @retval None |
299 | */ |
316 | */ |
300 | #define __HAL_I2C_ENABLE_IT(__HANDLE__, __INTERRUPT__) (SET_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__))) |
317 | #define __HAL_I2C_ENABLE_IT(__HANDLE__, __INTERRUPT__) (SET_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__))) |
301 | 318 | ||
302 | /** @brief Disable the specified I2C interrupts. |
319 | /** @brief Disable the specified I2C interrupt. |
303 | * @param __HANDLE__: specifies the I2C Handle. |
320 | * @param __HANDLE__ specifies the I2C Handle. |
304 | * @param __INTERRUPT__: specifies the interrupt source to disable. |
321 | * @param __INTERRUPT__: specifies the interrupt source to disable. |
305 | * This parameter can be one of the following values: |
322 | * This parameter can be one of the following values: |
306 | * @arg I2C_IT_BUF: Buffer interrupt enable |
323 | * @arg @ref I2C_IT_BUF Buffer interrupt enable |
307 | * @arg I2C_IT_EVT: Event interrupt enable |
324 | * @arg @ref I2C_IT_EVT Event interrupt enable |
308 | * @arg I2C_IT_ERR: Error interrupt enable |
325 | * @arg @ref I2C_IT_ERR Error interrupt enable |
309 | * @retval None |
326 | * @retval None |
310 | */ |
327 | */ |
311 | #define __HAL_I2C_DISABLE_IT(__HANDLE__, __INTERRUPT__) (CLEAR_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__))) |
328 | #define __HAL_I2C_DISABLE_IT(__HANDLE__, __INTERRUPT__) (CLEAR_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__))) |
312 | 329 | ||
313 | /** @brief Checks if the specified I2C interrupt source is enabled or disabled. |
330 | /** @brief Check whether the specified I2C interrupt source is enabled or not. |
314 | * @param __HANDLE__: specifies the I2C Handle. |
331 | * @param __HANDLE__ specifies the I2C Handle. |
315 | * @param __INTERRUPT__: specifies the I2C interrupt source to check. |
332 | * @param __INTERRUPT__: specifies the I2C interrupt source to check. |
316 | * This parameter can be one of the following values: |
333 | * This parameter can be one of the following values: |
317 | * @arg I2C_IT_BUF: Buffer interrupt enable |
334 | * @arg @ref I2C_IT_BUF Buffer interrupt enable |
318 | * @arg I2C_IT_EVT: Event interrupt enable |
335 | * @arg @ref I2C_IT_EVT Event interrupt enable |
319 | * @arg I2C_IT_ERR: Error interrupt enable |
336 | * @arg @ref I2C_IT_ERR Error interrupt enable |
320 | * @retval The new state of __INTERRUPT__ (TRUE or FALSE). |
337 | * @retval The new state of __INTERRUPT__ (TRUE or FALSE). |
321 | */ |
338 | */ |
322 | #define __HAL_I2C_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET) |
339 | #define __HAL_I2C_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET) |
323 | 340 | ||
324 | /** @brief Checks whether the specified I2C flag is set or not. |
341 | /** @brief Check whether the specified I2C flag is set or not. |
325 | * @param __HANDLE__: specifies the I2C Handle. |
342 | * @param __HANDLE__ specifies the I2C Handle. |
326 | * @param __FLAG__: specifies the flag to check. |
343 | * @param __FLAG__ specifies the flag to check. |
327 | * This parameter can be one of the following values: |
344 | * This parameter can be one of the following values: |
328 | * @arg I2C_FLAG_SMBALERT: SMBus Alert flag |
345 | * @arg @ref I2C_FLAG_SMBALERT SMBus Alert flag |
329 | * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag |
346 | * @arg @ref I2C_FLAG_TIMEOUT Timeout or Tlow error flag |
330 | * @arg I2C_FLAG_PECERR: PEC error in reception flag |
347 | * @arg @ref I2C_FLAG_PECERR PEC error in reception flag |
331 | * @arg I2C_FLAG_OVR: Overrun/Underrun flag |
348 | * @arg @ref I2C_FLAG_OVR Overrun/Underrun flag |
332 | * @arg I2C_FLAG_AF: Acknowledge failure flag |
349 | * @arg @ref I2C_FLAG_AF Acknowledge failure flag |
333 | * @arg I2C_FLAG_ARLO: Arbitration lost flag |
350 | * @arg @ref I2C_FLAG_ARLO Arbitration lost flag |
334 | * @arg I2C_FLAG_BERR: Bus error flag |
351 | * @arg @ref I2C_FLAG_BERR Bus error flag |
335 | * @arg I2C_FLAG_TXE: Data register empty flag |
352 | * @arg @ref I2C_FLAG_TXE Data register empty flag |
336 | * @arg I2C_FLAG_RXNE: Data register not empty flag |
353 | * @arg @ref I2C_FLAG_RXNE Data register not empty flag |
337 | * @arg I2C_FLAG_STOPF: Stop detection flag |
354 | * @arg @ref I2C_FLAG_STOPF Stop detection flag |
338 | * @arg I2C_FLAG_ADD10: 10-bit header sent flag |
355 | * @arg @ref I2C_FLAG_ADD10 10-bit header sent flag |
339 | * @arg I2C_FLAG_BTF: Byte transfer finished flag |
356 | * @arg @ref I2C_FLAG_BTF Byte transfer finished flag |
340 | * @arg I2C_FLAG_ADDR: Address sent flag |
357 | * @arg @ref I2C_FLAG_ADDR Address sent flag |
341 | * Address matched flag |
358 | * Address matched flag |
342 | * @arg I2C_FLAG_SB: Start bit flag |
359 | * @arg @ref I2C_FLAG_SB Start bit flag |
343 | * @arg I2C_FLAG_DUALF: Dual flag |
360 | * @arg @ref I2C_FLAG_DUALF Dual flag |
344 | * @arg I2C_FLAG_SMBHOST: SMBus host header |
361 | * @arg @ref I2C_FLAG_SMBHOST SMBus host header |
345 | * @arg I2C_FLAG_SMBDEFAULT: SMBus default header |
362 | * @arg @ref I2C_FLAG_SMBDEFAULT SMBus default header |
346 | * @arg I2C_FLAG_GENCALL: General call header flag |
363 | * @arg @ref I2C_FLAG_GENCALL General call header flag |
347 | * @arg I2C_FLAG_TRA: Transmitter/Receiver flag |
364 | * @arg @ref I2C_FLAG_TRA Transmitter/Receiver flag |
348 | * @arg I2C_FLAG_BUSY: Bus busy flag |
365 | * @arg @ref I2C_FLAG_BUSY Bus busy flag |
349 | * @arg I2C_FLAG_MSL: Master/Slave flag |
366 | * @arg @ref I2C_FLAG_MSL Master/Slave flag |
350 | * @retval The new state of __FLAG__ (TRUE or FALSE). |
367 | * @retval The new state of __FLAG__ (TRUE or FALSE). |
351 | */ |
368 | */ |
352 | #define __HAL_I2C_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 16)) == 0x01)?((((__HANDLE__)->Instance->SR1) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)): \ |
369 | #define __HAL_I2C_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 16)) == 0x01)?((((__HANDLE__)->Instance->SR1) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)): \ |
353 | ((((__HANDLE__)->Instance->SR2) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK))) |
370 | ((((__HANDLE__)->Instance->SR2) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK))) |
354 | 371 | ||
355 | /** @brief Clears the I2C pending flags which are cleared by writing 0 in a specific bit. |
372 | /** @brief Clear the I2C pending flags which are cleared by writing 0 in a specific bit. |
356 | * @param __HANDLE__: specifies the I2C Handle. |
373 | * @param __HANDLE__ specifies the I2C Handle. |
357 | * @param __FLAG__: specifies the flag to clear. |
374 | * @param __FLAG__ specifies the flag to clear. |
358 | * This parameter can be any combination of the following values: |
375 | * This parameter can be any combination of the following values: |
359 | * @arg I2C_FLAG_SMBALERT: SMBus Alert flag |
376 | * @arg @ref I2C_FLAG_SMBALERT SMBus Alert flag |
360 | * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag |
377 | * @arg @ref I2C_FLAG_TIMEOUT Timeout or Tlow error flag |
361 | * @arg I2C_FLAG_PECERR: PEC error in reception flag |
378 | * @arg @ref I2C_FLAG_PECERR PEC error in reception flag |
362 | * @arg I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode) |
379 | * @arg @ref I2C_FLAG_OVR Overrun/Underrun flag (Slave mode) |
363 | * @arg I2C_FLAG_AF: Acknowledge failure flag |
380 | * @arg @ref I2C_FLAG_AF Acknowledge failure flag |
364 | * @arg I2C_FLAG_ARLO: Arbitration lost flag (Master mode) |
381 | * @arg @ref I2C_FLAG_ARLO Arbitration lost flag (Master mode) |
365 | * @arg I2C_FLAG_BERR: Bus error flag |
382 | * @arg @ref I2C_FLAG_BERR Bus error flag |
- | 383 | * |
|
366 | * @retval None |
384 | * @retval None |
367 | */ |
385 | */ |
368 | #define __HAL_I2C_CLEAR_FLAG(__HANDLE__, __FLAG__) (__HANDLE__)->Instance->SR1 = (((__HANDLE__)->Instance->SR1) & (~((__FLAG__) & I2C_FLAG_MASK))) |
386 | #define __HAL_I2C_CLEAR_FLAG(__HANDLE__, __FLAG__) (__HANDLE__)->Instance->SR1 = (((__HANDLE__)->Instance->SR1) & (~((__FLAG__) & I2C_FLAG_MASK))) |
369 | 387 | ||
370 | /** @brief Clears the I2C ADDR pending flag. |
388 | /** @brief Clears the I2C ADDR pending flag. |
Line 390... | Line 408... | ||
390 | tmpreg = (__HANDLE__)->Instance->CR1 |= I2C_CR1_PE; \ |
408 | tmpreg = (__HANDLE__)->Instance->CR1 |= I2C_CR1_PE; \ |
391 | UNUSED(tmpreg); \ |
409 | UNUSED(tmpreg); \ |
392 | }while(0) |
410 | }while(0) |
393 | 411 | ||
394 | /** @brief Enable the specified I2C peripheral. |
412 | /** @brief Enable the specified I2C peripheral. |
395 | * @param __HANDLE__: specifies the I2C Handle. |
413 | * @param __HANDLE__ specifies the I2C Handle. |
396 | * @retval None |
414 | * @retval None |
397 | */ |
415 | */ |
398 | #define __HAL_I2C_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE)) |
416 | #define __HAL_I2C_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE)) |
399 | 417 | ||
400 | /** @brief Disable the specified I2C peripheral. |
418 | /** @brief Disable the specified I2C peripheral. |
401 | * @param __HANDLE__: specifies the I2C Handle. |
419 | * @param __HANDLE__ specifies the I2C Handle. |
402 | * @retval None |
420 | * @retval None |
403 | */ |
421 | */ |
404 | #define __HAL_I2C_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE)) |
422 | #define __HAL_I2C_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE)) |
405 | 423 | ||
406 | /** |
424 | /** |