| 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
LPC17xx/40xx CAN example
Peripheral examples

## Detailed Description

Example description
This example describes how to use CAN peripheral on LPC17xx and LPC40xx chip. It requires a CAN analyser or, another CAN device connected to CAN_1 pins. After initializing, the device will setup the AF Look-up table which defines acceptable IDs. Then, it transmits first standard message with ID 0x200 on bus, a remote message with ID 0x300 and an extended message with ID 0x10000200. The device always listens message on the bus. Whenever a message whose ID exists in the AF Look-up Table comes, the device will reply back a message with ID 0x200. The data in replied message is the same with the one of received message.

AF Lookup Table:
Full CAN Section: includes 0x03, 0x04, 0x07, 0x09.
Individual Standard ID Section: includes 0x30, 0x40, 0x50, 0x90, 0xB0.
Standard ID Range Section: includes 0x300~0x400, 0x400~0x500, 0x700~0x780.
Extended ID Section: includes 0x803, 0x804, 0x807, 0x809.
Extended ID Range Section: includes 0xB00~0xC00, 0xC00~0xD00, 0xF00~0xF80.

Special connection requirements

- Embedded Artists' LPC1788 Developer's Kit:
- Embedded Artists' LPC4088 Developer's Kit:
  Set jumpers as follows:
  JP14: 3-4 ON
  J16-7 (CAN1-L) is connected to CAN-L (Pin 2) of CAN Analyser.
  J16-8 (CAN1-H) is connected to CAN-H (Pin 7) of CAN Analyser.
  GND pin is connected to GND (pin 3) of CAN Analyser.
- LPCXpresso LPC1769:
  Need to connect with base board for using RS232/UART port and CAN transceiver.
  J15-7 (CAN-L) of base board is connected to CAN-L (Pin 2) of CAN Analyser.
  J15-8 (CAN-H) of base board is connected to CAN-H (Pin 7) of CAN Analyser.
  GND pin is connected to GND (pin 3) of CAN Analyser.

Build procedures:
LPC17xx/40xx example quickstart for Keil uVision4
LPC17xx/40xx example quickstart for IAR EWARM
LPC17xx/40xx example quickstart for Code Red Xpresso

Supported boards and board setup:
Embedded Artists' LPC1788 Developer's Kit
Embedded Artists' LPC4088 Developer's Kit
NXP Xpresso LPC1769 board

Submitting LPCOpen issues:
Community support for LPCOpen

## Macros
#define | CAN_CTRL_NO 0
#define | LPC_CAN (LPC_CAN1)
#define | AF_LUT_USED 1
#define | FULL_CAN_AF_USED 1
#define | CAN_TX_MSG_STD_ID (0x200)
#define | CAN_TX_MSG_REMOTE_STD_ID (0x300)
#define | CAN_TX_MSG_EXT_ID (0x10000200)
#define | CAN_RX_MSG_ID (0x100)

## Functions
static void | PrintCANErrorInfo (uint32_t Status)
static void | PrintCANMsg (CAN_MSG_T *pMsg)
static void | ReplyRemoteMessage (CAN_MSG_T *pRcvMsg)
static void | ReplyNormalMessage (CAN_MSG_T *pRcvMsg)
static void | PrintAFLUT (void)
static void | SetupAFLUT (void)
static void | ChangeAFLUT (void)
void | CAN_IRQHandler (void)
int | main (void)
| Main program body.

## Variables
static char | WelcomeMenu []
CAN_STD_ID_ENTRY_T | FullCANSection []
CAN_STD_ID_ENTRY_T | SFFSection []
CAN_STD_ID_RANGE_ENTRY_T | SffGrpSection []
CAN_EXT_ID_ENTRY_T | EFFSection []
CAN_EXT_ID_RANGE_ENTRY_T | EffGrpSection []
CANAF_LUT_T | AFSections

## Macro Definition Documentation

#define AF_LUT_USED 1

Definition at line 95 of file can.c.

#define CAN_CTRL_NO 0

Definition at line 88 of file can.c.

#define CAN_RX_MSG_ID (0x100)

Definition at line 102 of file can.c.

#define CAN_TX_MSG_EXT_ID (0x10000200)

Definition at line 101 of file can.c.

#define CAN_TX_MSG_REMOTE_STD_ID (0x300)

Definition at line 100 of file can.c.

#define CAN_TX_MSG_STD_ID (0x200)

Definition at line 99 of file can.c.

#define FULL_CAN_AF_USED 1

Definition at line 97 of file can.c.

#define LPC_CAN (LPC_CAN1)

Definition at line 91 of file can.c.

## Function Documentation

void CAN_IRQHandler | ( | void |  | ) |

Definition at line 388 of file can.c.

static void ChangeAFLUT | ( | void |  | ) |
| static

Definition at line 308 of file can.c.

