LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
i2c_001.h
Go to the documentation of this file.
1 /*
2  * @brief I2C registers and driver functions
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products. This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights. NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers. This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #ifndef __I2C_001_H_
33 #define __I2C_001_H_
34 
35 #include "sys_config.h"
36 #include "cmsis.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
50 typedef struct {
52  __I uint32_t STAT;
53  __IO uint32_t DAT;
54  __IO uint32_t ADR0;
55  __IO uint32_t SCLH;
56  __IO uint32_t SCLL;
59  __IO uint32_t ADR1;
60  __IO uint32_t ADR2;
61  __IO uint32_t ADR3;
63  __IO uint32_t MASK[4];
65 
69 #define I2C_STA_STO_RECV 0x20
70 
74 #define I2C_I2CONSET_AA ((0x04))
75 #define I2C_I2CONSET_SI ((0x08))
76 #define I2C_I2CONSET_STO ((0x10))
77 #define I2C_I2CONSET_STA ((0x20))
78 #define I2C_I2CONSET_I2EN ((0x40))
83 #define I2C_I2CONCLR_AAC ((1 << 2))
84 #define I2C_I2CONCLR_SIC ((1 << 3))
85 #define I2C_I2CONCLR_STOC ((1 << 4))
86 #define I2C_I2CONCLR_STAC ((1 << 5))
87 #define I2C_I2CONCLR_I2ENC ((1 << 6))
92 #define I2C_STAT_CODE_BITMASK ((0xF8))
93 #define I2C_STAT_CODE_ERROR ((0xFF))
98 #define I2C_I2STAT_NO_INF ((0xF8))
99 #define I2C_I2STAT_BUS_ERROR ((0x00))
104 #define I2C_I2STAT_M_TX_START ((0x08))
105 #define I2C_I2STAT_M_TX_RESTART ((0x10))
106 #define I2C_I2STAT_M_TX_SLAW_ACK ((0x18))
107 #define I2C_I2STAT_M_TX_SLAW_NACK ((0x20))
108 #define I2C_I2STAT_M_TX_DAT_ACK ((0x28))
109 #define I2C_I2STAT_M_TX_DAT_NACK ((0x30))
110 #define I2C_I2STAT_M_TX_ARB_LOST ((0x38))
115 #define I2C_I2STAT_M_RX_START ((0x08))
116 #define I2C_I2STAT_M_RX_RESTART ((0x10))
117 #define I2C_I2STAT_M_RX_ARB_LOST ((0x38))
118 #define I2C_I2STAT_M_RX_SLAR_ACK ((0x40))
119 #define I2C_I2STAT_M_RX_SLAR_NACK ((0x48))
120 #define I2C_I2STAT_M_RX_DAT_ACK ((0x50))
121 #define I2C_I2STAT_M_RX_DAT_NACK ((0x58))
126 #define I2C_I2STAT_S_RX_SLAW_ACK ((0x60))
127 #define I2C_I2STAT_S_RX_ARB_LOST_M_SLA ((0x68))
128 // #define I2C_I2STAT_S_RX_SLAW_ACK ((0x68))
129 #define I2C_I2STAT_S_RX_GENCALL_ACK ((0x70))
130 #define I2C_I2STAT_S_RX_ARB_LOST_M_GENCALL ((0x78))
131 // #define I2C_I2STAT_S_RX_GENCALL_ACK ((0x78))
132 #define I2C_I2STAT_S_RX_PRE_SLA_DAT_ACK ((0x80))
133 #define I2C_I2STAT_S_RX_PRE_SLA_DAT_NACK ((0x88))
134 #define I2C_I2STAT_S_RX_PRE_GENCALL_DAT_ACK ((0x90))
135 #define I2C_I2STAT_S_RX_PRE_GENCALL_DAT_NACK ((0x98))
136 #define I2C_I2STAT_S_RX_STA_STO_SLVREC_SLVTRX ((0xA0))
142 #define I2C_I2STAT_S_TX_SLAR_ACK ((0xA8))
143 #define I2C_I2STAT_S_TX_ARB_LOST_M_SLA ((0xB0))
144 // #define I2C_I2STAT_S_TX_SLAR_ACK ((0xB0))
145 #define I2C_I2STAT_S_TX_DAT_ACK ((0xB8))
146 #define I2C_I2STAT_S_TX_DAT_NACK ((0xC0))
147 #define I2C_I2STAT_S_TX_LAST_DAT_ACK ((0xC8))
148 #define I2C_SLAVE_TIME_OUT 0x10000000UL
153 #define I2C_I2DAT_BITMASK ((0xFF))
154 #define I2C_I2DAT_IDLE_CHAR (0xFF)
160 #define I2C_I2MMCTRL_MM_ENA ((1 << 0))
161 #define I2C_I2MMCTRL_ENA_SCL ((1 << 1))
162 #define I2C_I2MMCTRL_MATCH_ALL ((1 << 2))
163 #define I2C_I2MMCTRL_BITMASK ((0x07))
168 #define I2DATA_BUFFER_BITMASK ((0xFF))
173 #define I2C_I2ADR_GC ((1 << 0))
174 #define I2C_I2ADR_BITMASK ((0xFF))
179 #define I2C_I2MASK_MASK(n) ((n & 0xFE))
184 #define I2C_I2SCLH_BITMASK ((0xFFFF))
189 #define I2C_I2SCLL_BITMASK ((0xFFFF))
194 #define I2C_SETUP_STATUS_ARBF (1 << 8)
195 #define I2C_SETUP_STATUS_NOACKF (1 << 9)
196 #define I2C_SETUP_STATUS_DONE (1 << 10)
201 #define I2C_OK 0x00
202 #define I2C_BYTE_SENT 0x01
203 #define I2C_BYTE_RECV 0x02
204 #define I2C_LAST_BYTE_RECV 0x04
205 #define I2C_SEND_END 0x08
206 #define I2C_RECV_END 0x10
207 #define I2C_STA_STO_RECV 0x20
208 
209 #define I2C_ERR (0x10000000)
210 #define I2C_NAK_RECV (0x10000000 | 0x01)
211 
212 #define I2C_CheckError(ErrorCode) (ErrorCode & 0x10000000)
213 
217 #define I2C_MONITOR_CFG_SCL_OUTPUT I2C_I2MMCTRL_ENA_SCL
218 #define I2C_MONITOR_CFG_MATCHALL I2C_I2MMCTRL_MATCH_ALL
223 typedef struct {
225  uint8_t *tx_data;
228  uint8_t *rx_data;
235 
239 typedef struct {
240  uint8_t *tx_data;
243  uint8_t *rx_data;
248 
252 typedef enum {
256 
260 typedef struct {
262  uint8_t SlaveAddr_7bit;
263  uint8_t GeneralCallState;
266  uint8_t SlaveAddrMaskValue;
271 
272 typedef enum {
276 } I2C_Mode;
277 
278 typedef enum {
279  I2C0 = 0,
280 #if defined(CHIP_LPC175X_6X) || defined(CHIP_LPC177X_8X) || defined(CHIP_LPC18XX) || defined(CHIP_LPC43XX)
281  I2C1,
282 #if defined(CHIP_LPC175X_6X) || defined(CHIP_LPC177X_8X)
283  I2C2,
284 #endif
285 #endif
286 } I2C_ID_Type;
287 
293 void IP_I2C_Init(IP_I2C_001_Type *LPC_I2C);
294 
300 void IP_I2C_DeInit(IP_I2C_001_Type *LPC_I2C);
301 
308 void IP_I2C_SetClockRate(IP_I2C_001_Type *LPC_I2C, uint32_t SCLValue);
309 
317 void IP_I2C_Cmd(IP_I2C_001_Type *LPC_I2C, I2C_Mode Mode, FunctionalState NewState);
318 
326 
334 
351  I2C_ID_Type I2C_Num,
352  I2C_M_SETUP_Type *TransferCfg,
354 
377  I2C_ID_Type I2C_Num,
378  I2C_S_SETUP_Type *TransferCfg,
380 
387 
394 
402 void IP_I2C_SetOwnSlaveAddr(IP_I2C_001_Type *LPC_I2C, I2C_OWNSLAVEADDR_CFG_Type *OwnSlaveAddrConfigStruct);
403 
408 #ifdef __cplusplus
409 }
410 #endif
411 
412 #endif /* __I2C_001_H_ */