2L01I Renesas Electronics America Inc. © 2012 Renesas Electronics America Inc. All rights reserved. CAN In A Day © 2012 Renesas Electronics America Inc. All rights reserved.2 Renesas Technology & Solution Portfolio © 2012 Renesas Electronics America Inc. All rights reserved.3 Microcontroller and Microprocessor Line-up Wide Format LCDs Industrial & Automotive, 130nm 350µA/MHz, 1µA standby 44 DMIPS, True Low Power Embedded Security, ASSP 165 DMIPS, FPU, DSC 1200 DMIPS, Performance 1200 DMIPS, Superscalar 500 DMIPS, Low Power 165 DMIPS, FPU, DSC 25 DMIPS, Low Power 10 DMIPS, Capacitive Touch Industrial & Automotive, 150nm 190µA/MHz, 0.3µA standby Industrial, 90nm 200µA/MHz, 1.6µA deep standby Automotive & Industrial, 90nm 600µA/MHz, 1.5µA standby Automotive & Industrial, 65nm 600µA/MHz, 1.5µA standby Automotive, 40nm 500µA/MHz, 35µA deep standby Industrial, 40nm 200µA/MHz, 0.3µA deep standby Industrial, 90nm 1mA/MHz, 100µA standby Industrial & Automotive, 130nm 144µA/MHz, 0.2µA standby 2010 2012 32-bit8/16-bit 32-Bit High Performance DSP, FPU with High Integration © 2012 Renesas Electronics America Inc. All rights reserved.4 Smart Society Challenge You don’t have time to write and debug a reliable CAN driver You need to get your idea to market SOON Solution Use CAN and the CAN API! The CAN API handles controlling the peripheral The CAN peripheral - Handles ALL the low level details Focus on your application! Connect to the Smart Society with CAN! Agenda © 2012 Renesas Electronics America Inc. All rights reserved.5 Where Use CAN!? The CAN Dataframe The CAN Mailbox The CAN API Polling vs. Interrupts Transmit Dataframes Polling vs. Interrupt Receive Dataframes Polling vs. Interrupt Error Handling Lab Application Level Considerations Agenda © 2012 Renesas Electronics America Inc. All rights reserved.6 Lab Learn how to Initialize the CAN peripheral with the API Transmit from a CAN mailbox Receive data to a mailbox Use a low cost CAN Monitor to view and send CAN dataframes The lab is straightforward Reading Understanding Uncommenting code… So don’t leave! The CAN API © 2012 Renesas Electronics America Inc. All rights reserved.7 Where CAN is Best! – 4 min. http://www.youtube.com/watch?v=X9_mYoUuAaQ&feature=youtu.be Mainly on-board comm. Too expensive Poor noise immunity © 2012 Renesas Electronics America Inc. All rights reserved.8 CAN – Continuously Moving into New Fields Machines (knitting) Agriculture Control Electronics Factory Assembly Lines Medical Systems Railway Electronics Marine Electronics Elevators Building Automation Printing, Copying © 2012 Renesas Electronics America Inc. All rights reserved.9 Lowest Levels Dataframe and Mailbox © 2012 Renesas Electronics America Inc. All rights reserved.10 The Dataframe “Standard” 11-bit ID Dataframe ID extend 1 Rem Req 1 I F S 3+ Data (Bytes) 0-8 bytes C R C 15 A C K 1 S O F 1 Identifier 11 Control 6 Data (Bytes) 0-8 bytes Identifier 11 Control 6 Application software only reads/writes CAN ID Data Length Code (in Control Field) Data Field [...]... Dataframe transmit triggers ISR CAN0 _TXM0_ISR() checks which mailbox sent Flag the application that data has been sent! 21 © 2012 Renesas Electronics America Inc All rights reserved Question A CAN mailbox configured with an ID can later be reused to handle other IDs? A True, a mailbox can be reconfigured at runtime Can a mailbox be reconfigured from transmit to receive? A Again, yes! A mailbox can be... Set CAN bit timing and baud rate Set mask register Go to CAN operation mode CAN operation mode? NO YES END 17 © 2012 Renesas Electronics America Inc All rights reserved T h e CAN API The CAN API Initialization, Port and Peripheral Control R _CAN_ Create (ch_nr); R _CAN_ SetBitrate (ch_nr); R _CAN_ PortSet (ch_nr, action_type); [action_type = ENABLE, DISABLE] R _CAN_ Control (ch_nr, action_type); [action_type... USE _CAN_ POLL defined 23 © 2012 Renesas Electronics America Inc All rights reserved Polling for Received Data How to receive Dataframe in application At System Setup In config_r _can_ rapi.h #define USE _CAN_ POLL 1 When polling from app, use R _CAN_ RxPoll(ch_nr, mbox_nr, frame_p); If this returns API_OK, mailbox has new message, call R _CAN_ RxRead (ch_nr, mbox_nr, frame_p); Copies data to address... Renesas Electronics America Inc All rights reserved Dealing with the CAN Registers… CAN Initialization START Enter CAN reset/ initialization mode Exit CAN sleep mode CAN reset mode? NO can be tedious Sure would be nice to have… YES Enable CAN ports Set CAN control register - Loopback mode select bit - Message order select bit - Basic CAN mode select bit - Bus error interrupt enable bit Set CAN bit... until it recovers Pause application, notify user that node is not working Reinitialize CAN and reset mailboxes when node recovers to Error Active 30 © 2012 Renesas Electronics America Inc All rights reserved T h e CAN API Minimum Application Handling of Bus Off Normal application activity Poll if peripheral is in Bus Off Peripheral recovered: Reinitialize CAN! Bus Off reached Application can not send or... New message overwrites old Interrupts For processing data as soon as it arrives When messages may not be lost - “linked” messages To avoid overwrite / overrun 19 © 2012 Renesas Electronics America Inc All rights reserved Transmitting A Frame struct can_ std_data_s { uint16 id; uint8 dlc; uint8 data[8]; }; struct can_ std_frame_t T h e CAN API my_tx_frame; my_tx_frame.id = 0x700; my_tx_frame.dlc... ENTERSLEEP_CANMODE, EXITSLEEP_CANMODE, RESET_CANMODE, HALT_CANMODE, OPERATE_CANMODE, CANPORT_TEST_LISTEN_ONLY, CANPORT_TEST_0_EXT_LOOPBACK, CANPORT_TEST_1_INT_LOOPBACK, CANPORT_RETURN_TO_NORMAL] Send R _CAN_ TxSet (ch_nr, mbox_nr, frame_p, frame_type); R _CAN_ Tx (ch_nr, mbox_nr); R _CAN_ TxCheck (ch_nr, mbox_nr); R _CAN_ TxStopMsg (ch_nr, mbox_nr); Receive R _CAN_ RxSet (ch_nr, mbox_nr, stid, frame_type); R _CAN_ RxRead... my_tx_frame.data[0] = 0x11; my_tx_frame.data[1] = 0x22; R _CAN_ TxSet (0, mbox_nr, &my_tx_frame, DATA_FRAME); The API function Waits for previous frame to finish transmit Clears message control register Disables interrupts for mailbox Sets CAN ID Sets DLC Sets transmit data Transmits Dataframe 20 © 2012 Renesas Electronics America Inc All rights reserved Transmit Verification Not necessary... mbox_nr, frame_p); R _CAN_ RxPoll (ch_nr, mbox_nr, frame_p); R _CAN_ RxSetMask (ch_nr, sid_mask_value, mask_reg_nr); Error Check R _CAN_ CheckErr (ch_nr); 18 © 2012 Renesas Electronics America Inc All rights reserved T h e CAN API Polling vs Interrupts Polling You only need data at a certain execution path You don’t want CAN interrupts interfering some other task Note: – Overrun New message discarded... -> frame_p 24 © 2012 Renesas Electronics America Inc All rights reserved Using the Receive Interrupt How to receive Dataframe in application At System Setup In config_r _can_ rapi.h #define USE _CAN_ POLL 0 When frame arrives with ID set by API the CAN Receive ISR triggers Check which mailbox caused the interrupt with R _CAN_ RxPoll (ch_nr, mbox_nr, frame_p); If new frame, call R _CAN_ RxRead (ch_nr, . The CAN Dataframe The CAN Mailbox The CAN API Polling vs. Interrupts Transmit Dataframes Polling vs. Interrupt Receive Dataframes Polling vs. Interrupt Error Handling Lab Application. Receive data to a mailbox Use a low cost CAN Monitor to view and send CAN dataframes The lab is straightforward Reading Understanding Uncommenting code… So don’t leave! The CAN API ©. Check R _CAN_ CheckErr (ch_nr); The CAN API The CAN API © 2012 Renesas Electronics America Inc. All rights reserved.19 Polling You only need data at a certain execution path You don’t want CAN interrupts