LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
LPC11xx I2C example

Detailed Description

Example description
This example shows how to use I2C as master or slave and communicate between Master and Slave with polling/interrupt mode. (Interrupt mode is default)

After setting up connection, run the example in both the boards. At regular intervals both the boards will send data as master and receive data from master hence blinking the LED at regular intervals (Both boards will act as master as well as slave).

If you have UART connected define DEBUG_ENABLE in sys_config.h, and can interactively use the example to access I2C data for more information see LPC18xx/43xx I2C example

Special connection requirements

Build procedures:
LPC11xx example quickstart for Code Red Xpresso
LPC11xx example quickstart for Keil uVision4
LPC11xx example quickstart for IAR EWARM

Supported boards and board setup:
NXP Xpresso LPC11U14 board
NXP Xpresso LPC11C24 board

Submitting LPCOpen issues:
Community support for LPCOpen

Macros

#define DEFAULT_I2C   I2C0
 
#define I2C_EEPROM_BUS   DEFAULT_I2C
 
#define I2C_IOX_BUS   DEFAULT_I2C
 
#define SPEED_100KHZ   100000
 
#define SPEED_400KHZ   400000
 
#define I2C_SLAVE_EEPROM_SIZE   64
 
#define I2C_SLAVE_EEPROM_ADDR   0x5A
 
#define I2C_SLAVE_IOX_ADDR   0x5B
 

Functions

static void i2c_state_handling (I2C_ID_T id)
 
static void con_print_data (const uint8_t *dat, int sz)
 
static int con_get_input (const char *str)
 
static void i2c_rw_input (I2C_XFER_T *xfer, int ops)
 
static void i2c_set_mode (I2C_ID_T id, int polling)
 
static void i2c_app_init (I2C_ID_T id, int speed)
 
static void i2c_probe_slaves (I2C_ID_T i2c)
 
static int i2c_menu (void)
 
static void i2c_eeprom_update_state (I2C_XFER_T *xfer, uint8_t *buff, int sz)
 
static void i2c_eeprom_events (I2C_ID_T id, I2C_EVENT_T event)
 
static void i2c_eeprom_init (I2C_ID_T id)
 
void i2c_iox_update_regs (int ops)
 
static void i2c_iox_events (I2C_ID_T id, I2C_EVENT_T event)
 
static void i2c_iox_init (I2C_ID_T id)
 
void SysTick_Handler (void)
 SysTick Interrupt Handler.
 
void I2C_IRQHandler (void)
 I2C Interrupt Handler.
 
int main (void)
 Main program body.
 

Variables

static int mode_poll
 
static I2C_ID_T i2cDev = DEFAULT_I2C
 
static I2C_XFER_T seep_xfer
 
static I2C_XFER_T iox_xfer
 
static uint8_t seep_data [I2C_SLAVE_EEPROM_SIZE+1]
 
static uint8_t buffer [2][256]
 
static uint8_t iox_data [2]
 
static volatile uint32_t tick_cnt
 

Macro Definition Documentation

#define DEFAULT_I2C   I2C0

Definition at line 75 of file i2c.c.

#define I2C_EEPROM_BUS   DEFAULT_I2C

Definition at line 77 of file i2c.c.

#define I2C_IOX_BUS   DEFAULT_I2C

Definition at line 78 of file i2c.c.

#define I2C_SLAVE_EEPROM_ADDR   0x5A

Definition at line 100 of file i2c.c.

#define I2C_SLAVE_EEPROM_SIZE   64

Definition at line 99 of file i2c.c.

#define I2C_SLAVE_IOX_ADDR   0x5B

Definition at line 101 of file i2c.c.

#define SPEED_100KHZ   100000

Definition at line 80 of file i2c.c.

#define SPEED_400KHZ   400000

Definition at line 81 of file i2c.c.

Function Documentation

static int con_get_input ( const char *  str)
static

Definition at line 144 of file i2c.c.

static void con_print_data ( const uint8_t *  dat,
int  sz 
)
static

Definition at line 132 of file i2c.c.

static void i2c_app_init ( I2C_ID_T  id,
int  speed 
)
static

Definition at line 247 of file i2c.c.

static void i2c_eeprom_events ( I2C_ID_T  id,
I2C_EVENT_T  event 
)
static

Definition at line 297 of file i2c.c.

static void i2c_eeprom_init ( I2C_ID_T  id)
static

Definition at line 332 of file i2c.c.

static void i2c_eeprom_update_state ( I2C_XFER_T xfer,
uint8_t *  buff,
int  sz 
)
static

Definition at line 290 of file i2c.c.

static void i2c_iox_events ( I2C_ID_T  id,
I2C_EVENT_T  event 
)
static

Definition at line 360 of file i2c.c.

static void i2c_iox_init ( I2C_ID_T  id)
static

Definition at line 386 of file i2c.c.

void i2c_iox_update_regs ( int  ops)

Definition at line 343 of file i2c.c.

void I2C_IRQHandler ( void  )

I2C Interrupt Handler.

Returns
None

Definition at line 419 of file i2c.c.

static int i2c_menu ( void  )
static

Definition at line 283 of file i2c.c.

static void i2c_probe_slaves ( I2C_ID_T  i2c)
static

Definition at line 260 of file i2c.c.

static void i2c_rw_input ( I2C_XFER_T xfer,
int  ops 
)
static

Definition at line 201 of file i2c.c.

static void i2c_set_mode ( I2C_ID_T  id,
int  polling 
)
static

Definition at line 233 of file i2c.c.

static void i2c_state_handling ( I2C_ID_T  id)
static

Definition at line 122 of file i2c.c.

int main ( void  )

Main program body.

Returns
int

defined(CHIP_LPC175X_6X)

Definition at line 428 of file i2c.c.

void SysTick_Handler ( void  )

SysTick Interrupt Handler.

SysTick 1mS tick handler.

Returns
Nothing
Note
Systick interrupt handler updates the button status

Definition at line 409 of file i2c.c.

Variable Documentation

uint8_t buffer[2][256]
static

Definition at line 109 of file i2c.c.

I2C_ID_T i2cDev = DEFAULT_I2C
static

Definition at line 96 of file i2c.c.

uint8_t iox_data[2]
static

Definition at line 110 of file i2c.c.

I2C_XFER_T iox_xfer
static

Definition at line 105 of file i2c.c.

int mode_poll
static

Definition at line 95 of file i2c.c.

uint8_t seep_data[I2C_SLAVE_EEPROM_SIZE+1]
static

Definition at line 108 of file i2c.c.

I2C_XFER_T seep_xfer
static

Definition at line 104 of file i2c.c.

volatile uint32_t tick_cnt
static

Definition at line 111 of file i2c.c.