Course Introduction Purpose This training course provides an overview of the CAN peripheral in Renesas M16C and R8C microcontrollers that is used to build.

Slides:



Advertisements
Similar presentations
Contents Overview Data Information Frame Format Protocol
Advertisements

Homework Reading Machine Projects Labs
Introduction to CAN.
I2C bus Inter Integrated Circuits bus by Philips Semiconductors
1 The SJA1000 CAN Controller and Linux Driver Cristiano Brudna Universität Ulm Fakultät für Informatik Abteilung Rechnerstrukturen.
Part 2: Preventing Loops in the Network
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
The 8051 Microcontroller Chapter 5 SERIAL PORT OPERATION.
Setha Pan-ngum. History of CAN [1] It was created in mid-1980s for automotive applications by Robert Bosch. Design goal was to make automobiles more reliable,
Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1.
SCI: Serial Communications Interface Presented by: Sean Kline Chad Smith Jamie Cruce.
I/O Unit.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
Dave Mills CANbus: A brief introduction Incorporating: The Fujitsu status Dave Mills Queen Mary, University of London.
The 8051 Microcontroller and Embedded Systems
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
Clock Generation Module MTT CLOCK GENERATION MODULE (CGM)
Lecture 27: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I 2 C) Interface.
The University of New Hampshire InterOperability Laboratory Serial ATA (SATA) Protocol Chapter 10 – Transport Layer.
© 2008, Renesas Technology America, Inc. All Rights Reserved The RCAN-ET peripheral and the CAN API SH2 & SH2A MCUs V 1.2 Mar 2010.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Purpose  This training course describes how to configure the the C/C++ compiler options.
Input/Output mechanisms
Renesas Electronics Europe GmbH A © 2010 Renesas Electronics Corporation. All rights reserved. RL78 Clock Generator.
Lecture 14 Controller Area Network (CAN) NCHUEE 720A Lab Prof. Jichiang Tsai.
M Semiconductor Products Sector Computer Operating Properly Module Detail Slide #1 of 7 Tutorial Introduction PURPOSE -To explain how to configure and.
MICROPROCESSOR INPUT/OUTPUT
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Principles of I/0 hardware.
1-1 Embedded Network Interface (ENI) API Concepts Shared RAM vs. FIFO modes ENI API’s.
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
Lecture 14 DMA Controller & Serial Communications Interface (UART)
Scott Baker Will Cross Belinda Frieri March 9 th, 2005 Serial Communication Overview ME4447/6405.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This course provides an overview of the CPU architecture.
Lecture 11 Low Power Modes & Watchdog Timers
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This training course provides an overview of the CPU architecture.
© 2009, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction  Purpose This training course provides an overview of Message Frames.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose This module provides an overview of sophisticated peripheral.
Siemens Microelectronics, Inc. December 98 Slide 1 HOT50x-5 Version 1.0 HOT50x-5 An Add-On to the HOT50x_1 Hands-On Training Materials for the 8bit Family.
Direct Memory Access Module MTT M DIRECT MEMORY ACCESS MODULE (DMA)
2L01I Renesas Electronics America Inc. © 2012 Renesas Electronics America Inc. All rights reserved. Class ID: 2L02I CAN In A Day Carl Stenquist, Staff.
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
1 ARM University Program Copyright © ARM Ltd 2013 Using Direct Memory Access to Improve Performance.
Renesas Electronics America Inc. © 2010 Renesas Electronics America Inc. All rights reserved. ID 230L: Simplify your Networked Application with CAN and.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Conclusion Speech. Content Organization Pronunciation Handwriting.
12/16/  List the elements of 8255A Programmable Peripheral Interface (PPI)  Explain its various operating modes  Develop a simple program to.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
Serial Communications Interface Module Slide #1 of 19 MC68HC908GP20 Training PURPOSE -To explain how to configure and use the Serial Communications Interface.
© 2009, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction  Purpose:  This course provides an overview of the serial communication.
© 2009, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction  Purpose This course provides an introduction to the peripheral functions.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This course provides an introduction to the peripheral functions.
An Introduction to CAN CAN Basics 2 Renesas Interactive
#1 of 10 Tutorial Introduction PURPOSE -To explain how to configure and use the Timer Interface Module in common applications OBJECTIVES: -Identify the.
Introduction Contain two or more CPU share common memory and peripherals. Provide greater system throughput. Multiple processor executing simultaneous.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Introduction Purpose  This training course demonstrates the Project Generator function.
LonWorks Introduction Hwayoung Chae.
Networked Embedded Systems Pengyu Zhang & Sachin Katti EE107 Spring 2016 Lecture 4 Timers and Interrupts.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Controller Area Network
Tiva C TM4C123GH6PM UART Embedded Systems ECE 4437 Fall 2015 Team 2:
Serial mode of data transfer
Introduction Purpose Objective Content Learning Time
Microprocessor Systems Design I
Timer and Interrupts.
RX Compare Match Timer (CMT)
RX 8-Bit Timer (TMR) 4/20/2011 Rev. 1.00
Programmable Data Communication Blocks
Controller Area Networks (CAN)
Presentation transcript:

