LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
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
{
51
__IO
uint32_t
CONSET
;
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
;
57
__O
uint32_t
CONCLR
;
58
__IO
uint32_t
MMCTRL
;
59
__IO
uint32_t
ADR1
;
60
__IO
uint32_t
ADR2
;
61
__IO
uint32_t
ADR3
;
62
__I
uint32_t
DATA_BUFFER
;
63
__IO
uint32_t
MASK[4];
64
}
IP_I2C_001_Type
;
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 {
224
uint32_t
sl_addr7bit
;
225
uint8_t *
tx_data
;
226
uint32_t
tx_length
;
227
uint32_t
tx_count
;
228
uint8_t *
rx_data
;
229
uint32_t
rx_length
;
230
uint32_t
rx_count
;
231
uint32_t
retransmissions_max
;
232
uint32_t
retransmissions_count
;
233
uint32_t
status
;
234
}
I2C_M_SETUP_Type
;
235
239
typedef
struct
{
240
uint8_t *
tx_data
;
241
uint32_t
tx_length
;
242
uint32_t
tx_count
;
243
uint8_t *
rx_data
;
244
uint32_t
rx_length
;
245
uint32_t
rx_count
;
246
uint32_t
status
;
247
}
I2C_S_SETUP_Type
;
248
252
typedef
enum
{
253
I2C_TRANSFER_POLLING
= 0,
254
I2C_TRANSFER_INTERRUPT
255
}
I2C_TRANSFER_OPT_Type
;
256
260
typedef
struct
{
261
uint8_t
SlaveAddrChannel
;
262
uint8_t
SlaveAddr_7bit
;
263
uint8_t GeneralCallState;
266
uint8_t SlaveAddrMaskValue;
270
}
I2C_OWNSLAVEADDR_CFG_Type
;
271
272
typedef
enum
{
273
I2C_MASTER_MODE
,
274
I2C_SLAVE_MODE
,
275
I2C_GENERAL_MODE
,
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
325
void
IP_I2C_Interrupt_MasterHandler
(
IP_I2C_001_Type
*LPC_I2C,
I2C_ID_Type
I2C_Num);
326
333
void
IP_I2C_Interrupt_SlaveHandler
(
IP_I2C_001_Type
*LPC_I2C,
I2C_ID_Type
I2C_Num);
334
350
Status
IP_I2C_MasterTransferData
(
IP_I2C_001_Type
*LPC_I2C,
351
I2C_ID_Type
I2C_Num,
352
I2C_M_SETUP_Type
*TransferCfg,
353
I2C_TRANSFER_OPT_Type
Opt);
354
376
Status
IP_I2C_SlaveTransferData
(
IP_I2C_001_Type
*LPC_I2C,
377
I2C_ID_Type
I2C_Num,
378
I2C_S_SETUP_Type
*TransferCfg,
379
I2C_TRANSFER_OPT_Type
Opt);
380
386
bool
IP_I2C_Interrupt_MasterTransferComplete
(
I2C_ID_Type
I2C_Num);
387
393
bool
IP_I2C_Interrupt_SlaveTransferComplete
(
I2C_ID_Type
I2C_Num);
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_ */
software
lpc_core
lpc_ip
i2c_001.h
Generated on Fri Nov 16 2012 13:36:43 for LPCOpen Platform by
1.8.2