+ All Categories
Home > Documents > © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API...

© 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API...

Date post: 11-Jan-2016
Category:
Upload: arnold-gardner
View: 217 times
Download: 1 times
Share this document with a friend
26
© 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010
Transcript
Page 1: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2008, Renesas Technology America, Inc.All Rights Reserved

The RCAN-ET peripheral and the CAN APISH2 & SH2A MCUs

V 1.2 Mar 2010

Page 2: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved2

Course Introduction

Purpose This course explains features of the CAN peripheral “RCAN-ET” and

discusses usage of the firmware CAN API for the SH2 and SH2A MCUs.

Objective Learn about the features of the R-CAN ET peripheral Grasp the overall structure of the Mailbox See what the CAN API offers Learn the difference in receiving and transmitting when using

Polled vs. interrupt design Understand basic error handling, and what test modes are available

Content 25 pages 3 questions

Learning Time 20 minutes

Page 3: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved3

Compliant with Bosch CAN specification 2.0B ISO-11898-1

Clocked 20 to 50 MHz for CAN data rate up to 1Mbit/s

One receive filter mask per mailbox

‘Mailbox’ = CAN message ‘Buffer’ = ‘Slot’ = A place where a CAN dataframe is stored

Features

Page 4: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved4

Features…

Transmit message queuing by: Regular CAN arbitration mechanism Mailbox number

Sleep mode for low power consumption: Automatic recovery from sleep mode by detecting CAN bus activity Manual recovery from sleep mode

Page 5: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved5

The RCAN-ET Peripheral

Page 6: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved6

The Mailbox 16 mailboxes (slots) - 15 transmit/receive & 1 receive-only.

Mailbox attributes to be set by user application: Extended/Standard ID [IDE], Remote request flag [RTR], Message ID. Acceptance Filter Mask [LAFM]. Data content if transmission mailbox [MSG_DATA_0-7]. New Message Control [NMC]: Overwrite or keep old if message not read in time. Mailbox Control [MBC]; configure as transmit/receive/remote mailbox.

CAN API functions take care of setting attributes - User need not know details!

Page 7: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

PROPERTIES

On passing, 'Finish' button: Goes to Next Slide

On failing, 'Finish' button: Goes to Slide

Allow user to leave quiz: At any time

User may view slides after quiz: After passing quiz

User may attempt quiz: Unlimited times

Page 8: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved8

Interrupts

Interrupt causes Receive complete Transmit complete Errors

– Message error– Transition to states

Error Warning Error Passive Bus Off

CAN Reset, Halt, Sleep/Wake transition

Remote frame reception Message overrun Overload frame sent

Interrupt service routines must be declared with “#pragma” in vect.h#pragma INTERRUPT INT_RCANET0_ERS_0()#pragma INTERRUPT INT_RCANET0_OVR_0()#pragma INTERRUPT INT_RCANET0_RM_0#pragma INTERRUPT INT_RCANET0_SLE_0 ()

Page 9: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved9

Interrupts

Four Interrupt vectors: 104-107. Actual interrupt cause is read inside ISR by reading IRR flags:

Int#104:

Int#105:

Int#106:

Int#107:

Page 10: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved10

Layers: Hardware (bottom) to application software (top).

Application would prefer to interface only to a simple CAN API.=> Not bother with low level details.

Layers

Application

CANopen, Devicenet, J1939

CAN API

CAN peripheral

MCU / transceiver / bus

Optional industrial protocol(not necessary)

Page 11: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

PROPERTIES

On passing, 'Finish' button: Goes to Next Slide

On failing, 'Finish' button: Goes to Slide

Allow user to leave quiz: At any time

User may view slides after quiz: After passing quiz

User may attempt quiz: Unlimited times

Page 12: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved12

The CAN API

The CAN API

Page 13: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved13

CAN Initialization

Top level function call to CAN setup functions

Enable the CAN peripheral.

Enter CAN Reset state.

Initialize all mailboxes.

Set all mailboxes’ masks.

Configure the CAN interrupts.

Set the bitrate.

Exit CAN Reset state.

Enable CAN ports.

voidR_CAN_Initial ( void )

The CAN API

Page 14: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved14

Data Frame Transmit

Set up a mailbox to transmit a CAN dataframe

If previously a receive mailbox, enter halt mode.

Setup ID, DLC for the mailbox.

Set mailbox to transmit mode. (MB 0 cannot transmit.)

Write data frame payload.

Enable mailbox Tx-interrupt unless USE_CAN_POLL was defined.