Course Introduction Purpose This training course provides an overview of the CAN peripheral in Renesas M16C and R8C microcontrollers that is used to build networked, multiprocessor embedded systems, and the Application Programming Interface (API) used to program that on-chip CAN peripheral. Objectives Get an introduction to the Renesas M16C and R8C CAN peripheral hardware. Understand how to program the CAN peripheral using the Renesas API function calls. Content 29 pages 4 questions Learning Time 45 minutes

MCU data bus CAN bus timing control register CAN control register Message control registers 0 to 15 CAN global mask register CAN local mask register A CAN local mask register B Acceptance filter slots 0 to bit timer Timestamp register (not in R8C/23) Message boxes (Slots 0 to 15) Message ID DLC Data field Timestamp CAN status register CAN slot status register CAN interrupt control register CAN receive error count register CAN transmit error count register CTx CRx CAN receive complete CAN transmit complete CAN error CAN wakeup CAN extended ID register Interrupt control logic To/From External CAN Transceiver Protocol controller Wakeup logic M16C/R8C MCU CAN Peripheral

Message Boxes A B C D E F 16 Message ID (Standard, Extended) DLC (6 Bytes) Data Field (8 Bytes) Timestamp Value (2 Bytes) Communication performed via CAN message boxes: Message boxes –Transmit and receive buffers for CAN messages –Comprise 16 slots of 16 bytes (or 8 words) each –Slots 14 and 15 can be used for BasicCAN slots Individual slots can be set as transmit or receive slots by a program During both transmit and receive operation, slots with the lowest numbers have highest priority; i.e., priority increases as slot number decreases Each slot retains its previous contents until a new message is sent or received.

Interrupt sources: CAN receive complete CAN transmit complete CAN error (error passive state, bus off state, bus error) CAN wakeup Related registers: Interrupt control registers (C0RECIC, C0TRMIC, C01ERRIC, [C01WKIC]) –Set priority levels for interrupt sources listed above CAN interrupt control register (C0IRC) –Enables and disables interrupts for individual message box slots Interrupt Control Logic #pragma INTERRUPT /B fnc_c0recic(); #pragma INTERRUPT /B fnc_c0trmic(); An interrupt service function must be declared with pragma somewhere in the program. Examples:

Renesas M16C CAN peripheral API set_mask_can ( ) config_can ( ) set_rec_std_dataframe_can ( slot_nr, id ) check_rec_success_can ( slot_nr, dataframe* ) – if polling get_message_can ( slot_nr, dataframe* ) set_bitrate_can ( ) abort_trm_can ( slot_nr ) check_err_can ( ) fnc_c0recic ( ) – if using interrupts can_initial ( ) fnc_c0trmic ( ) – if using interrupts set_trm_std_dataframe_can ( slot_nr, dataframe* ) check_trm_std_dataframe_can ( slot_nr) – if polling check_hw_tmr_can ( canblock1_tmo_diag* ) Error functions Initialization functions Transmit functions Receive functions

config_can ( ) Transition to CAN reset/ initialization mode Enable CAN ports Set operating mode Set bit timing and baud rate Set mask registers Transition to CAN operating mode Initializing CAN Peripheral CAN Configuration Procedure START Enter CAN reset/ initialization mode Exit CAN sleep mode CAN reset mode? NO 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 - Timestamp prescaler Set CAN bit timing and baud rate Set mask register Go to CAN operation mode CAN operation mode? NO END YES START END Set interrupt priority level Clear interrupt enable flag Set interrupt enable flag Enable CAN interrupts If using CAN interrupts

