CAN Peripheral - Ti Processor Wiki

CAN Peripheral - Ti Processor Wiki
CAN Peripheral Module
Introduction
This module covers the CAN peripheral, library and examples provided with the LM3S8962
evaluation kit.
Learning Objectives
•
CAN Basics
•
Ethernet vs. CAN
•
CAN Drivers
•
CAN Stacks
•
Lab
Stellaris One-Day Workshop - CAN Peripheral
12 - 1
Module Topics
Module Topics
CAN Peripheral Module ...............................................................................................................................1
Module Topics.............................................................................................................................................2
CAN Basics .................................................................................................................................................3
CAN Bus ................................................................................................................................................3
CAN Node ..............................................................................................................................................4
CAN Principles.......................................................................................................................................4
Message Format......................................................................................................................................5
Arbitration ..............................................................................................................................................5
Message Types .......................................................................................................................................6
Message Objects .....................................................................................................................................6
FIFO Mode .............................................................................................................................................7
Ethernet vs. CAN....................................................................................................................................7
Stellaris CAN..........................................................................................................................................8
Kits and Software........................................................................................................................................9
Drivers ..................................................................................................................................................10
APIs ......................................................................................................................................................10
Code Example ......................................................................................................................................11
Stacks....................................................................................................................................................14
CAN Lab ...................................................................................................................................................15
Description: ..........................................................................................................................................15
Hardware list: .......................................................................................................................................16
Software list:.........................................................................................................................................16
Procedure..............................................................................................................................................17
12 - 2
Stellaris One-Day Workshop - CAN Peripheral
CAN Basics
CAN Basics
Controller Area Network (CAN)
A Multi-Master Serial Bus System
Bosch CAN 2.0 A/B Standard
High speed (up to 1 Mbps)
Add a node without disturbing the bus (number of nodes not
limited by protocol)
Fewer wires (lower cost, less maintenance, and more
reliable)
Redundant error checking (high reliability)
No node addressing (message identifiers)
Broadcast based signaling
A
B
C
‹
‹
‹
‹
‹
‹
‹
D
E
CAN Bus …
CAN Bus
CAN Bus
‹
‹
Two wire differential bus (usually twisted pair)
Max. bus length depend on transmission rate
Š
40 meters @ 1 Mbps
CAN
NODE A
CAN
NODE B
CAN
NODE C
CAN_H
120Ω
120Ω
CAN_L
CAN Node …
Stellaris One-Day Workshop - CAN Peripheral
12 - 3
CAN Basics
CAN Node
CAN Node
Wired-AND Bus Connection
CAN_H
120Ω
120Ω
CAN_L
CAN Transceiver
(e.g. TI SN65HVD23x)
TX
RX
CAN Controller
Ex. LM3S8962
Principles …
CAN Principles
Principles of Operation
‹
‹
Data messages transmitted are identifier based,
not address based
Content of message is labeled by an identifier that
is unique throughout the network
Š
‹
‹
‹
All nodes on network receive the message and
each performs an acceptance test on the identifier
If message is relevant, it is processed (received);
otherwise it is ignored
Unique identifier also determines the priority of the
message
Š
‹
(e.g. rpm, temperature, position, pressure, etc.)
(lower the numerical value of the identifier, the higher the
priority)
When two or more nodes attempt to transmit at the
same time, a non-destructive arbitration technique
guarantees messages are sent in order of priority
and no messages are lost
MSG Format …
12 - 4
Stellaris One-Day Workshop - CAN Peripheral
CAN Basics
Message Format
CAN Message Format
‹
Data is transmitted and received using Message Frames
‹
8 byte data payload per message
Standard and Extended identifier formats
‹
‹
Standard Frame: 11-bit Identifier (CAN v2.0A)
Arbitration
Field
S
O
F
Control
Field
R I
11-bit
Identifier T D r 0 DLC
R E
Data Field
0…8 B ytes Data
CRC
ACK
E
O
F
‹ Extended Frame: 29-bit Identifier (CAN v2.0B)
Arbitration Field
S
O
F
Control
Field
R
S I
11-bit
18-bit
T r 1 r0 DLC
Identifier R D Identifier
R
R E
Data Field
0… 8 B ytes Data
CRC
ACK
E
O
F
Arbitration …
Arbitration
Non-Destructive Bitwise Arbitration
‹
Bus arbitration resolved via arbitration with
wired-AND bus connections
Š
Š
Dominate state (logic 0, bus is high)
Recessive state (logic 1, bus is low)
Start
Bit
Node A wins
arbitration
Node A
Node B
Node C
CAN Bus
Node B loses
arbitration
Node C loses
arbitration
MSG Types …
Stellaris One-Day Workshop - CAN Peripheral
12 - 5
CAN Basics
Message Types
CAN Message Types
Data Frame
Š “Hello everyone, here’s DATA ALPHA, hope you like it!”
Remote Frame
Š
“Hello everyone, can somebody please produce DATA ALPHA?”
Error Frame
Š
[Everyone out loud] “Uh-oh! Whoever sent that, let’s try again.”
Overload Frame
Š “I heard you, but I’m bigger than you – and I am busy. Can you please
wait?”
CAN networks hear everything… when a node sends something, everyone listens
and they either REACT or IGNORE
‹
There are two types of transmissions; event-triggered and time-triggered.
Š In event-triggered, events (such as a temperature threshold) cause
transmission.
Š In time-triggered, each CAN-entity is only allowed to transmit during a
given time allotment.
Š
Stellaris features the ability to disable auto-retransmission for the benefit of
TTCAN (so our device doesn’t speak during someone else’s turn)
MSG Objects …
Message Objects
Message Objects (Mailboxes)
‹
Message main parts: message identifier and data
Š
Š
‹
Messages are:
Š
Š
Š
Š
‹
Identifier “names” the content of the message (11 bits
or 29 bits)
Data can be from 0 to 8 bytes (0=remote frame)
Received by protocol controller
Passed to message handler
Loaded into appropriate message object
Messages can be filtered (ignored) using a mask
Message object RAM
Š
Š
Š
32 identical blocks
Ordered by priority (1 is highest, 32 lowest)
Application reads/writes Message RAM via the
message object registers, not accessible directly
FIFO Mode …
12 - 6
Stellaris One-Day Workshop - CAN Peripheral
CAN Basics
FIFO Mode
FIFO Mode
‹
‹
‹
‹
You can “concatenate” multiple message
objects (saves interrupt overhead for
messages larger than 8 bytes)
Set the identifier and mask to be the same
value
Data is filled starting with the highest
priority message object (1 to 32)
EOB bit (End of Buffer) set to 1 in last
object (0 indicates this object belongs to
a FIFO)
Enet vs CAN …
Ethernet vs. CAN
Ethernet vs CAN
PRO
CAN
Ethernet
‹
‹
‹
CON
Robust, deterministic, real-time Slower, not as widely
adopted on HMI*-side
of industrial control
Standardization in traditional
Non-real-time, nonoffice equipment, web-interface deterministic
capability, high throughput
Both CAN and Ethernet (together and independently) have
viable benefits in industrial applications
Gateways and floor terminals tend to be the most common
places for CAN+Ethernet solutions
An ARM Cortex-based Ethernet hub means code
compatibility throughout the entire system
* Human-Machine Interface
Stellaris One-Day Workshop - CAN Peripheral
Stellaris CAN …
12 - 7
CAN Basics
Stellaris CAN
Stellaris Integrated Controller Area Network (CAN)
Main Features
‹
‹
‹
‹
‹
‹
‹
Up to 3 Bosch-licensed CAN controllers
Each supports CAN protocol version 2.0 part A/B
Bit rates up to 1Mb/s
32 message objects, each with its own identifier mask
Maskable interrupt
Disable automatic retransmission mode for Time Triggered
CAN (TTCAN)
Programmable loop-back mode for self test operation
TI also provides
‹
‹
‹
‹
Over 50 CAN-enabled Stellaris® ARM® Cortex™-M3
microcontrollers
The EK-LM3S2965 CAN-network-in-a-CAN evaluation kit
The EK-LM3S8962 CAN-network-plus-Ethernet evaluation
kit
Access to CAN quickstart applications and software
examples from renowned CAN stack providers.
MCUs …
12 - 8
Stellaris One-Day Workshop - CAN Peripheral
Kits and Software
Kits and Software
ADC
Channels
ADC S peed
(K sps)
LDO V ol tage
Regulator
A nalog
Comparators
Digit al
Comparators
?
?
3
-
46 ?
100-LQFP
108-BGA
O/H/D 3
2
2
?
16
1000
?
?
3
7
65 ?
100-LQFP
6
1
2
?
?
100
?
4
8
2
8
?
8
4
2
?
?
2
6
256
96 ?
2
?
IS
6
2
1
QEI
8
LM3S9000s
Package Options
IC
SS I/S PI
1000
4
-
Hibernate
UART
8
-
256
ADC (10-bit )
GPIOs (5-V)
CAN MA C
USB Full Speed
-
IE EE 1588
2
Fault Inputs
2
RTC
3
Outputs
-
50
12
Digital
3
64
LM3S8000s
Analog
Serial Interfaces
Internal T emp
Sensor
Motion
Control
PWM
10/100 Et hernet
MAC+PHY
General P urpose
Tim er Modules
Core
16-bit Timer
Watchdog
Tim ers
CCP
Flash (KB)
Mem ory and
Speed
S RAM (KB)
ROM S W
Library
Max Speed
(MHz )
Internal
Precis ion
Oscillator
32-bit Timer
MCUs in Series
Ethernet+CAN Connected MCUs
First MCUs featuring fully integrated 10/100 Ethernet MAC+PHY and up to 3
Bosch CAN 2.0 A/B MACs
‹ IEEE 1588 Precision Time Protocol hardware assist
‹
–
–
–
–
–
–
Stellaris LM3S8962
Evaluation Kit
$89
Stellaris LM3S8962 MCU with fully-integrated CAN module
OLED graphics display with 128 x 64 pixel resolution
User LED, navigation switches, and select pushbuttons
Magnetic speaker
LM3S8962 I/O available on labeled break-out pads
Standard ARM® 20-pin JTAG debug connector with input and
output modes
‹ Standalone CAN
microcontroller
‹ Ethernet
device board using Stellaris LM3S2110
cable, CAN ribbon cable, USB and JTAG cables
‹
‹
ADC
Ch ann els
ADC Sp eed
(Ksps)
In ter nal Tem p
Se nso r
Analo g
Com pa ra tors
Dig ti al
C omp ar ator s
?
3
7
60 ?
64 -L QF P
10 0-L QF P
10 8-BG A
O/H/ D 3
2
2
?
16
10 00
?
?
3
7
71 ?
64 -L QF P
10 0-L QF P
?
80
?
4
8
2
8
?
8
4
2
-
-
L M 3S500 0s
12
25 6
96
?
80
?
4
8
2
8
?
8
4
2
-
-
2
L M 3S800 0s
12
25 6
64
-
50
-
4
8
1
6
?
6
1
2
?
?
3
L M 3S900 0s
6
25 6
96
?
10 0
?
4
8
2
8
?
8
4
2
?
?
2
Hib er n ate
I 2S
?
96
GPIO s ( 5-V)
I 2C
SSI/SPI
10 00
25 6
L DO Volt age
Regu lato r
UART
16
IEEE 158 8
?
Q EI
2
F ault Inp uts
2
1 0/1 00 Eth er net
MAC+ PHY
3
RT C
CAN M AC
Pack ag e O pt io ns
Dig it al
-
26
SRAM (KB)
R OM SW
Libr ar y
M ax Sp eed
( MH z)
I nter na l
Pr ecisio n
Osc li la tor
32- bit T ime r
ADC (10 -b it)
2
L M 3S200 0s
Flas h ( KB)
An al og
Se ri al In te rf ac es
Ou tpu ts
Mo ti on
Co nt r ol
PWM
USB Fu ll Spee d
G en er al Pu rp o se
T im er M od u les
Cor e
16- bit T ime r
Wat chd og
T ime rs
CCP
M CUs in Ser ie s
CAN Connected MCUs
M em o ry an d
Sp ee d
3
2
2
-
8
10 00
?
?
3
-
46 ?
10 0-L QF P
10 8-BG A
O/H/ D 3
2
2
?
16
10 00
?
?
3
7
65 ?
10 0-L QF P
-
Featuring up to 3 Bosch CAN 2.0 A/B CAN MACs
Independent CAN buffer allows simultaneous CAN usage with all other peripherals
–
–
–
–
–
Stellaris LM3S2965
Evaluation Kit
$79
OLED graphics display with 128 x 64 pixel resolution
User LED, navigation switches, and select pushbuttons
Magnetic speaker
LM3S2965 I/O available on labeled break-out pads
Standard ARM® 20-pin JTAG debug connector with input
and output modes
‹ Standalone CAN
device board using Stellaris
LM3S2110 microcontroller
‹ CAN
Stellaris One-Day Workshop - CAN Peripheral
ribbon cable, USB and JTAG cables
Drivers …
12 - 9
Kits and Software
Drivers
StellarisWare CAN Drivers
‹
StellarisWare has a full set of drivers for the CAN
modules
‹
Bit timing calculations are often complex and
difficult to understand. StellarisWare has an
easy to use API called CANBitTimingSet that
automatically configures the CAN bit timing
based on a passed set of parameters
Š
‹
There are also a set of pre-configured bit timing settings
for each speed that you can use
The clocking on the Fury devices is different than
the Dust Devil and Tempest devices
Š
Š
Fury uses an 8MHz dedicated clock when the PLL is
enabled, and the crystal clock otherwise
Dust Devil and Tempest use the system clock, whether
that is the main oscillator, internal oscillator, or PLL
APIs …
APIs
Stellaris CAN APIs: Initialization and Interrupts
‹
Initialization
Š
CANInit()
CANBitTimingSet(), CANBitTimingGet()
CANBitRateSet()
CANEnable(), CANDisable()
Š
CANRetrySet(), CANRetryGet()
Š
Š
Š
‹
Interrupts
Š
Š
Š
Š
12 - 10
CANIntRegister(), CANIntUnregister()
CANIntEnable(), CANIntDisable()
CANIntStatus()
CANIntClear()
Stellaris One-Day Workshop - CAN Peripheral
Kits and Software
Stellaris CAN APIs: Message Objects and Status
‹
‹
Message objects
Š
CANMessageSet()
Š
CANMessageClear()
Š
CANMessageGet()
Status
Š
CANStatusGet()
Š
CANErrCntrGet()
Code Example …
Code Example
Code Example – CAN Initialization
‹
CAN interfaces must be initialized in both applications
Š
Š
LM3S8962 board – qs_ek-lm3s8962 project
LM3S2110 board – can_device-qs project
// Configure CAN pins
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinTypeCAN(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);
// Enable the CAN controllers
SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
CANInit(CAN0_BASE);
// Configure the clock rate 8MHz, bit rate set to 250K bits/sec
CANBitRateSet(CAN0_BASE, 8000000, 250000);
CANEnable(CAN0_BASE);
// Enable interrupts from CAN controller
CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR);
// Set up the message objects that will receive all messages
CANConfigureNetwork();
// Enable interrupts for the CAN in the NVIC
IntEnable(INT_CAN0);
Stellaris One-Day Workshop - CAN Peripheral
12 - 11
Kits and Software
Message Objects Used in QS Application
‹
Four CAN message objects are used in qs_ek-lm3s8962 app
(can_net.c file)
Š
Š
Š
Š
‹
‹
g_MsgObjectButton – receives button messages (Rx interrupt
enabled) note: there are two buttons, and two events (press & release)
g_MsgObjectLED – sends LED brightness (Tx interrupt enabled)
g_MsgObjectTx – sends commands to 2110 (Tx interrupt enabled)
g_MsgObjectRx – receives commands from 2110 (Rx interrupt enabled)
The “Message Object #” selects one of 32 locations in message
object memory, also determines priority (lower # is higher)
The “Message ID” is the 11-bit or 29-bit message identifier, in this
application, no masking is needed or enabled
Message
Object #
symbol
Message
ID
symbol
1
MSGOBJ_NUM_BUTTON
0x10
MSGOBJ_ID_BUTTON
2
3
MSGOBJ_NUM_LED
MSGOBJ_DATA_TX
0x12
0x20
MSGOBJ_ID_LED
MSGOBJ_ID_DATA_TX
4
MSGOBJ_DATA_RX
0x21
MSGOBJ_ID_DATA_RX
Code Example – Configure Receive Object
‹ LM3S8962 board receives “button” messages from
LM3S2110 CAN device board
‹ g_MsgObjectButton structure is initialized in can_net.c
as follows:
// Set the identifier and mask for the button object
g_MsgObjectButton.ulMsgID = MSGOBJ_ID_BUTTON;
g_MsgObjectButton.ulMsgIDMask = 0;
// This enables interrupts for received messages
g_MsgObjectButton.ulFlags = MSG_OBJ_RX_INT_ENABLE;
// Set the size of the message and the data buffer used
g_MsgObjectButton.ulMsgLen = 2;
g_MsgObjectButton.pucMsgData = g_pucButtonMsg;
// Configure the Button receive message object
CANMessageSet(CAN0_BASE, MSGOBJ_NUM_BUTTON,
&g_MsgObjectButton, MSG_OBJ_TYPE_RX);
12 - 12
Stellaris One-Day Workshop - CAN Peripheral
Kits and Software
Code Example – Configure Transmit Object
‹ LM3S2110 board sends “button” messages to the LM3S8962
board
‹ g_MsgObjectButton structure is initialized in can_device_qs.c
as follows:
// This is the message object used to send button updates. This
// message object will not be “set” using CANMessageSet right now
// as that would trigger a transmission
g_MsgObjectButton.ulMsgID = MSGOBJ_ID_BUTTON;
g_MsgObjectButton.ulMsgIDMask = 0;
// This enables interrupts for transmitted messages.
g_MsgObjectButton.ulFlags = MSG_OBJ_TX_INT_ENABLE;
// Set message length, which should only be two bytes and the
// data is always whatever is in g_pucButtonMsg
g_MsgObjectButton.ulMsgLen = 2;
g_MsgObjectButton.pucMsgData = g_pucButtonMsg;
Code Example – Transmit Button Object
‹ LM3S2110 board transmits a button message to the 8962 using
g_MsgObjectButton
‹ g_MsgObjectButton has already been initialized except for the
two bytes of data containing the event (press or release) and specific
button (up or down)
Once data is set, CANMessageSet() is called to transmit the
message
‹
// ucEvent can be EVENT_BUTTON_PRESS (0x10)
//
or EVENT_BUTTON_RELEASED (0x11)
g_MsgObjectButton.pucMsgData[0] = ucEvent;
// ucButton can be TARGET_BUTTON_DN (1)or TARGET_BUTTON_UP (0)
g_MsgObjectButton.pucMsgData[1] = ucButton;
// send the message
CANMessageSet(CAN0_BASE,MSGOBJ_NUM_BUTTON,&g_MsgObjectButton,
MSG_OBJ_TYPE_TX);
Stellaris One-Day Workshop - CAN Peripheral
12 - 13
Kits and Software
Code Example – Receive Object
‹ 8962 board receives a button message from the 2110 using
g_MsgObjectButton in the interrupt handler CANHandler()
CANHandler(void)
{
unsigned long ulStatus;
// Find the cause of the interrupt, if it is a status interrupt then just
// acknowledge the interrupt by reading the status register.
ulStatus = CANIntStatus(CAN0_BASE, CAN_INT_STS_CAUSE);
switch(ulStatus)
{
case MSGOBJ_NUM_BUTTON:
{
// Read the Button Message.
CANMessageGet(CAN0_BASE, MSGOBJ_NUM_BUTTON, &g_MsgObjectButton, 1);
// . . . Rest of the code to handle the button message
break;
}
// all other cases: MSGOBJ_NUM_LED,MSGOBJ_NUM DATA_TX,MSGOBJ_NUM_DATA_RX
}
CANIntClear(CAN0_BASE, ulStatus);
Stacks …
}
Stacks
CAN Stacks
‹
The main two protocols used in CAN-based
designs are CANopen and DeviceNet
Š
Other protocols include POWERLINK, EtherCAT,
Profinet, EtherNetIP and also TCP/IP`
http://www.micrium.com
http://www.port.de
http://www.rtaautomation.com /
Lab …
12 - 14
Stellaris One-Day Workshop - CAN Peripheral
CAN Lab
CAN Lab
Description:
We’ll use the LM3S8962 eval board and the LM3S2110 CAN device board to investigate CAN
communication.
CAN Lab
USB
‹
‹
‹
‹
‹
‹
LM3S8962 EVM
LM3S2110 CAN Device board
10-pin CAN cable (not the 20-pin JTAG cable)
USB cable
Buttons on device board send CAN volume messages
Select button on LM3S8962 board lights device LED
Stellaris One-Day Workshop - CAN Peripheral
12 - 15
CAN Lab
Hardware list:
9
9
9
9
LM3S8962 Evaluation Board
LM3S2110 CAN device board
10-pin CAN ribbon cable
3 meter, 4 pin, USB Type A-M to mini-USB Type B-M
Software list:
9 Code Composer Studio 4.1
9 LM3S8962 software examples
12 - 16
Stellaris One-Day Workshop - CAN Peripheral
CAN Lab
Procedure
1. Open the IDE
Open Code Composer Studio and create a workspace_8962CAN workspace (we’re
using a new workspace for each lab to prevent issues and learn the steps by repetition).
Close the Welcome screen if it appears. Click the C/C++ Perspective button to make sure
that you’re in the editing perspective.
2. Import driverlib
From the menu bar, click on Project, and then select Import Existing CCS/CCE Eclipse
Project. When the Import dialog appears, browse to the root directory of the driver library
(C:\StellarisWare\driverlib). Click OK. Be sure that the checkbox next to driverlib in
the Project pane is checked and that Copy projects into workspace is unchecked. Click
Finish.
3. Import the CAN project
From the menu bar, click on Project, and then select Import Existing CCS/CCE Eclipse
Project. When the Import dialog appears, browse to the root directory of the quickstart
project (C:\StellarisWare\boards\ek-lm3s8962\qs_ek-lm3s8962). Click OK. Be sure
that the checkbox next to qs_ek-lm3s8962 in the Project pane is checked and that Copy
projects into workspace is unchecked. Click Finish.
4. Open can_net.c for editing
When the project has finished importing, close any open editor windows. Maximize the
IDE window if you haven’t already and expand the qs_ek-lm3s8962 folder in the
Projects pane.
Double-click on can_net.c to open it for editing.
can_net.c is made up of several modules:
CANMain()
Handles connection to the other device and incoming messages
CANGetTargetVersion()
Retrieves the target board’s firmware version
CANUpdateTargetLED()
Sends message to set brightness of the LED on the target board
CANConfigureNetwork()
Configures message objects used
CANHandler()
CAN interrupt handler
CANConfigure()
Configures the CAN h/w and interrupts
Stellaris One-Day Workshop - CAN Peripheral
12 - 17
CAN Lab
As long as you’re poking around in the CAN code, here are some of the important objects to
look for:
Message Object Structure
typedef struct
{
unsigned long ulMsgID;
unsigned long ulMsgIDMask;
unsigned long ulFlags;
unsigned long ulMsgLen;
unsigned char *pucMsgData;
}
tCANMsgObject
Members:
ulMsgID The CAN message identifier used for 11 or 29 bit identifiers.
ulMsgIDMask The message identifier mask used when identifier filtering is enabled.
ulFlags This value holds various status flags and settings specified by tCANObjFlags.
ulMsgLen This value is the number of bytes of data in the message object.
pucMsgData This is a pointer to the message object’s data.
Description:
The structure used for encapsulating all the items associated with a CAN message object in
the CAN controller.
tCANObjFlags – these are the flag bits in the CAN message object
MSG_OBJ_TX_INT_ENABLE This indicates that transmit interrupts should be enabled, or
are enabled.
MSG_OBJ_RX_INT_ENABLE This indicates that receive interrupts should be enabled, or
are enabled.
MSG_OBJ_EXTENDED_ID This indicates that a message object will use or is using an extended
identifier.
MSG_OBJ_USE_ID_FILTER This indicates that a message object will use or is using filtering
based on the object’s message identifier.
MSG_OBJ_NEW_DATA This indicates that new data was available in the message object.
MSG_OBJ_DATA_LOST This indicates that data was lost since this message object was
last read.
MSG_OBJ_USE_DIR_FILTER This indicates that a message object will use or is using filtering
based on the direction of the transfer. If the direction filtering is used, then ID filtering
must also be enabled.
MSG_OBJ_USE_EXT_FILTER This indicates that a message object will use or is using message
identifier filtering based on the extended identifier. If the extended identifier filtering
is used, then ID filtering must also be enabled.
MSG_OBJ_REMOTE_FRAME This indicates that a message object is a remote frame.
MSG_OBJ_NO_FLAGS This indicates that a message object has no flags set.
12 - 18
Stellaris One-Day Workshop - CAN Peripheral
CAN Lab
5. Test the current software
Before we change anything, let’s make sure that the project works as it is. Connect your
8962 board to your laptop. From the menu bar, click Project and then select Build Active
Project. Sometimes it’s handy to build the project and check for errors without attempting
to load it to Flash memory.
6. Debug and Run
When the build completes, we need to load the program to the board and start the
debugger. Click Target on the menu bar, then click Debug Active Project or you can
simply click the
Debug button.
The program will load to the 8962 Flash memory and the perspective will switch to
Debug. Click the
Run button to start program execution. The maze game on the
OLED display should appear and the speaker should emit the game sounds.
7. Back to the Editor
Click the C/C++ Perspective button (in the upper right) to return to the editor. Page down
and find the CANHandler() module in can_net.c . This module handles the interrupt
caused by received CAN messages. When you have more time, you can look at where
those messages were sent by exploring the can_device_qs project that runs on the
LM3S2110.
8. Look at CANUpdateTargetLED()
We’d like to add some code that will turn the LM3S2110 board status LED on when the
up button is released and off when the down button is released.
If you haven’t looked closely at the CANUpdateTargetLED() module, now would be a
good time to do so. Note that there are two passed parameters:
ucLevel
bFlash
0 is off and 1 is on
true flashes the LED, false does not
Calling CANUpdateTargetLED() with the correct parameters sends a CAN message
from the LM3S8962 board to the LM3S2110 board.
Stellaris One-Day Workshop - CAN Peripheral
12 - 19
CAN Lab
9. Add some code
Find the CANHandler() module and note how AudioVolume() is called to alter the game
volume. Add the calls to CANUpdateTargetLED() as shown below:
if(g_MsgObjectButton.pucMsgData[1] == TARGET_BUTTON_UP)
{
//
// Adjust the volume up by 10.
//
AudioVolumeUp(10);
CANUpdateTargetLED(1, false);
//LED ON
}
//
// Check if the down button was released.
//
if(g_MsgObjectButton.pucMsgData[1] == TARGET_BUTTON_DN)
{
//
// Adjust the volume down by 10.
//
AudioVolumeDown(10);
CANUpdateTargetLED(0, false);
//LED OFF
}
}
break;
12 - 20
Stellaris One-Day Workshop - CAN Peripheral
CAN Lab
10. Change Preferences
It would be nice not to have to Build and Debug in two separate steps. We can change a
selection so that clicking on Debug will rebuild the project if needed.
On the menu bar, click Window, then Preferences. Click on the + next to CCS, and then
click on Debug. Check the Rebuild the program (if required) before loading checkbox.
Click OK
11. Build/Load/Run
Debug button. Save the changes to can_net.c and reload the .out file when
Click the
prompted. The project will automatically build and load to the 8962 Flash memory.
Change the perspective to Debug. Click the
Run button to start program execution.
The maze game on the OLED display should appear and the speaker should emit the game
sounds.
12. Testing our changes
After you click the resume button, don’t touch the up/down buttons until Press Select To
Play appears on the OLED. At that point, pressing the up button on the LM3S2110 sends
a VolumeUp CAN message to the LM3S8962 board, which then responds by sending a
CAN message to turn on the status LED on the LM3S2110 board. The down button
works in a similar fashion to turn the LED off.
If you wait too long and the screen saver appears, press the Select button on the
LM3S8962 board to exit the screen saver mode.
13. Remove changes
Go back to the C/C++ perspective and edit the can_net.c file. Comment out the two lines
that you added to the code. Build/Load/Run again to make sure you’ve removed the
changes.
Remember that the QuickStart application has been replaced by this application. You can
reprogram it at any time with either Code Composer Studio or the Flash Programmer.
You’re done
Stellaris One-Day Workshop - CAN Peripheral
12 - 21
CAN Lab
*** A mind is the only thing that can really be blank ***
12 - 22
Stellaris One-Day Workshop - CAN Peripheral
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertising