23 #ifndef __STM32F10x_I2C_H
24 #define __STM32F10x_I2C_H
31 #include "stm32f10x.h"
51 uint32_t I2C_ClockSpeed;
57 uint16_t I2C_DutyCycle;
60 uint16_t I2C_OwnAddress1;
66 uint16_t I2C_AcknowledgedAddress;
79 #define IS_I2C_ALL_PERIPH(PERIPH) (((PERIPH) == I2C1) || \
85 #define I2C_Mode_I2C ((uint16_t)0x0000)
86 #define I2C_Mode_SMBusDevice ((uint16_t)0x0002)
87 #define I2C_Mode_SMBusHost ((uint16_t)0x000A)
88 #define IS_I2C_MODE(MODE) (((MODE) == I2C_Mode_I2C) || \
89 ((MODE) == I2C_Mode_SMBusDevice) || \
90 ((MODE) == I2C_Mode_SMBusHost))
99 #define I2C_DutyCycle_16_9 ((uint16_t)0x4000)
100 #define I2C_DutyCycle_2 ((uint16_t)0xBFFF)
101 #define IS_I2C_DUTY_CYCLE(CYCLE) (((CYCLE) == I2C_DutyCycle_16_9) || \
102 ((CYCLE) == I2C_DutyCycle_2))
111 #define I2C_Ack_Enable ((uint16_t)0x0400)
112 #define I2C_Ack_Disable ((uint16_t)0x0000)
113 #define IS_I2C_ACK_STATE(STATE) (((STATE) == I2C_Ack_Enable) || \
114 ((STATE) == I2C_Ack_Disable))
123 #define I2C_Direction_Transmitter ((uint8_t)0x00)
124 #define I2C_Direction_Receiver ((uint8_t)0x01)
125 #define IS_I2C_DIRECTION(DIRECTION) (((DIRECTION) == I2C_Direction_Transmitter) || \
126 ((DIRECTION) == I2C_Direction_Receiver))
135 #define I2C_AcknowledgedAddress_7bit ((uint16_t)0x4000)
136 #define I2C_AcknowledgedAddress_10bit ((uint16_t)0xC000)
137 #define IS_I2C_ACKNOWLEDGE_ADDRESS(ADDRESS) (((ADDRESS) == I2C_AcknowledgedAddress_7bit) || \
138 ((ADDRESS) == I2C_AcknowledgedAddress_10bit))
147 #define I2C_Register_CR1 ((uint8_t)0x00)
148 #define I2C_Register_CR2 ((uint8_t)0x04)
149 #define I2C_Register_OAR1 ((uint8_t)0x08)
150 #define I2C_Register_OAR2 ((uint8_t)0x0C)
151 #define I2C_Register_DR ((uint8_t)0x10)
152 #define I2C_Register_SR1 ((uint8_t)0x14)
153 #define I2C_Register_SR2 ((uint8_t)0x18)
154 #define I2C_Register_CCR ((uint8_t)0x1C)
155 #define I2C_Register_TRISE ((uint8_t)0x20)
156 #define IS_I2C_REGISTER(REGISTER) (((REGISTER) == I2C_Register_CR1) || \
157 ((REGISTER) == I2C_Register_CR2) || \
158 ((REGISTER) == I2C_Register_OAR1) || \
159 ((REGISTER) == I2C_Register_OAR2) || \
160 ((REGISTER) == I2C_Register_DR) || \
161 ((REGISTER) == I2C_Register_SR1) || \
162 ((REGISTER) == I2C_Register_SR2) || \
163 ((REGISTER) == I2C_Register_CCR) || \
164 ((REGISTER) == I2C_Register_TRISE))
173 #define I2C_SMBusAlert_Low ((uint16_t)0x2000)
174 #define I2C_SMBusAlert_High ((uint16_t)0xDFFF)
175 #define IS_I2C_SMBUS_ALERT(ALERT) (((ALERT) == I2C_SMBusAlert_Low) || \
176 ((ALERT) == I2C_SMBusAlert_High))
185 #define I2C_PECPosition_Next ((uint16_t)0x0800)
186 #define I2C_PECPosition_Current ((uint16_t)0xF7FF)
187 #define IS_I2C_PEC_POSITION(POSITION) (((POSITION) == I2C_PECPosition_Next) || \
188 ((POSITION) == I2C_PECPosition_Current))
197 #define I2C_IT_BUF ((uint16_t)0x0400)
198 #define I2C_IT_EVT ((uint16_t)0x0200)
199 #define I2C_IT_ERR ((uint16_t)0x0100)
200 #define IS_I2C_CONFIG_IT(IT) ((((IT) & (uint16_t)0xF8FF) == 0x00) && ((IT) != 0x00))
209 #define I2C_IT_SMBALERT ((uint32_t)0x01008000)
210 #define I2C_IT_TIMEOUT ((uint32_t)0x01004000)
211 #define I2C_IT_PECERR ((uint32_t)0x01001000)
212 #define I2C_IT_OVR ((uint32_t)0x01000800)
213 #define I2C_IT_AF ((uint32_t)0x01000400)
214 #define I2C_IT_ARLO ((uint32_t)0x01000200)
215 #define I2C_IT_BERR ((uint32_t)0x01000100)
216 #define I2C_IT_TXE ((uint32_t)0x06000080)
217 #define I2C_IT_RXNE ((uint32_t)0x06000040)
218 #define I2C_IT_STOPF ((uint32_t)0x02000010)
219 #define I2C_IT_ADD10 ((uint32_t)0x02000008)
220 #define I2C_IT_BTF ((uint32_t)0x02000004)
221 #define I2C_IT_ADDR ((uint32_t)0x02000002)
222 #define I2C_IT_SB ((uint32_t)0x02000001)
224 #define IS_I2C_CLEAR_IT(IT) ((((IT) & (uint16_t)0x20FF) == 0x00) && ((IT) != (uint16_t)0x00))
226 #define IS_I2C_GET_IT(IT) (((IT) == I2C_IT_SMBALERT) || ((IT) == I2C_IT_TIMEOUT) || \
227 ((IT) == I2C_IT_PECERR) || ((IT) == I2C_IT_OVR) || \
228 ((IT) == I2C_IT_AF) || ((IT) == I2C_IT_ARLO) || \
229 ((IT) == I2C_IT_BERR) || ((IT) == I2C_IT_TXE) || \
230 ((IT) == I2C_IT_RXNE) || ((IT) == I2C_IT_STOPF) || \
231 ((IT) == I2C_IT_ADD10) || ((IT) == I2C_IT_BTF) || \
232 ((IT) == I2C_IT_ADDR) || ((IT) == I2C_IT_SB))
245 #define I2C_FLAG_DUALF ((uint32_t)0x00800000)
246 #define I2C_FLAG_SMBHOST ((uint32_t)0x00400000)
247 #define I2C_FLAG_SMBDEFAULT ((uint32_t)0x00200000)
248 #define I2C_FLAG_GENCALL ((uint32_t)0x00100000)
249 #define I2C_FLAG_TRA ((uint32_t)0x00040000)
250 #define I2C_FLAG_BUSY ((uint32_t)0x00020000)
251 #define I2C_FLAG_MSL ((uint32_t)0x00010000)
257 #define I2C_FLAG_SMBALERT ((uint32_t)0x10008000)
258 #define I2C_FLAG_TIMEOUT ((uint32_t)0x10004000)
259 #define I2C_FLAG_PECERR ((uint32_t)0x10001000)
260 #define I2C_FLAG_OVR ((uint32_t)0x10000800)
261 #define I2C_FLAG_AF ((uint32_t)0x10000400)
262 #define I2C_FLAG_ARLO ((uint32_t)0x10000200)
263 #define I2C_FLAG_BERR ((uint32_t)0x10000100)
264 #define I2C_FLAG_TXE ((uint32_t)0x10000080)
265 #define I2C_FLAG_RXNE ((uint32_t)0x10000040)
266 #define I2C_FLAG_STOPF ((uint32_t)0x10000010)
267 #define I2C_FLAG_ADD10 ((uint32_t)0x10000008)
268 #define I2C_FLAG_BTF ((uint32_t)0x10000004)
269 #define I2C_FLAG_ADDR ((uint32_t)0x10000002)
270 #define I2C_FLAG_SB ((uint32_t)0x10000001)
272 #define IS_I2C_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0x20FF) == 0x00) && ((FLAG) != (uint16_t)0x00))
274 #define IS_I2C_GET_FLAG(FLAG) (((FLAG) == I2C_FLAG_DUALF) || ((FLAG) == I2C_FLAG_SMBHOST) || \
275 ((FLAG) == I2C_FLAG_SMBDEFAULT) || ((FLAG) == I2C_FLAG_GENCALL) || \
276 ((FLAG) == I2C_FLAG_TRA) || ((FLAG) == I2C_FLAG_BUSY) || \
277 ((FLAG) == I2C_FLAG_MSL) || ((FLAG) == I2C_FLAG_SMBALERT) || \
278 ((FLAG) == I2C_FLAG_TIMEOUT) || ((FLAG) == I2C_FLAG_PECERR) || \
279 ((FLAG) == I2C_FLAG_OVR) || ((FLAG) == I2C_FLAG_AF) || \
280 ((FLAG) == I2C_FLAG_ARLO) || ((FLAG) == I2C_FLAG_BERR) || \
281 ((FLAG) == I2C_FLAG_TXE) || ((FLAG) == I2C_FLAG_RXNE) || \
282 ((FLAG) == I2C_FLAG_STOPF) || ((FLAG) == I2C_FLAG_ADD10) || \
283 ((FLAG) == I2C_FLAG_BTF) || ((FLAG) == I2C_FLAG_ADDR) || \
284 ((FLAG) == I2C_FLAG_SB))
306 #define I2C_EVENT_MASTER_MODE_SELECT ((uint32_t)0x00030001)
334 #define I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED ((uint32_t)0x00070082)
335 #define I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED ((uint32_t)0x00030002)
337 #define I2C_EVENT_MASTER_MODE_ADDRESS10 ((uint32_t)0x00030008)
370 #define I2C_EVENT_MASTER_BYTE_RECEIVED ((uint32_t)0x00030040)
374 #define I2C_EVENT_MASTER_BYTE_TRANSMITTING ((uint32_t)0x00070080)
376 #define I2C_EVENT_MASTER_BYTE_TRANSMITTED ((uint32_t)0x00070084)
411 #define I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED ((uint32_t)0x00020002)
412 #define I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED ((uint32_t)0x00060082)
415 #define I2C_EVENT_SLAVE_RECEIVER_SECONDADDRESS_MATCHED ((uint32_t)0x00820000)
416 #define I2C_EVENT_SLAVE_TRANSMITTER_SECONDADDRESS_MATCHED ((uint32_t)0x00860080)
419 #define I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED ((uint32_t)0x00120000)
450 #define I2C_EVENT_SLAVE_BYTE_RECEIVED ((uint32_t)0x00020040)
452 #define I2C_EVENT_SLAVE_STOP_DETECTED ((uint32_t)0x00000010)
456 #define I2C_EVENT_SLAVE_BYTE_TRANSMITTED ((uint32_t)0x00060084)
457 #define I2C_EVENT_SLAVE_BYTE_TRANSMITTING ((uint32_t)0x00060080)
459 #define I2C_EVENT_SLAVE_ACK_FAILURE ((uint32_t)0x00000400)
463 #define IS_I2C_EVENT(EVENT) (((EVENT) == I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED) || \
464 ((EVENT) == I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED) || \
465 ((EVENT) == I2C_EVENT_SLAVE_TRANSMITTER_SECONDADDRESS_MATCHED) || \
466 ((EVENT) == I2C_EVENT_SLAVE_RECEIVER_SECONDADDRESS_MATCHED) || \
467 ((EVENT) == I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED) || \
468 ((EVENT) == I2C_EVENT_SLAVE_BYTE_RECEIVED) || \
469 ((EVENT) == (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_DUALF)) || \
470 ((EVENT) == (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_GENCALL)) || \
471 ((EVENT) == I2C_EVENT_SLAVE_BYTE_TRANSMITTED) || \
472 ((EVENT) == (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_DUALF)) || \
473 ((EVENT) == (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_GENCALL)) || \
474 ((EVENT) == I2C_EVENT_SLAVE_STOP_DETECTED) || \
475 ((EVENT) == I2C_EVENT_MASTER_MODE_SELECT) || \
476 ((EVENT) == I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED) || \
477 ((EVENT) == I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED) || \
478 ((EVENT) == I2C_EVENT_MASTER_BYTE_RECEIVED) || \
479 ((EVENT) == I2C_EVENT_MASTER_BYTE_TRANSMITTED) || \
480 ((EVENT) == I2C_EVENT_MASTER_BYTE_TRANSMITTING) || \
481 ((EVENT) == I2C_EVENT_MASTER_MODE_ADDRESS10) || \
482 ((EVENT) == I2C_EVENT_SLAVE_ACK_FAILURE))
491 #define IS_I2C_OWN_ADDRESS1(ADDRESS1) ((ADDRESS1) <= 0x3FF)
500 #define IS_I2C_CLOCK_SPEED(SPEED) (((SPEED) >= 0x1) && ((SPEED) <= 400000))
524 void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
525 void I2C_DMACmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
533 void I2C_ITConfig(I2C_TypeDef* I2Cx, uint16_t I2C_IT, FunctionalState NewState);
544 void I2C_ARPCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
631 ErrorStatus
I2C_CheckEvent(I2C_TypeDef* I2Cx, uint32_t I2C_EVENT);