Controller area network can
Download
1 / 74

Controller Area Network (CAN) - PowerPoint PPT Presentation


  • 176 Views
  • Uploaded on

Controller Area Network (CAN). Lecture 5.1. Reference. S12MSCANV2.pdf. MSCAN Block Guide V02.14. PIM_9C32 Block Diagram. CAN module. PCA82C250 / 251 CAN Transceiver. Bit time =2500ns. 0.4 Mbps. 3m. =2(15ns + 150ns) = 330ns. 4MHz. 2. 250ns. 2500/250 = 10. 330/250 = 2. 2. 10.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Controller Area Network (CAN)' - maddock-walters


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Controller area network can

Controller Area Network(CAN)

Lecture 5.1


Reference
Reference

S12MSCANV2.pdf

MSCAN

Block Guide

V02.14


PIM_9C32

Block Diagram

CAN module


PCA82C250 / 251

CAN Transceiver


Bit time =2500ns

0.4 Mbps

3m

=2(15ns + 150ns) = 330ns


4MHz

2

250ns

2500/250 = 10

330/250 = 2

2

10

7 so PROP_SEG = 3, PHASE_SEG1 = 3 and PHASE_SEG2 = 3

RJW = 3


3

20x10

= 0.015

3

2(127)

= 0.0118

2

10

3

3

3

3

1.18%


$141

BSET CANCTL1,#$80 ;turn on CAN


$141

;place CAN in init mode

CAN_INI BSET CANCTL0,#$01

BRCLR CANCTL1,#$01,CAN_INI



$141

;Bus clock, listen off

LDAA #$C0

STAA CANCLT1




$140

;CSWAI,WUPE,TIME,SLPRQ off

BCLR CANCTL0,#$2E


$140

;CSWAI,WUPE,TIME,SLPRQ off

BCLR CANCTL0,#$2E


1

3 + 3 = 6

3


$142

1 0


$142

1 0 0 0 0 0 0 1

MOVB #$81,CANBTR0

Prescale = 2



$143

0 0 1 0

TSEG2 = 3

0 1 0 3 Tq clock cycles


0 0 1 0 0 1 0 1

$143

TSEG1 = 6

0 1 0 1 6 Tq clock cycles

MOVB #$25,CANBTR1


ID = 127

ID = 1

IDR0 = $00

IDR1 = $18

IDR2 = $00

IDR3 = $02

IDR0 = $00

IDR1 = $18

IDR2 = $00

IDR3 = $FE


$150

$151

$152

$153


$158

$159

$15A

$15B


$154

$155

$156

$157


$15C

$15D

$15E

$15F


$14B

MOVB #$00,CANIDAC


ID = 127

$FFFF0001

$FFFF0001

$001800FE


ID = 1

$FFFF0001

$FFFF0001

$00180002


;Acceptance & Mask registers

MOVW #$0018,CAN0IDA0 ; ID = $0018

MOVW #$00FE,CAN0IDA2 ; ID = $00FE

MOVW #$FFFF,CAN0IDM0 ; filter = $FFFF

MOVW #$0001,CAN0IDM2 ; filter = $0001

MOVW #$0018,CAN0IDA4 ; ID = $0018

MOVW #$0002,CAN0IDA6 ; ID = $0002

MOVW #$FFFF,CAN0IDM4 ; filter = $FFFF

MOVW #$0001,CAN0IDM6 ; filter = $0001


EXIT CAN INIT MODE

$140

BCLR CANCTL0,#$01


$140

;wait for sync

SYNC BRCLR CANCTL0,#$10,SYNC


LDAB DLR

ANDB #$0F




$146

;wait for an available transmit register

again BRCLR CANTFLG,#$07,again



$146

$14A

LDAA CANTFLG ; read 00000110

STAA CANTBSEL ;write 00000110

<fill TX foreground buffer>

LDAA CANTBSEL ; read 00000010

STAA CANTFLG ;send data out TX1


ID_SMSG dw $0018 ;CAN ID registers

dw $0002

S_DATA db $41 ;CAN DATA

