Johannes Philippi

sending CAN-message with MC9S08DZ60

Discussion created by Johannes Philippi on Jul 17, 2007
Latest reply on Dec 3, 2008 by Madhavi Reddy
I've got some problems with the CAN-interface. The configuration is as in  the datasheet. It's a simple example. I just try to send a message via CAN - it does not work in the Full Chip Simulation in CodeWarrior.
When executing the line:
//start transmit data
The Simulator tells me: "MSCAN Error - transmit buffer #1 not initialized", to be sure I understand he tells it four times :smileyhappy:
So what isn't initialized? I configured all CAN and CAN-message registers...
/*----------------------------------------------------------ISR CAN_TX------------------------------------------------------------------------------------------------------------ */interrupt ISR_VEC_CANTX void intCANtx(void) {LED1 ^= 1;      //toggle LED1}/*----------------------------------------------------------init CAN-------------------------------------------------------------------------------------------------------------- */void initCAN(void){UINT32 Count;UINT16 idmask;    CANCTL0_INITRQ = 1; // init-mode
  CANCTL1_CANE   = 1; // activate CAN-module  CANCTL1_CLKsrc=0; // select clk source  CANCTL1_LISTEN = 0; // normal-mode  CANBTR0        = 1; // Baud Rate Prescaler = 2  CANBTR0_SJW0   = 0; // Synchronization Jump Width = 1 Tq  CANBTR0_SJW1   = 0; // (CAN0BTR0_SJWx = SJW-1)  CANBTR1        = 4; // Time Segment1 = 5 Tq clock cycle  // (CAN0BTR1=Time Segment1-1)  CANBTR1_TSEG22 = 0; // Time Segment2 = 2 Tq clock cycle  CANBTR1_TSEG21 = 0; // (CAN0BTR1_TSEG2x=Time Segment2-1)  CANBTR1_TSEG20 = 1;  CANBTR1_SAMP   = 0; // one sample per bit
  CANIDAC_IDAM1  = 0; // 4 16-Bit acceptance filter
  CANIDAC_IDAM0  = 1;    idmask = 0x0300;  CANIDAR0 = idmask>>3; // set ID-acceptance registers
  CANIDAR1 = idmask<<5; //
  CANIDMR0 = 0xFF;      // set ID-mask registers
  CANIDMR1 = 0xFF;  CANCTL0_INITRQ  = 0;  // exit init-mode    Count=200000;
   {    Count--;    if (Count==0)    {      SRS = 0xff;  //reset the MCU    }   }      while(CANCTL0_SYNCH==0); // wait for CAN-bus synchronization
  CANRIER_TSTATE1 = 1; // Interrupt, wenn sich der Transmitter-Status  CANRIER_TSTATE0 = 1; // (Error-active, Error-passive, Bus-off) ändert  CANRIER_CSCIE   = 1; // Ein Statuswechsel löst einen Interrupt aus  }/*----------------------------------------------------------send a message via CAN------------------------------------------------------------------------------------------------ */void sendCAN_message(void){  UINT8 tx_buf,data[8],dlen;  UINT16 id;    //configure data of CAN-frame  id = 0x0301;  data[0]= 0x0A;  data[1]= 0x0B;  data[2]= 0x0C;  data[3]= 0x0D;  data[4]= 0x0E;  data[5]= 0x0F;  data[6]= 0xEE;  data[7]= 0xFF;  dlen = 8;    //select background buffer  CANTBSEL=CANTFLG;     tx_buf = CANTFLG;      //set ID  CANTIDR0 = id>>3;  CANTIDR1 = id<<5; //RTR = 0; IDE = 0; ==> standard frames    //set frame-data  CANTDSR0 = data[0];  CANTDSR1 = data[1];  CANTDSR2 = data[2];  CANTDSR3 = data[3];  CANTDSR4 = data[4];  CANTDSR5 = data[5];  CANTDSR6 = data[6];  CANTDSR7 = data[7];    //set data length code  CANTDLR = dlen;   //set buffer priority    CANTTBPR = 0x01;    //start transmit data  CANTFLG=tx_buf;     }

So the main problem is: when executing the last code-line in the send-function, I get the error, and the message ist not sent, because something isn't initialized correctly. 
I've got some other questions too:
Where can I set the baud rate for the CAN-bus?
How do I enable CAN-transmit  interrupts? I was trying to set the CANTXEIEx bits in CANTIER to 1, but in that case the CAN-ISR is executed permanently, the code in main() never reaches the sendCAN_message()-function.
melancolic P.S.:
When I think back to the ATMEL-CAN I feel some nostalgy. There you have 15 Message objects (compared to 3..4 message buffers in this freescale), each has its registers for ID, ID-mask, data length and its configuration registers (rx, tx, interrupts...). For the CAN config there is a big table in the datasheet where you can selct your CPU-frequency, your desired baud rate and look up your register settings for bit timing, time segments and so on... It's a bit easier to check.  I'm sorry I'm bothering you with ATMELs...