Set Baud Rate and Bit Timing END Set CAN clock divide-by-N value Clear protect register Set: Prescaler divide-by-N value Sampling count PTS, PBS1, PBS2, SJW Setting CAN bit timing and baud rate START Set protect register Cancel register protect Set divide ratio for CAN clock Set register protect Set dividing ratio for prescaler Set sampling count Set sampling points PTS, PBS1, PBS2, and SJW set_bitrate_can ( )

Is the following statement true or false? Click Done when you are finished. The R8C/M16C CAN peripheral provides 16 message boxes, each of which has transmit and receive buffers. The message buffers comprise 16 slots of 16 bytes (or 8 words). True False Done Question

Sets up a slot to transmit: 1.Check if transmit possible [ TrmActive = 0?] 2.Clear message control register 3.Prohibit interrupts for slot (if using TX interrupts) 4.Select standard or extended ID 5.Set TX-ID 6.Byte count of transmit data (set DLC) 7.Set transmit data 8.Interrupt enable the slot (if using TX interrupts) 9.Transmit data frame Data Frame Transmit Mode set_trm_std_dataframe_can ( slot_nr, dataframe* ) If multiple slots are set to data frame transmit mode simultaneously, they transmit in order, starting with slot with lowest number

Keep interrupt code short to avoid blocking other interrupts. Confirming Successful Transmission using an Interrupt CAN successful transmission interrupt routine START Check that slot finished sending Notify application etc. CAN successful transmission interrupt routine END Performs successful data frame transmit interrupt routine: Sets a flag so main program knows what data was successfully sent out Notify application Flash an LED, etc. fnc_c0trmic ( ) Verify Successful Transmission

Transmitting the highest-priority message Message transmissionError frameMessage retransmissionReception Receiving ErrorArbitration loss Transmit abort request Transmit request Time limit Applying a time limit to message transmission Message (1) transmission Reception Message (2) transmission Arbitration loss Transmit abort request Transmission request for now highest priority message (2) Transmit Abort

Abort transmission procedure START Transmit requested? Request abort transmission END NO YES Being transmitted? NO YES Send priority message Abort transmission requests unnecessary abort_trm_can ( in_slot ) Transmit incomplete? SentData = 0? Transmit abort request TrmReq 0 When transmit abort complete, transmit highest-priority message

Data Frame Receive set_rec_std_dataframe_can ( slot_nr, id ) Functions performed: Set up slot for receive Prohibit interrupts for slot (if using RX interrupts) Set Standard or Extended ID Set RX-ID Clear message control register Set data frame receive mode Set RecReq to 1 to start receiving Enable interrupts for the receive slot (if using RX interrupts)

Question a.set_rec_std_dataframe_can b.abort_trm_can c.set_trm_std_dataframe_can d.set_bitrate_can Which of the following functions is used to set up a slot to receive? Select the response that applies and click Done. Done

Example 2: Receiving standard data frames/remote frames with IDs 122 and 123 in CAN slot 0 Slot 0 sees on bus Mask register Received message C0GMR ID X SID 10-6 SID 5-0 ID This function does the following: Accept one ID for message box => sets MASK to all ones Accept all messages => sets MASK to all zeros Accept range of messages => sets the dont-care bits of ID to zero in MASK Mask Setting Example 1: Receiving standard data frame/ remote frame with ID 123 in CAN slot 0 Slot 0 sees on bus Mask register Received message C0GMR ID SID 10-6 SID 5-0 set_mask_can ( )

Acceptance Filter Support Unit The ASU function: Determines if received Standard IDs are valid Provides faster response than software filtering Acceptance filter support registers Received ID (11 bits) Upper 8 bits of received ID Converted value of lower 3 bits of received ID Register configuration during read operation CSID 7 CSID 6 CSID 5 CSID 4 CSID 3 CSID 2 CSID 1 CSID 0 SID 10 SID 9 SID 8 SID 7 SID 6 SID 5 SID 4 SID 3 Converted value of lower 3 bits of received ID Upper 8 bits of received ID b0b15b8b7 (ASU registers: C0AFS, C1AFS)

