Matt Meier

CAN help on the S08DZ60

Discussion created by Matt Meier on Mar 8, 2012
Latest reply on Mar 8, 2012 by Matt Meier

Hello,

 

I'm having trouble with getting the MSCAN to transmit a message on the MC9S08DZ60.  I have, I think, properly initialized everything, and wrote a subroutine that gets called every 5ms from a timer interrupt.  I know the subroutine gets called, because I toggle a pin, and I can set a breakpoint.  Unfortunately, the CANTX pin never responds.  Right now, the pin is floating.  If I connect it to a CAN network through a transceiver, I get the same result.  I've checked my initialization code and transmit code against some other examples, but I'm not seeing any problem.  I considered that perhaps my code isn't initializing properly, since I'm not waiting for the INITAK bit to be set, but according to the data sheet this should already be set on startup.  Additionally, I can view the initialized registers, and they seem to have the correct values.

 

Moreover, I understand that transmit buffer 0 might not be available when I enter the subroutine.  However, when I step through the program, I can see that buffer 0 is empty every time I enter the subroutine.  I'll reinstate the appropriate logic once I can get this operating, but I took it out lest it casue an issue.

 

I can see that the last step in the subroutine, where I'm supposed to be clearing the CANTFLG, isn't working.  I can see the $01 loaded into register A, but when that gets stored in CANTFLG, CANTFLG remains at $07, and I don't see any life on the TXCAN line.

 

I included my initialization code and the transmit code inline in the post.  If anyone wants the whole thing, I can provide that as well.  I'm using CodeWarrior V10.1 and the PE Micro USB Multilink Interface standalone probe.

 

Thanks in advance,

 

Matt

 

 

 

This is my initialization code:

 

;Initialize CAN

  LDA #$80  ;Enable the CAN peripheral

  STA CANCTL1

  LDA #$F0  ;Enable normal operation, set clock source to bus clock (8MHz)

  STA CANCTL1

  LDA #$67  ;Set 7xTq before sample, 8xTq after, for 500kHz bitrate

  STA CANBTR1

  LDA #$00  ;Clear INITRQ, to enter CAN operation

  STA CANCTL0

 

 

...and this is the subroutine that, I think, should transmit a message:

 

;****CAN_TX***********************************************

  CAN_TX:

  LDA #$01  ;Select transmit buffer 0

  STA CANTBSEL

  LDA #$32  ;Set CAN ID to $191

  STA CANTIDR1

  LDA #$20

  STA CANTIDR0

  LDA #$01  ;Set CAN Message to $0123456789ABCDEF

  STA CANTDSR0

  LDA #$23

  STA CANTDSR1

  LDA #$45

  STA CANTDSR2

  LDA #$67

  STA CANTDSR3

  LDA #$89

  STA CANTDSR4

  LDA #$AB

  STA CANTDSR5

  LDA #$DC

  STA CANTDSR6

  LDA #$EF

  STA CANTDSR7

  LDA #$08  ;Eight transmit bytes

  STA CANTDLR

  LDA #$01  ;Clear transmit flag 0

  STA CANTFLG

 

  LDA PTFD

  EOR #$08

  STA PTFD

 

  RTS

;****END CAN_TX***********************************************

Outcomes