Request transmission.

voidR_CAN_SetTxStdData ( uint8_t mbx_nr,

can_std_frame_t* tx_dataframe_p )

The CAN API

Page 15: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved15

Data Frame Transmit Verification

Transmit verification

Not necessary

When message is sent - flag main application

Do not define USE_CAN_POLL

Successful data frame transmit automatically triggers ISR

INT_RCANET0_SLE_0()

Flag main program that data was sent.

Define USE_CAN_POLL

Check if data received by regularly calling

R_CAN_CheckTxStdData()

If returns API_OK, message sent.

Two methods available

Polling

Transmit complete interrupt

Page 16: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved16

Configure Mailbox to Receive

Set up a mailbox to receive

Enter CAN Halt state

Set specified receive CAN ID for specified mailbox

Set to receive to use the mailbox mask

Overwrite mode set

Receive interrupt enabled unless USE_CAN_POLL defined

voidR_CAN_SetRxStdData ( uint8_t mbx_nr, const int16_t sid )

The CAN API

Page 17: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved17

Receive using Polling or Interrupt

Do not define USE_CAN_POLL

Successful data frame receive automatically triggers ISR

INT_RCANET0_RM_0( )

Copy data to buffer and flag main program that data was received.

Define USE_CAN_POLL

Check if data received by regularly calling

R_CAN_CheckRxStdData()

If yes, process received message

Two methods available

Receive by polling

Receive using receive interrupt

The CAN API

Page 18: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved18

Poll function confirms checks if a framed was received

Use also from receive interrupt to check which mailbox received

If message received, call this!

Reads frame from given mailbox

Writes frame to given address

Checks for overwrite/overrun

Data Frame Receive

uint32_t R_CAN0_PollRxCAN ( uint32_t mbx_nr)

The CAN API

voidR_CAN0_ReadCanMsg ( uint32_t mbx_nr,

can_std_frame_t* frame_p)

Page 19: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved19

Mask Setting

One mask per mailbox

Receive one ID: Set all mask bits to ‘1’

Accept all messages: Set all mask bits to ‘0’ (don’t care)

Accept range of IDs: Set selected bits to ‘0’ (don’t care)

voidset_mask_can ( void )

The CAN API

Page 20: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved20

Error Handling

Check CAN error state regularly

This function returns one of STATE_NO_ERROR (Error Active): OK! STATE_ERROR (Error Active): One or more errors occurred, no need to

take action! STATE_ERROR_PASSIVE: Over 127 errors occurred – warn user! STATE_BUSOFF: Node will not transmit until it recovers.

notify user that node is not working and restart application when unit returns to Error Active.

uint8_tR_CAN_CheckErr ( void )

The CAN API

Page 21: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved21

Application Handling of Bus Off

Bus Off reached

Peripheral recovered:

Reinitialize CAN peripheral and

slots

Normal application activityPoll if peripheral is in Bus Off

Application can not send or receive

System goes into error mode:Poll if peripheral recovers

Page 22: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved22

Loopback - Self Test Mode 1

Transmit slot

Receive slot

CAN bus

Message transmission

Same ID set for

transmit

and receive slot

Node can acknowledge its own data,

and receive sent data to another

mailbox via CAN bus

(Communicating node not necessary)

Page 23: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved23

Loopback - Self Test Mode 2

Transmit slot

Receive slot

Message transmission

CAN bus

Same ID set for

transmit

and receive slot

Node can acknowledge its own data,

and receive sent data to another

mailbox without CAN bus

(Communicating node not necessary)

Page 24: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved24

Listen Only Mode

Bus node

Bus nodeTransmitting

node

Bus node

Bus node

Node inListen Only

mode

TransmittingNode

Node inListen Only

mode

Nodetransmitting

frame

“Normal” node: ACK is output,

or, if communication error,

Error frame is output instead.

No ACK or Error

frame sent by

Listen Only node!

Page 25: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

PROPERTIES

On passing, 'Finish' button: Goes to Next Slide

On failing, 'Finish' button: Goes to Slide

Allow user to leave quiz: At any time

User may view slides after quiz: At any time

User may attempt quiz: Unlimited times

Page 26: © 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.

© 2010, Renesas Technology America, Inc., All Rights Reserved27

The R-CAN ET peripheral features

The Mailbox structure

What the CAN API can do

Polled vs. interrupt design

Basic error handling

CAN Test modes

Course Summary

http://www.renesasinteractive.com


Recommended