Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "© 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010."— Presentation transcript:

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

2 © 2010, Renesas Technology America, Inc., All Rights Reserved 2 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

3 © 2010, Renesas Technology America, Inc., All Rights Reserved 3  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

4 © 2010, Renesas Technology America, Inc., All Rights Reserved 4 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

5 © 2010, Renesas Technology America, Inc., All Rights Reserved 5 The RCAN-ET Peripheral

6 © 2010, Renesas Technology America, Inc., All Rights Reserved 6 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!

7

8 © 2010, Renesas Technology America, Inc., All Rights Reserved 8 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 ()

9 © 2010, Renesas Technology America, Inc., All Rights Reserved 9 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:

10 © 2010, Renesas Technology America, Inc., All Rights Reserved 10  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 Optional industrial protocol (not necessary)

11

12 © 2010, Renesas Technology America, Inc., All Rights Reserved 12 The CAN API

13 © 2010, Renesas Technology America, Inc., All Rights Reserved 13 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. void R_CAN_Initial ( void ) The CAN API

14 © 2010, Renesas Technology America, Inc., All Rights Reserved 14 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. void R_CAN_SetTxStdData ( uint8_t mbx_nr, can_std_frame_t* tx_dataframe_p ) The CAN API

15 © 2010, Renesas Technology America, Inc., All Rights Reserved 15 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

16 © 2010, Renesas Technology America, Inc., All Rights Reserved 16 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 void R_CAN_SetRxStdData ( uint8_t mbx_nr, const int16_t sid ) The CAN API

17 © 2010, Renesas Technology America, Inc., All Rights Reserved 17 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

18 © 2010, Renesas Technology America, Inc., All Rights Reserved 18  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 void R_CAN0_ReadCanMsg ( uint32_t mbx_nr, can_std_frame_t*frame_p)

19 © 2010, Renesas Technology America, Inc., All Rights Reserved 19 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) void set_mask_can ( void ) The CAN API

20 © 2010, Renesas Technology America, Inc., All Rights Reserved 20 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_t R_CAN_CheckErr ( void ) The CAN API

21 © 2010, Renesas Technology America, Inc., All Rights Reserved 21 Application Handling of Bus Off Bus Off reached Peripheral recovered: Reinitialize CAN peripheral and slots Normal application activity Poll if peripheral is in Bus Off Application can not send or receive System goes into error mode: Poll if peripheral recovers

22 © 2010, Renesas Technology America, Inc., All Rights Reserved 22 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)

23 © 2010, Renesas Technology America, Inc., All Rights Reserved 23 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)

24 © 2010, Renesas Technology America, Inc., All Rights Reserved 24 Listen Only Mode Bus node Transmitting node Bus node Node in Listen Only mode Transmitting Node Node in Listen Only mode Node transmitting 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!

25

26 © 2010, Renesas Technology America, Inc., All Rights Reserved 26 Quiz 2  Before designing your application, you need to decide whether you will poll mailboxes for received messages, or use the CAN receive interrupt.  True  False  In general, the quickest way to take care of incoming data from a CAN mailbox is to poll the mailbox.  True  False  You should copy received data to a buffer, so it is safe from overwrites from newer CAN data.  True  False  A CAN message is acknowledged by the same node that sent the message if a mailbox is configured to receive the same ID.  True, unless Self Test mode 1 or 2 is used.  False, unless Self Test mode 1 or 2 is used.

27 © 2010, Renesas Technology America, Inc., All Rights Reserved 27  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


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

Similar presentations


Ads by Google