CAN Bus Application Guide

From Flowcode Help
Jump to navigationJump to search

Introduction

These examples demonstrate the use of the Flowcode CAN Bus component.

In particular they make use of two sets of the EB018 E-blocks CAN Bus board, connected to EB006 E-blocks PICmicro multiprogrammers fitted with a 16F1937 microprocessor.

However, the examples are easily changed in Flowcode to support other microprocessors and platforms.

The Matrix TSL EB628SI6 Easy CAN Bus bundle has all the items required for these sample applications and is an ideal introduction to CAN Bus technology.


Setting up the project hardware

Connect the E-Blocks as indicated in the table below.

The CAN Bus, LCD and Switch E-Blocks all need to be powered via wire connections to the +V on their respective EB006 upstream processor board.

The CANH signal terminals should be linked together.

The CANL signal terminals should be linked together.

The EB006 Ground terminals should be linked together.

The jumper on each CAN board should be set to "End Node".


Hardware Setup (Node 1)
EB006 PICmicro multiprogrammer
Port A
Port B EB005 E-blocks LCD board
Port C EB018 E-blocks CAN board
Port D EB007 E-blocks switch board


Hardware Setup (Node 2)
EB006 PICmicro multiprogrammer
Port A
Port B
Port C EB018 E-blocks CAN board
Port D EB004 E-blocks LED board


Example 1: Simple single data message transfer

FC6 Icon.png Simple Message Transfer Example (Node 1) FC6 Icon.png Simple Message Transfer Example (Node 2)

Example 1 shows how to send and receive a message identifier complete with a single data byte.

The node 1 with the LCD and Switch E-Blocks will send out a CAN message every second containing the value of the switches.

The receiving node 2 will then display any incoming data to the LED board.

Example 2: Data transfer acknowledgement example

FC6 Icon.png Data Acknowledge Example (Node 1) FC6 Icon.png Data Acknowledge Example (Node 2)

Example 2 adds to the functionality shown in example 1 by adding a detection routine to the programs.

Node 1 now issues a message with an ID of 1 after starting up. Node 2 listens for messages as before but now decides what to do based on the message identifier that is received. If ID 1 is received then node 2 replies with an ID of 2. This tells node 1 that the message has been received and acknowledged. Node 1 then sends out a message ID of 3 to control the switch to LED functionality.

Checking if a node is present before sending data to that node allows the system to be much more reliable and also allows it to sense fault conditions.