| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
LPC13xx I2C example
Peripheral examples

## 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

- User needs 2 boards and must setup the following connection between them
- Connect PIO0_5(SDA) of both the boards with a wire
- Connect PIO0_4(SCL) of both boards with a wire
- Connect J6-PIN1(GND) of both boards with a wire
- Pull up SDA & SCL using two 10K resistors between SDA,SCL and J6-PIN28(3v3)

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

Supported boards and board setup:
NXP Xpresso LPC1347 board
NXP Xpresso LPC1343 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 74 of file i2c.c.

#define I2C_EEPROM_BUS DEFAULT_I2C

Definition at line 76 of file i2c.c.

#define I2C_IOX_BUS DEFAULT_I2C

Definition at line 77 of file i2c.c.

#define I2C_SLAVE_EEPROM_ADDR 0x5A

Definition at line 99 of file i2c.c.

#define I2C_SLAVE_EEPROM_SIZE 64

Definition at line 98 of file i2c.c.

#define I2C_SLAVE_IOX_ADDR 0x5B

Definition at line 100 of file i2c.c.

#define SPEED_100KHZ 100000

Definition at line 79 of file i2c.c.

#define SPEED_400KHZ 400000

Definition at line 80 of file i2c.c.

## Function Documentation

static int con_get_input | ( | const char * | str | ) |
| static

Definition at line 143 of file i2c.c.

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

Definition at line 131 of file i2c.c.

static void i2c_app_init | ( | I2C_ID_T | id,
|  | int | speed
| ) |  |
| static

Definition at line 246 of file i2c.c.

static void i2c_eeprom_events | ( | I2C_ID_T | id,
|  | I2C_EVENT_T | event
| ) |  |
| static

Definition at line 296 of file i2c.c.

static void i2c_eeprom_init | ( | I2C_ID_T | id | ) |
| static

Definition at line 331 of file i2c.c.

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

Definition at line 289 of file i2c.c.

static void i2c_iox_events | ( | I2C_ID_T | id,
|  | I2C_EVENT_T | event
| ) |  |
| static

Definition at line 357 of file i2c.c.

static void i2c_iox_init | ( | I2C_ID_T | id | ) |
| static

Definition at line 383 of file i2c.c.

void i2c_iox_update_regs | ( | int | ops | ) |

Definition at line 342 of file i2c.c.

void I2C_IRQHandler | ( | void |  | ) |

I2C Interrupt Handler.

Returns
  None

Definition at line 414 of file i2c.c.

static int i2c_menu | ( | void |  | ) |
| static

Definition at line 282 of file i2c.c.

static void i2c_probe_slaves | ( | I2C_ID_T | i2c | ) |
| static

Definition at line 259 of file i2c.c.

static void i2c_rw_input | ( | I2C_XFER_T * | xfer,
|  | int | ops
| ) |  |
| static

Definition at line 200 of file i2c.c.

static void i2c_set_mode | ( | I2C_ID_T | id,
|  | int | polling
| ) |  |
| static

Definition at line 232 of file i2c.c.

static void i2c_state_handling | ( | I2C_ID_T | id | ) |
| static

Definition at line 121 of file i2c.c.

int main | ( | void |  | ) |

Main program body.

Returns
  int

defined(CHIP_LPC175X_6X)

Definition at line 423 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 404 of file i2c.c.

## Variable Documentation

uint8_t buffer[2][256]
| static

Definition at line 108 of file i2c.c.

I2C_ID_T i2cDev = DEFAULT_I2C
| static

Definition at line 95 of file i2c.c.

uint8_t iox_data[2]
| static

Definition at line 109 of file i2c.c.

I2C_XFER_T iox_xfer
| static

Definition at line 104 of file i2c.c.

int mode_poll
| static

Definition at line 94 of file i2c.c.

uint8_t seep_data[I2C_SLAVE_EEPROM_SIZE+1]
| static

Definition at line 107 of file i2c.c.

I2C_XFER_T seep_xfer
| static

Definition at line 103 of file i2c.c.

volatile uint32_t tick_cnt
| static

Definition at line 110 of file i2c.c.