1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

CAN In A Day

33 487 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 33
Dung lượng 1,89 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

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 1

CAN In A Day

Trang 2

Renesas Technology & Solution Portfolio

Trang 3

Microcontroller 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 4

Smart 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 6

Learn how to

view and send CAN dataframes

The lab is straightforward

T h e CA N A P I

Trang 7

Where CAN is Best! – 4 min.

Mainly on-board comm.

Too expensive Poor noise immunity

Trang 8

CAN – Continuously Moving into New Fields

Trang 9

Lowest Levels

Dataframe and Mailbox

Trang 10

Data (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 12

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

Read Read Read

Trang 13

CAN 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 15

Application Level

Trang 16

 Let’s move up the layers.

Layers (Where are we?)

Optional industrial protocol

Trang 17

Dealing 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 18

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 = 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 20

The 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 23

The 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 24

Polling 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 25

Using 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 26

Lab 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 27

Application 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 29

Error 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 30

Minimum 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 31

Questions?

Trang 32

Smart 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!

Ngày đăng: 22/06/2015, 14:04

Xem thêm

TỪ KHÓA LIÊN QUAN