Managing a Mailbox HW takes care of rest Tx mailbox: HW takes care of low level transmit details Transmit Write Write Write to do!. Receive Setup mailbox Write - -Receive Get message
Trang 1CAN In A Day
Trang 2Renesas Technology & Solution Portfolio
Trang 3Microcontroller and Microprocessor Line-up
44 DMIPS, True Low Power Embedded Security, ASSP
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
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
Trang 4Smart Society Challenge
You don’t have time to write and debug a reliable CAN driver
Solution
Use CAN and the CAN API!
Focus on your application!
Connect to the Smart Society with CAN!
Trang 5 Where Use CAN!?
Trang 6Learn how to
view and send CAN dataframes
The lab is straightforward
T h e CA N A P I
Trang 7Where CAN is Best! – 4 min.
Mainly on-board comm.
Too expensive Poor noise immunity
Trang 8CAN – Continuously Moving into New Fields
Trang 9Lowest Levels
Dataframe and Mailbox
Trang 10Data (Bytes)
0-8 bytes
C R C 15
A C K 1
Trang 11 With two channels, 64 mailboxes to use on one bus
More SW design flexibility
Less runtime reconfiguring
Frame Resides in Mailbox
Trang 12Managing a Mailbox
HW takes care of rest
Tx mailbox: HW takes care of low level transmit details
Transmit
Write Write Write
to do!
Receive
Setup mailbox
Write -
-Receive
Get message
Read Read Read
Trang 13CAN Firmware & Peripheral Interaction
CAN Peripheral
Firmware
Node
Mask Mask
Mask
ID=5,Data= ,RX ID=5,Data=123, TX
Transceiver Transceiver Transceiver
123…
Trang 14 Which of these do you need in order to setup a mailbox to transmit?
Trang 15Application Level
Trang 16 Let’s move up the layers.
Layers (Where are we?)
Optional industrial protocol
Trang 17Dealing with the CAN Registers…
…can be tedious.
Sure would be nice to have…
CAN Initialization
START
Enter CAN reset/ initialization 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
Set CAN bit timing and baud rate
Set mask register
Go to CAN operation mode
CAN operation mode? NO Exit CAN sleep mode
Trang 18Initialization, 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 = ENTERSLEEP_CANMODE,
EXITSLEEP_CANMODE, RESET_CANMODE, HALT_CANMODE, OPERATE_CANMODE, CANPORT_TEST_LISTEN_ONLY,
CANPORT_TEST_0_EXT_LOOPBACK, CANPORT_TEST_1_INT_LOOPBACK,
R_CAN_RxSet (ch_nr, mbox_nr, stid, frame_type);
R_CAN_RxRead (ch_nr, mbox_nr, frame_p);
R_CAN_RxPoll (ch_nr, mbox_nr, frame_p);
The CAN API
T h e CA N A P I
Trang 19 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 – Overwrite New message overwrites old
For processing data as soon as it arrives
When messages may not be lost - “linked” messages
To avoid overwrite / overrun
Polling vs Interrupts
Trang 20The API function
Waits for previous frame to finish transmit
Clears message control register
Disables interrupts for mailbox
Trang 21 Not necessary
Example; message in a sequence
Just continuously check for Error Passive/Bus Off
Transmit Verification
#define USE_CAN_POLL 0
Successful Dataframe transmit triggers ISR
Polling
#define USE_CAN_POLL 1 (config_r_can_rapi.h)
Check if data sent by calling
API_status = R_CAN_TxCheck (ch_nr, mbox_nr);
If API_OK, message was sent!
Transmit interrupt
Trang 22 A CAN mailbox configured with an ID can later be reused to handle other IDs?
Question
Trang 23The API
unless USE_CAN_POLL defined
Configure Mailbox to Receive
R_CAN_RxSet(ch_nr, mbox_nr, stid, frame_type);
T h e CA N A P I
Trang 24Polling for Received Data
How to receive Dataframe in application
At System Setup
#define USE_CAN_POLL 1
When polling from app, use
R_CAN_RxPoll(ch_nr, mbox_nr, frame_p);
R_CAN_RxRead (ch_nr, mbox_nr, frame_p);
Copies data to address -> frame_p.
Trang 25Using the Receive Interrupt
How to receive Dataframe in application
At System Setup
#define USE_CAN_POLL 0
When frame arrives with ID set by API
the CAN Receive ISR triggers
R_CAN_RxPoll (ch_nr, mbox_nr, frame_p);
If new frame, call
R_CAN_RxRead (ch_nr, mbox_nr, frame_p);
which copies the data to frame_p
Set a flag to tell the main application that data has been received
Trang 26Lab Setup
YRDK63N
A to mini-B USB cable
To PC for J-Link debug
J8
U A R T
LCD
5V DCNot necessary
CAN only needs 0-3.5 V
J-Link
Debug
Trang 27Application Level Considerations
Trang 28 No real addresses
Messages broadcast to whomever happens to listen!
11-bit ID split into “user protocol” fields
Your CAN Application - Keep in Mind
Trang 29Error Handling
uint8_t R_CAN_CheckErr(void)
STATE_ERROR (Error Active): < 127 CAN transmit and
receive errors occurred, OK!
warn user.
STATE_BUSOFF: Node will not transmit until it
recovers Pause application, notify user that node is not
working Reinitialize CAN and reset mailboxes when node
recovers to Error Active.
T h e CA N A P I
Trang 30Minimum Application Handling of Bus Off
Bus Off reached
Peripheral recovered:
Reinitialize CAN!
Normal application activity
Poll if peripheral is in Bus Off
Application can not send or receive
Trang 31Questions?
Trang 32Smart Society Challenge
You don’t have time to write and debug a reliable CAN driver
Solution
Use CAN and the CAN API!
Focus on your application!
Connect to the Smart Society with CAN!