int main | ( | void |  | ) |

Main program body.

main routine for example_lwip_tcpecho_sa_18xx43xx

Returns
  Always returns 0 (device reset prior to return)
  Function should not exit.

Main program body.

Entry point for all the dual core examples. All the dual core example execution starts from this function, it is common for code that runs on core-M4 and core-M0.

Returns
  Function should not return.

Main program body.

Returns
  Nothing

Main program body.

Returns
  Nothing, function should not exit

Main program entry point. This routine contains the overall program flow, including initial setup of all components and the main program loop.

Main program body.

Returns
  Function should not exit

Main program body.

Returns
  Function should not exit.

Main program body.

Returns
  Nothing (function should not exit)
  Does not return
  int

Main program body.

Returns
  Always returns -1

Definition at line 437 of file can.c.

static void PrintAFLUT | ( | void |  | ) |
| static

Definition at line 245 of file can.c.

static void PrintCANErrorInfo | ( | uint32_t | Status | ) |
| static

Definition at line 160 of file can.c.

static void PrintCANMsg | ( | CAN_MSG_T * | pMsg | ) |
| static

Definition at line 191 of file can.c.

static void ReplyNormalMessage | ( | CAN_MSG_T * | pRcvMsg | ) |
| static

Definition at line 232 of file can.c.

static void ReplyRemoteMessage | ( | CAN_MSG_T * | pRcvMsg | ) |
| static

Definition at line 215 of file can.c.

static void SetupAFLUT | ( | void |  | ) |
| static

Definition at line 300 of file can.c.

## Variable Documentation

CANAF_LUT_T AFSections

Initial value:
= {
FullCANSection, sizeof(FullCANSection) / sizeof(CAN_STD_ID_ENTRY_T),
SFFSection, sizeof(SFFSection) / sizeof(CAN_STD_ID_ENTRY_T),
SffGrpSection, sizeof(SffGrpSection) / sizeof(CAN_STD_ID_RANGE_ENTRY_T),
EFFSection, sizeof(EFFSection) / sizeof(CAN_EXT_ID_ENTRY_T),
EffGrpSection, sizeof(EffGrpSection) / sizeof(CAN_EXT_ID_RANGE_ENTRY_T),
}

Definition at line 143 of file can.c.

CAN_EXT_ID_RANGE_ENTRY_T EffGrpSection[]

Initial value:
= {
{{CAN_CTRL_NO, ((1 << 11) | 0x300)}, {CAN_CTRL_NO, ((1 << 11) | 0x400)}},
{{CAN_CTRL_NO, ((1 << 11) | 0x500)}, {CAN_CTRL_NO, ((1 << 11) | 0x600)}},
{{CAN_CTRL_NO, ((1 << 11) | 0x700)}, {CAN_CTRL_NO, ((1 << 11) | 0x780)}},
}

Definition at line 138 of file can.c.

CAN_EXT_ID_ENTRY_T EFFSection[]

Initial value:
= {
{CAN_CTRL_NO, ((1 << 11) | 0x03)},
{CAN_CTRL_NO, ((1 << 11) | 0x05)},
{CAN_CTRL_NO, ((1 << 11) | 0x07)},
{CAN_CTRL_NO, ((1 << 11) | 0x09)},
}

Definition at line 132 of file can.c.

CAN_STD_ID_ENTRY_T FullCANSection[]

Initial value:
= {
{CAN_CTRL_NO, 0, 0x03},
{CAN_CTRL_NO, 0, 0x05},
{CAN_CTRL_NO, 0, 0x07},
{CAN_CTRL_NO, 0, 0x09},
}

Definition at line 113 of file can.c.

CAN_STD_ID_RANGE_ENTRY_T SffGrpSection[]

Initial value:
= {
{{CAN_CTRL_NO, 0, 0x300}, {CAN_CTRL_NO, 0, 0x400}},
{{CAN_CTRL_NO, 0, 0x500}, {CAN_CTRL_NO, 0, 0x600}},
{{CAN_CTRL_NO, 0, 0x700}, {CAN_CTRL_NO, 0, 0x780}},
}

Definition at line 127 of file can.c.

CAN_STD_ID_ENTRY_T SFFSection[]

Initial value:
= {
{CAN_CTRL_NO, 0, 0x30},
{CAN_CTRL_NO, 0, 0x50},
{CAN_CTRL_NO, 0, 0x70},
{CAN_CTRL_NO, 0, 0x90},
{CAN_CTRL_NO, 0, 0xB0},
}

Definition at line 120 of file can.c.

char WelcomeMenu[]
| static

Initial value:
= "\n\rHello NXP Semiconductors \r\n"
"CAN DEMO : Use CAN to transmit and receive Message from CAN Analyzer\r\n"
"CAN bit rate : 500kBit/s\r\n"

Definition at line 107 of file can.c.