db $42

db $43

db $44

db $45

db $46

db $47

db $48

S_DL db 8 ;CAN DATA Length

PRIO_MSG db 0 ;CAN Priority register

LDX #ID_SMSG ;X -> CAN IDs

LDY #CANTXFG ;Y -> TX foreground buffer

MOVW 2,X+,2,Y+ ;transmit IDs

MOVW 2,X+,2,Y+

LDAB #10

loop1 MOVB 1,X+,1,Y+ ;move 10 bytes to TX FG buffer

DECB

BNE loop1






$144

;wait for new message

self2 BRCLR CANRFLG,#$01,self2

BSET CANRFLG,#$01 ;clr RXF

BSET CANCNTL0,#$80 ;clr RXFRM




ORG $800

;RX Buffer

R_ID rmb 4 ;CAN ID registers

R_DATA rmb 8 ;CAN receive data buffer

R_DL rmb 1 ;CAN DATA Length

; Move data from foreground buffer to RX buffer

LDX #R_ID ;X -> CAN IDs

LDY #CANRXFG ;Y -> RX foreground buffer

MOVW 2,Y+,2,X+ ;receive IDs

MOVW 2,Y+,2,X+

LDAB 8,Y ;B = no. of data bytes

loop1 MOVB 1,Y+,1,X+ ;move data bytes to rx buffer

DECB

BNE loop1


Transmitter Example

;Example of a CAN Transmitter

CANCTL0: EQU $140 ;CAN control register 0

CANCTL1: EQU $141 ;CAN control register 1

CANBTR0: EQU $142 ;CAN bus timing register 0

CANBTR1: EQU $143 ;CAN bus timing register 1

CANRFLG: EQU $144 ;CAN receiver flags

CANRIER: EQU $145 ;CAN receiver interrupt enables

CANTFLG: EQU $146 ;CAN transmit flags

CANTIER: EQU $147 ;CAN transmit interrupt enables

CANTARQ: EQU $148 ;CAN transmit message abort control

CANTAAK: EQU $149 ;CAN transmit message abort status

CANTBEL: EQU $14A ;CAN transmit buffer select

CANIDAC: EQU $14B ;CAN identfier acceptance control


CANRERR: EQU $14E ;CAN Receive error counter

CANTERR: EQU $14F ;CAN Transmit error counter

CANIDA0: EQU $150 ;CAN Identifier acceptance register 0

CANIDA1: EQU $151 ;CAN Identifier acceptance register 1

CANIDA2: EQU $152 ;CAN Identifier acceptance register 2

CANIDA3: EQU $153 ;CAN Identifier acceptance register 3

CANIDM0: EQU $154 ;CAN Identifier mask register 0

CANIDM1: EQU $155 ;CAN Identifier mask register 1

CANIDM2: EQU $156 ;CAN Identifier mask register 2

CANIDM3: EQU $157 ;CAN Identifier mask register 3

CANIDA4: EQU $158 ;CAN Identifier acceptance register 4

CANIDA5: EQU $159 ;CAN Identifier acceptance register 5

CANIDA6: EQU $15A ;CAN Identifier acceptance register 6

CANIDA7: EQU $15B ;CAN Identifier acceptance register 7

CANIDM4: EQU $15C ;CAN Identifier mask register 4

CANIDM5: EQU $15D ;CAN Identifier mask register 5

CANIDM6: EQU $15E ;CAN Identifier mask register 6

CANIDM7: EQU $15F ;CAN Identifier mask register 7

CANRXFG: EQU $160 ;CAN RX foreground buffer thru +$16F

CANTXFG: EQU $170 ;CAN TX foreground buffer thru +$17F


ORG $800

ID_SMSG dw $0018 ;CAN ID registers

dw $0002

S_DATA db $41 ;CAN DATA

db $42

db $43

db $44

db $45

db $46

db $47

db $48

S_DL db 8 ;CAN DATA Length

PRIO_MSG db 0 ;CAN Priority register


ORG $4000

;Initialize CAN port

