| 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
LPC8xx I2C example using I2C ROM API functions
Peripheral examples

## Detailed Description

Example description
This example shows how to configure I2C as master or slave device using ROM-based APIs.

This demo supports both 7-bit and 10-bit slave addressing. After setting up successfully, all transmit/receive functions will be called step by step.
If error occurs, this example will hang up. When all steps run successfully, the demo will end and blue LED will be shown.

Special connection requirements
User needs 2 boards connected through P0.10 (SDA), P0.11 (SCL) and a common GND (need two pull-up resistors for I2C bus because P0.10 and P0.11 are special I2C open-drain pins).

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

Supported boards and board setup:
NXP Xpresso LPC812 board

Submitting LPCOpen issues:
Community support for LPCOpen

## Macros
#define | I2C_MASTER_MODE 1
#define | I2C_SLAVE_ADDR_7BIT (0x90)
#define | I2C_SLAVE_ADDR_10BIT (0x2CA)
#define | I2C_ROM_MEM_SIZE (0x100UL)
#define | I2C_BITRATE (1000000)
#define | BUFFER_SIZE (0xFF)

## Functions
static void | Buffer_Init (uint8_t *buffer, uint32_t buf_len, uint8_t type)
static void | spin_on_error (void)
static void | Buffer_Compare (uint8_t *buffer1, uint8_t *buffer2, uint32_t StartPos, uint32_t StopPos)
static void | App_I2C_Callback_Receive (uint32_t err_code, uint32_t n)
static void | App_I2C_Callback_Transmit (uint32_t err_code, uint32_t n)
static void | App_I2C_Callback_MasterTxRx (uint32_t err_code, uint32_t n)
static void | App_I2C_Master_Polling (void)
static void | App_I2C_Master_Interrupt (void)
static void | App_I2C_Master_10bitAddressTest (void)
void | I2C_IRQHandler (void)
| I2C Interrupt Service Routine.
void | HW_Setup (void)
| Set up hardware for lpc8xx I2C example.
int | main (void)
| Main routine for I2C example.

## Variables
static I2C_HANDLE_T * | i2c_handle
static uint32_t | i2cmem [I2C_ROM_MEM_SIZE]
volatile uint32_t | error_code
I2C_PARAM_T | param
I2C_RESULT_T | result
volatile bool | isTxCompleted = false
volatile bool | isRxCompleted = false
volatile bool | isTxRxCompleted = false
uint8_t | Buffer [BUFFER_SIZE]
uint8_t | TmpBuffer [BUFFER_SIZE]

## Macro Definition Documentation

#define BUFFER_SIZE (0xFF)

Max buffer length

Definition at line 76 of file i2c.c.

#define I2C_BITRATE (1000000)

1Mbps I2C bit-rate

Definition at line 74 of file i2c.c.

#define I2C_MASTER_MODE 1

I2C mode: 1 - Master Mode, 0 - Slave Mode

Definition at line 66 of file i2c.c.

#define I2C_ROM_MEM_SIZE (0x100UL)

Memory size for I2C ROM

Definition at line 72 of file i2c.c.

#define I2C_SLAVE_ADDR_10BIT (0x2CA)

10-bit slave address

Definition at line 70 of file i2c.c.

#define I2C_SLAVE_ADDR_7BIT (0x90)

7-bit slave address

Definition at line 68 of file i2c.c.

## Function Documentation

static void App_I2C_Callback_MasterTxRx | ( | uint32_t | err_code,
|  | uint32_t | n
| ) |  |
| static

Definition at line 151 of file i2c.c.

static void App_I2C_Callback_Receive | ( | uint32_t | err_code,
|  | uint32_t | n
| ) |  |
| static

Definition at line 137 of file i2c.c.

static void App_I2C_Callback_Transmit | ( | uint32_t | err_code,
|  | uint32_t | n
| ) |  |
| static

Definition at line 144 of file i2c.c.

static void App_I2C_Master_10bitAddressTest | ( | void |  | ) |
| static

Definition at line 279 of file i2c.c.

static void App_I2C_Master_Interrupt | ( | void |  | ) |
| static

Definition at line 212 of file i2c.c.

static void App_I2C_Master_Polling | ( | void |  | ) |
| static

Definition at line 160 of file i2c.c.

static void Buffer_Compare | ( | uint8_t * | buffer1,
|  | uint8_t * | buffer2,
|  | uint32_t | StartPos,
|  | uint32_t | StopPos
| ) |  |
| static

Definition at line 125 of file i2c.c.

static void Buffer_Init | ( | uint8_t * | buffer,
|  | uint32_t | buf_len,
|  | uint8_t | type
| ) |  |
| static

Definition at line 99 of file i2c.c.

void HW_Setup | ( | void |  | ) |

Set up hardware for lpc8xx I2C example.

Returns
  Nothing

Definition at line 496 of file i2c.c.

void I2C_IRQHandler | ( | void |  | ) |

I2C Interrupt Service Routine.

Returns
  Nothing

Definition at line 486 of file i2c.c.

int main | ( | void |  | ) |

Main routine for I2C example.

Main program body.

Returns
  Function should not exit.

defined(CHIP_LPC175X_6X)

Definition at line 530 of file i2c.c.

static void spin_on_error | ( | void |  | ) |
| static

Definition at line 116 of file i2c.c.

## Variable Documentation

uint8_t Buffer[BUFFER_SIZE]

Definition at line 87 of file i2c.c.

volatile uint32_t error_code

Definition at line 80 of file i2c.c.

I2C_HANDLE_T* i2c_handle
| static

Definition at line 78 of file i2c.c.

uint32_t i2cmem[I2C_ROM_MEM_SIZE]
| static

Definition at line 79 of file i2c.c.

volatile bool isRxCompleted = false

Definition at line 84 of file i2c.c.

volatile bool isTxCompleted = false

Definition at line 83 of file i2c.c.

volatile bool isTxRxCompleted = false

Definition at line 85 of file i2c.c.

I2C_PARAM_T param

Definition at line 81 of file i2c.c.

I2C_RESULT_T result

Definition at line 82 of file i2c.c.

uint8_t TmpBuffer[BUFFER_SIZE]

Definition at line 88 of file i2c.c.