uc-sdk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lpc17xx_i2c.h
Go to the documentation of this file.
1 /***********************************************************************/
21 /* Peripheral group ----------------------------------------------------------- */
27 #ifndef LPC17XX_I2C_H_
28 #define LPC17XX_I2C_H_
29 
30 /* Includes ------------------------------------------------------------------- */
31 #include "LPC17xx.h"
32 #include "lpc_types.h"
33 
34 
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39 
40 
41 /* Private Macros ------------------------------------------------------------- */
46 /* --------------------- BIT DEFINITIONS -------------------------------------- */
47 /*******************************************************************/
50 #define I2C_I2CONSET_AA ((0x04))
51 #define I2C_I2CONSET_SI ((0x08))
52 #define I2C_I2CONSET_STO ((0x10))
53 #define I2C_I2CONSET_STA ((0x20))
54 #define I2C_I2CONSET_I2EN ((0x40))
56 /*******************************************************************/
60 #define I2C_I2CONCLR_AAC ((1<<2))
61 
62 #define I2C_I2CONCLR_SIC ((1<<3))
63 
64 #define I2C_I2CONCLR_STAC ((1<<5))
65 
66 #define I2C_I2CONCLR_I2ENC ((1<<6))
67 
68 /********************************************************************/
71 /* Return Code in I2C status register */
72 #define I2C_STAT_CODE_BITMASK ((0xF8))
73 
74 /* I2C return status code definitions ----------------------------- */
75 
77 #define I2C_I2STAT_NO_INF ((0xF8))
78 
79 /* Master transmit mode -------------------------------------------- */
81 #define I2C_I2STAT_M_TX_START ((0x08))
82 
83 #define I2C_I2STAT_M_TX_RESTART ((0x10))
84 
85 #define I2C_I2STAT_M_TX_SLAW_ACK ((0x18))
86 
87 #define I2C_I2STAT_M_TX_SLAW_NACK ((0x20))
88 
89 #define I2C_I2STAT_M_TX_DAT_ACK ((0x28))
90 
91 #define I2C_I2STAT_M_TX_DAT_NACK ((0x30))
92 
93 #define I2C_I2STAT_M_TX_ARB_LOST ((0x38))
94 
95 /* Master receive mode -------------------------------------------- */
97 #define I2C_I2STAT_M_RX_START ((0x08))
98 
99 #define I2C_I2STAT_M_RX_RESTART ((0x10))
100 
101 #define I2C_I2STAT_M_RX_ARB_LOST ((0x38))
102 
103 #define I2C_I2STAT_M_RX_SLAR_ACK ((0x40))
104 
105 #define I2C_I2STAT_M_RX_SLAR_NACK ((0x48))
106 
107 #define I2C_I2STAT_M_RX_DAT_ACK ((0x50))
108 
109 #define I2C_I2STAT_M_RX_DAT_NACK ((0x58))
110 
111 /* Slave receive mode -------------------------------------------- */
113 #define I2C_I2STAT_S_RX_SLAW_ACK ((0x60))
114 
116 #define I2C_I2STAT_S_RX_ARB_LOST_M_SLA ((0x68))
117 
118 //#define I2C_I2STAT_S_RX_SLAW_ACK ((0x68))
119 
121 #define I2C_I2STAT_S_RX_GENCALL_ACK ((0x70))
122 
124 #define I2C_I2STAT_S_RX_ARB_LOST_M_GENCALL ((0x78))
125 
126 //#define I2C_I2STAT_S_RX_GENCALL_ACK ((0x78))
127 
130 #define I2C_I2STAT_S_RX_PRE_SLA_DAT_ACK ((0x80))
131 
133 #define I2C_I2STAT_S_RX_PRE_SLA_DAT_NACK ((0x88))
134 
136 #define I2C_I2STAT_S_RX_PRE_GENCALL_DAT_ACK ((0x90))
137 
139 #define I2C_I2STAT_S_RX_PRE_GENCALL_DAT_NACK ((0x98))
140 
143 #define I2C_I2STAT_S_RX_STA_STO_SLVREC_SLVTRX ((0xA0))
144 
147 #define I2C_I2STAT_S_TX_SLAR_ACK ((0xA8))
148 
150 #define I2C_I2STAT_S_TX_ARB_LOST_M_SLA ((0xB0))
151 
152 //#define I2C_I2STAT_S_TX_SLAR_ACK ((0xB0))
153 
155 #define I2C_I2STAT_S_TX_DAT_ACK ((0xB8))
156 
157 #define I2C_I2STAT_S_TX_DAT_NACK ((0xC0))
158 
160 #define I2C_I2STAT_S_TX_LAST_DAT_ACK ((0xC8))
161 
163 #define I2C_SLAVE_TIME_OUT 0x10000UL
164 
165 /********************************************************************/
169 #define I2C_I2DAT_BITMASK ((0xFF))
170 
174 #define I2C_I2DAT_IDLE_CHAR (0xFF)
175 
176 /********************************************************************/
179 #define I2C_I2MMCTRL_MM_ENA ((1<<0))
180 #define I2C_I2MMCTRL_ENA_SCL ((1<<1))
181 #define I2C_I2MMCTRL_MATCH_ALL ((1<<2))
182 #define I2C_I2MMCTRL_BITMASK ((0x07))
184 /********************************************************************/
188 #define I2DATA_BUFFER_BITMASK ((0xFF))
189 
190 /********************************************************************/
194 #define I2C_I2ADR_GC ((1<<0))
195 
196 #define I2C_I2ADR_BITMASK ((0xFF))
197 
198 /********************************************************************/
202 #define I2C_I2MASK_MASK(n) ((n&0xFE))
203 
204 /********************************************************************/
208 #define I2C_I2SCLH_BITMASK ((0xFFFF))
209 
210 /********************************************************************/
214 #define I2C_I2SCLL_BITMASK ((0xFFFF))
215 
216 /* I2C status values */
217 #define I2C_SETUP_STATUS_ARBF (1<<8)
218 #define I2C_SETUP_STATUS_NOACKF (1<<9)
219 #define I2C_SETUP_STATUS_DONE (1<<10)
221 /*********************************************************************/
224 #define I2C_MONITOR_CFG_SCL_OUTPUT I2C_I2MMCTRL_ENA_SCL
225 #define I2C_MONITOR_CFG_MATCHALL I2C_I2MMCTRL_MATCH_ALL
227 /* ---------------- CHECK PARAMETER DEFINITIONS ---------------------------- */
228 /* Macros check I2C slave address */
229 #define PARAM_I2C_SLAVEADDR_CH(n) ((n>=0) && (n<=3))
230 
232 #define PARAM_I2Cx(n) ((((uint32_t *)n)==((uint32_t *)LPC_I2C0)) \
233 || (((uint32_t *)n)==((uint32_t *)LPC_I2C1)) \
234 || (((uint32_t *)n)==((uint32_t *)LPC_I2C2)))
235 
236 /* Macros check I2C monitor configuration type */
237 #define PARAM_I2C_MONITOR_CFG(n) ((n==I2C_MONITOR_CFG_SCL_OUTPUT) || (I2C_MONITOR_CFG_MATCHALL))
238 
245 /* Public Types --------------------------------------------------------------- */
253 typedef struct {
257  uint8_t SlaveAddr_7bit;
272 
273 
277 typedef struct
278 {
279  uint32_t sl_addr7bit;
280  uint8_t* tx_data;
282  uint32_t tx_length;
284  uint32_t tx_count;
285  uint8_t* rx_data;
287  uint32_t rx_length;
289  uint32_t rx_count;
292  uint32_t status;
293  void (*callback)(void);
296 
297 
301 typedef struct
302 {
303  uint8_t* tx_data;
304  uint32_t tx_length;
305  uint32_t tx_count;
306  uint8_t* rx_data;
307  uint32_t rx_length;
308  uint32_t rx_count;
309  uint32_t status;
310  void (*callback)(void);
312 
316 typedef enum {
320 
321 
327 /* Public Functions ----------------------------------------------------------- */
332 /* I2C Init/DeInit functions ---------- */
333 void I2C_Init(LPC_I2C_TypeDef *I2Cx, uint32_t clockrate);
334 void I2C_DeInit(LPC_I2C_TypeDef* I2Cx);
335 //void I2C_SetClock (LPC_I2C_TypeDef *I2Cx, uint32_t target_clock);
336 void I2C_Cmd(LPC_I2C_TypeDef* I2Cx, FunctionalState NewState);
337 
338 /* I2C transfer data functions -------- */
340  I2C_M_SETUP_Type *TransferCfg, I2C_TRANSFER_OPT_Type Opt);
342  I2C_S_SETUP_Type *TransferCfg, I2C_TRANSFER_OPT_Type Opt);
345 
346 
347 void I2C_SetOwnSlaveAddr(LPC_I2C_TypeDef *I2Cx, I2C_OWNSLAVEADDR_CFG_Type *OwnSlaveAddrConfigStruct);
349 
350 /* I2C Monitor functions ---------------*/
351 void I2C_MonitorModeConfig(LPC_I2C_TypeDef *I2Cx, uint32_t MonitorCfgType, FunctionalState NewState);
354 BOOL_8 I2C_MonitorHandler(LPC_I2C_TypeDef *I2Cx, uint8_t *buffer, uint32_t size);
355 
356 /* I2C Interrupt handler functions ------*/
357 void I2C_IntCmd (LPC_I2C_TypeDef *I2Cx, Bool NewState);
359 void I2C_SlaveHandler (LPC_I2C_TypeDef *I2Cx);
360 
361 
367 #ifdef __cplusplus
368 }
369 #endif
370 
371 #endif /* LPC17XX_I2C_H_ */
372 
377 /* --------------------------------- End Of File ------------------------------ */