msCAN question?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

msCAN question?

3,814 Views
Smith_Tom
Contributor I
Hi,
Does anybody tried to work with the CAN bus on the current board of 9s12dp256?
 
I have some question on it ...
 
At first,my program works properbly in loop back mode.
However when I config it to work in nomal mode . the listening CAN node receive nothing.
Does the following Initialize have error?
:smileyhappy:
void MSCAN_INITIAL(void)
{
 CAN0CTL0_INITRQ=1;
 CAN1CTL0_INITRQ=1;         //the MSCAN Initialization Mode
 while(!CAN0CTL1_INITAK);   //The MSCAN has entered Initialization Mode.
 while(!CAN1CTL1_INITAK);   
 
 CAN0CTL1_CANE=1;    //CAN0 enable && Oscillator Clock.
 CAN1CTL1_CANE=1;    //CAN1 enable
 CAN0IDAC=0x20;               //Eight identifier acceptance filters,
 CAN1IDAC=0x20;
 
 CAN0IDAR0=ID0[0];
 CAN1IDAR0=ID1[0];
 CAN0IDAR1=ID0[1];
 CAN1IDAR1=ID1[1];
 CAN0IDAR2=ID0[2];
 CAN1IDAR2=ID1[2];
 CAN0IDAR3=ID0[3];        //MSCAN Identifier Acceptance Registers
 CAN1IDAR3=ID1[3];
 CAN0IDAR4=0x41;
 CAN1IDAR4=0x41;
 CAN0IDAR5=0x41;
 CAN1IDAR5=0x41;
 CAN0IDAR6=0x41;
 CAN1IDAR6=0x41;
 CAN0IDAR7=0x41;
 CAN1IDAR7=0x41;
 CAN0IDMR0=0xFF;
 CAN0IDMR1=0xFF;
 CAN0IDMR2=0xFF;
 CAN0IDMR3=0xFF;
 CAN0IDMR4=0xFF;
 CAN0IDMR5=0xFF;        //MSCAN Identifier Mask Registers
 CAN0IDMR6=0xFF;
 CAN0IDMR7=0xFF;
 CAN1IDMR0=0xFF;
 CAN1IDMR1=0xFF;
 CAN1IDMR2=0xFF;
 CAN1IDMR3=0xFF;
 CAN1IDMR4=0xFF;
 CAN1IDMR5=0xFF;
 CAN1IDMR6=0xFF;
 CAN1IDMR7=0xFF;
 CAN0BTR0=0x63;    //Synchronization jump width 2 Tq clock cycles
 CAN1BTR0=0x63;    //Baud Rate Prescaler Bin 100011=35 Prescaler value
 
 CAN0BTR1=0x13;    //SAMP 1 timetime segment 2=2 Tq clock cycles
 CAN1BTR1=0x13;    //                         time segment 1=4 Tq clock cycles
 
 CAN0CTL1_LISTEN=0;  //1 = Listen Only Mode activated
 CAN1CTL1_LISTEN=0;  //LISTEN bit RESET to 1
 
 //CAN1CTL1_LOOPB=1;  //1 = Loop Back Self Test enabled
 
 CAN0CTL0_INITRQ=0; //INITRQ=0
 CAN1CTL0_INITRQ=0;
 while(CAN0CTL1_INITAK);
 while(CAN1CTL1_INITAK);    //out Initialization Mode

 CAN0RIER=0x01;        //CAN0  Interrupt Enable
 CAN1RIER=0x01;        //CAN1  Interrupt Enable
}
 
:smileyvery-happy:
Here is my Transmit program.
     CAN1TBSEL=CAN1TFLG;  //Transmit Buffer Selection
     CAN1TXIDR0=ID0[0];
     CAN1TXIDR1=ID0[1]&0xE0;
     CAN1TXDSR0=0x47;
     CAN1TXDSR1=0x47;
     CAN1TXDSR2=0x46;
     CAN1TXDSR3=0x45;
     CAN1TXDSR4=0x44;//MSCAN 1 Transmit Data
     CAN1TXDSR5=0x43;
     CAN1TXDSR6=0x47;
     CAN1TXDSR7=0x48;     
     CAN1TXDLR=8;      
     CAN1TXTBPR=0x00;        
     CAN1TFLG=CAN1TBSEL;
if you find some errors,I beg you tell me .
thanks a lot for you help me:womanvery-happy:
( if you want to see the hardware of my current board ,you can visit or see the Attachment:
Labels (1)
0 Kudos
Reply
2 Replies

598 Views
Steve
NXP Employee
NXP Employee
Hi,
  The receiver works in loop mode so the set up seems to be ok when the transmitter matches the receiver configuration.
  I suggest you double-check the following:
 1/ Do the bit rate values match the CAN transmitter bit rate? Your divide options look a bit unusual for the common CAN clock values. Are the time quanta configured correctly for the bus and the listening node location on the bus?
  2/ Is the filter is allowing the transmited messages to come through the filter?
 
 Are there other CAN nodes on the bus? In listen only mode the node will not transmit an acknowledge to the transmitter and so the transmitter will be unable to complete a frame.
 I suspect the problem may be due to the msCAN configuration not matching the CAN bus.
0 Kudos
Reply

598 Views
ThomasG
Contributor I

Hi,

I have a similar question/problem.

I am trying to just do a basic CAN message transmission on the Softec SK-S12XDP512-A board using a transmit interrupt.

The interrupt code is:

interrupt void CAN0_Transmit_ISR(void)
{
   DisableInterrupts;
   CAN0TBSEL = CAN0TFLG;
    
   CAN0TXIDR0 = 0xFF;
   CAN0TXIDR1 = 0xFF;
   CAN0TXIDR2 = 0xFF;
   CAN0TXIDR3 = 0xFF;
   
   CAN0TXDSR0 = ATD1DR0H;
   CAN0TXDSR1 = 0x26;
   CAN0TXDSR2 = 0x26;
   CAN0TXDSR3 = 0x26;
   CAN0TXDSR4 = 0x26;
   CAN0TXDSR5 = 0x26;
   CAN0TXDSR6 = 0x26;
   CAN0TXDSR7 = 0x26;
   CAN0TXDLR = 0x08;
   
   CAN0TFLG = CAN0TBSEL;    // Queue transmission on avail. buffer
   CAN0TIER = 0x00;            // Disable interrupts
    
}

 

When I try to debug the code, it halts and says unknown event and I think it is because of the 2nd to last line in the interrupt routine where I assign CAN0TFLG.  Am I doing this incorrectly or do I need to do something else in setting the message up?

 

Thanks in advance.

0 Kudos
Reply