Receive Complete using Polling Confirming by Polling START Finished receiving successfully? Process received message END NO YES Data received? If yes: process received message Note: Check for overruns! CAN slot status register or NewData in CAN message control register

Copy data to buffer Notify main program that data was received Receive Complete using Interrupt CAN successful reception interrupt routine START END Processing for received message Check that the slot finished receiving successfully Confirming successful reception with a CAN successful reception interrupt fnc_c0recic ( )

Checks whether or not received data to slot is complete Looks at receive complete flag (NewData) Reads received message Checks for more received data before leaving (to reduce nr of interrupts) Dataframe = pointer to a dataframe structure Received Message Processing check_rec_success_can ( slot_nr, dataframe ) get_message_can ( slot_nr, dataframe )

Match each CAN API function to the most appropriate explanation by dragging the letters on the left to the correct locations on the right. Click Done when you are finished. set_trm_std_dataframe_can fnc_c0recic B C Done Reset Show Solution A Tells main application that message has been sent successfully D C ASU Determines if received Standard IDs are valid B Executed when an interrupt verifies successful data frame reception D fnc_c0trmic A Sets up a slot to transmit Question

Prescaler (Divide by 1, 2, 4, or 8) 16-bit free-running counter Received ID Received data Timestamp Receive slot Standard cycle: 1-bit-time cycle Reset by software Cycle and initialization are programmable Timestamp Function This function: Automatically writes timestamp during normal receive operation Useful for determining sequence in which a group of messages was received

Polled message boxes - check which slots have new data Receive interrupts - check Active Slot Bits for which slot has received last (If the CAN receive interrupts are used) 1.Set interrupt priority level 2.Clear interrupt request bit 3.Set slot ICR enable flag 4.Set receive enable bit (I flag) Flag registers At system setup time: Running: What Slots Have New Data? CAN receive interrupt control register (c0recic) NewData in CAN message control register CAN status register Received message processing

CAN error generated? CAN bus error handling: CAN error passive state? –Error passive handling CAN bus off state? –Bus off handling Error Confirmation (Interrupt Processing) CAN bus off state? CAN return from bus off Error Confirmation (Polling Processing) Error Handling check_err_can ( ) CAN status register

CAN Status Register b15b14b13b12b11b10b2b1b0 CAN Status Register Error bus off state flag Error passive state flag Error Active State -Normal Bus error state flag Set if any Error frame Error Passive State Bus Off State - too many errors stop transmitting Error! Data Frames Error Passive State - more than 128 erros

Return From Bus Off State Bus Off State Error Active State Slots state changes when - Slot receives 11 consecutive recessive bits 128 times - Return from bus off function is executed CAN control register Sets return from bus off bit to 1 1 b11 Return from bus off function CAUTION - A node is supposed to go bus off if it is faulty. Use this function with care so a faulty node doesnt keep coming back.

Loopback Function This function does the following: Allows confirmation of transmitted content –Useful as self-diagnostic during debugging, etc. Transmit slot Receive slot Message transmission Transmit Unit Same ID set for transmit and receive slot CAN Bus O L O P B A C K

Listen-Only Mode Normal receive completed: ACK output Communication error: Error frame output No ACK or error frame transmit operations are performed Transmit unit Getting Responses Receive unit (Listen-Only mode) Receive unit Normal mode Transmitting Message Transmit unit Receive unit Receive unit (Listen-Only mode) For more CAN API information: CAN Application Note Data on API for R8C and M16C MCUs; download from CAN Specification Version 2.0, 1991, Robert Bosch GmbH M16C/6NK, M16C/1N, M16C/29, R8C/23, etc. hardware manuals

Question Which of these statements correctly describe error handling, slot status and other issues? Select all that apply and then click Done. The polling approach to error confirmation uses the bus error state flag, error active status flag, and bus off status flag in the CAN status register. A slot returns from the bus off state when it receives 11 consecutive recessive bits 128 times or when a Return from bus off function executes. The loopback function is useful as self-diagnostic during debugging because it can confirm transmitted content. A receive unit in listen-only mode doesn't transmit ACKs or error frames. Done

CAN peripheral in R8C and M16C microcontrollers Initializing the CAN peripheral CAN API functions Course Summary