main BSET CANCTL1, #$80 ;enable CAN

;place CAN in init mode

CAN_INI

BSET CANCTL0,#$01 ;Initialization Mode

BRCLR CANCTL1,#$01,CAN_INI

LDAA #$C0

STAA CANCTL1 ;use bus clock, turn off listen mode

MOVB #$81,CANBTR0 ;3Tq Synch and baud rate prescaler =2

MOVB #$25,CANBTR1 ;1 samp, tseg1=6, tseg2=3 ;

MOVB #$00,CANIDAC ;two 32bit acceptance filters

BCLR CANCTL0,#$01 ;Leave initialization mode

;wait for sync

SYNC BRCLR CANCTL0,#$10,SYNC


;Check to make sure some buffer is empty

again BRCLR CANTFLG, #$07, again

BCLR CANCTL0,#$2E ;CSWAI,WUPE,TIME,SLPRQ off

;select next available buffer as transmit buffer

LDAA CANTFLG

STAA CANTBEL

LDX #ID_SMSG ;X -> CAN IDs

LDY #CANTXFG ;Y -> TX foreground buffer

MOVW 2,X+,2,Y+ ;transmit IDs

MOVW 2,X+,2,Y+

LDAB #10

loop1 MOVB 1,X+,1,Y+ ;move 10 bytes to TX fore buffer

DECB

BNE loop1

LDAA CANTBEL ;read next available TX buffer

STAA CANTFLG ;send data over CAN bus

BRA again ;send them all again


Receiver Example

;Example of CAN Receiver

ORG $800

R_ID rmb 4 ;CAN ID registers

R_DATA rmb 8 ;CAN receive data buffer

R_DL rmb 1 ;CAN DATA Length

outa equ $FF4F

out1byt equ $FF52

outcrlf equ $FF5B


ORG $4000

main BSET CANCTL1, #$80 ;enable CAN

;place CAN in init mode

CAN_INI

BSET CANCTL0,#$01 ;Initialization Mode

BRCLR CANCTL1,#$01,CAN_INI

LDAA #$C0

STAA CANCTL1 ;use bus clock, listen mode off

MOVB #$81,CANBTR0 ;3Tq Synch baud rate prescale=2

MOVB #$25,CANBTR1 ;1 samp, tseg1=6, tseg2=3 ;

MOVB #$00,CANIDAC ;two 32bit acceptance filters

;Acceptance & Mask registers

MOVW #$0018,CANIDA0 ; ID = $0018

MOVW #$00FE,CANIDA2 ; ID = $00FE

MOVW #$FFFF,CANIDM0 ; filter = $FFFF

MOVW #$0001,CANIDM2 ; filter = $0001

MOVW #$0018,CANIDA4 ; ID = $0018

MOVW #$0002,CANIDA6 ; ID = $0002

MOVW #$FFFF,CANIDM4 ; filter = $FFFF

MOVW #$0001,CANIDM6 ; filter = $0001

BCLR CANCTL0,#$01 ;Leave initialization mode


;wait for sync

SYNC BRCLR CANCTL0,#$10,SYNC

BCLR CANCTL0,#$2E ;CSWAI,WUPE,TIME,SLPRQ off

;wait for new message

again BRCLR CANRFLG,#$01,again

BSET CANRFLG,#$01 ;clr RXF

BSET CANCTL0,#$80 ;clr RXFRM

;Move data from foreground buffer to RX buffer

LDX #R_ID ;X -> CAN IDs

LDY #CANRXFG ;Y -> RX foreground buffer

MOVW 2,Y+,2,X+ ;receive IDs

MOVW 2,Y+,2,X+

LDAB 8,Y ;B = no. of data bytes

ANDB #$0F ;mask upper nibble

STAB R_DL ;R_DL =no. of data bytes

loop1 MOVB 1,Y+,1,X+ ;move data bytes to receive buffer

DECB

BNE loop1


;display data

ldx #R_DATA

ldab R_DL

mn1 jsr out1byt

jsr outcrlf

decb

bne mn1

BRA again

END


ad