AnsweredAssumed Answered

CAN Module : Acknowlegdement errors

Question asked by rschoop on Aug 23, 2011
Latest reply on Aug 24, 2011 by rschoop

Hello All,

 

I am trying to put the CAN module of  a BF538F to work on a CAN bus but still with no luck.

 

I am working on a BF538F EZ-kit lite board version 1.2. Besides this board I also have two CANUSB modules (www.canusb.com).

I can put the two CANUSB modules work properly on the CAN bus, so I can let them communicate with each other.

 

Below you can find a very basic code that is supposed to transmit a frame each second.
But I get many ACK errors. On a oscilloscope I see that the CAN transceiver keeps
retransmitting, but it does'n receive a dominant ACK bit from the receiver CANUSB module.

 

The strange thing is when I enable the debug mode,  everything work fine on the CAN Bus.
The reason is that the  Auto ACK mode is enabled.

 

Can someone have a look at this code and give me some advice ??

Thanks in advance,

 

rschoop

 

<code>

 

/*****************************************************************************
* can_v02.c
*****************************************************************************/
  
#include <cdefBF538.h>
#include <ccblkfn.h>
#include <sys\exception.h>


volatile unsigned int ctr1=0;
volatile unsigned int ctr2=0;
volatile unsigned int ctr3=0;

volatile unsigned short a = 0;


volatile unsigned short dummy1=0;
volatile unsigned short dummy2=0;
volatile unsigned short dummy3=0;
volatile unsigned short dummy4=0;
volatile unsigned short dummy5=0;
volatile unsigned short dummy6=0;
volatile unsigned short dummy7=0;
volatile unsigned short dummy8=0;

 

volatile unsigned short word3=0;
volatile unsigned short word2=0;
volatile unsigned short word1=0;
volatile unsigned short word0=0;

 

EX_INTERRUPT_HANDLER(TMR0)

{

*pTIMER_STATUS = 0x1;

*pCAN_MB31_DATA3 = 0x0201 ;
*pCAN_MB31_DATA2 = 0x0c00 ;
*pCAN_MB31_DATA1 = a ;
*pCAN_MB31_DATA0 = a ;

 

a++;   //  word0 and word1 are incremented each second

 

dummy1 =  *pCAN_STATUS ;
dummy2 =  *pCAN_INTR ;
dummy3 =  *pCAN_GIS ;
dummy4 =  *pCAN_ESR ;


*pCAN_TRS2 = 0x8000 ;

ctr1++;  //  number of timer0 interrupts are counted

ssync();

}

 


EX_INTERRUPT_HANDLER(CAN_TX)

{

ctr2++ ;

*pCAN_TA2 =  0x8000 ;

*pCAN_MBTIF2 = 0x8000 ;

ssync();

 

}

 

EX_INTERRUPT_HANDLER(CAN_ERR)

{
 
dummy5 =  *pCAN_STATUS ;
dummy6 =  *pCAN_INTR ;
dummy7 =  *pCAN_GIS ;
dummy8 =  *pCAN_ESR ;

 

ctr3++ ;

*pCAN_GIS = 0x07ff ;   //  W1C
*pCAN_GIF = 0 ;        //   According to HRM write 0 to clear
*pCAN_ESR = 0xfc  ;    // W1C

 

ssync() ;

}



void main( void )

{
 
int ms = 100000;
int period = 0 ;
int width = 0 ;


*pSIC_IAR2=0x66666660;    //     Timer0 :  IVG 7
*pSIC_IAR5=0x16666666;    //     CAN Rx :  IVG 8 
*pSIC_IAR6=0x66666662;    //     CAN Tx :  IVG 9
*pSIC_IAR4=0x66666663;    //     CAN Error :  IVG 10

  
*pSIC_IMASK0=0x00010000;     //   Timer 0  interrupt enabled
*pSIC_IMASK1=0x00010001;     //   CAN  Tx , CAN Error interrupt enabled
 
 
register_handler(ik_ivg7, TMR0); 
register_handler(ik_ivg9, CAN_TX); 
register_handler(ik_ivg10, CAN_ERR);

  
period = 1000 * ms ;     //   timer0 period time is 1 second
width = 0.7 * period ;
  
      
*pTIMER0_CONFIG=0x1D;
*pTIMER0_PERIOD=period;
*pTIMER0_WIDTH=width ;

 
*pCAN_CLOCK = 19;     // 500 kbps    CCLK is 400 MHz,  SCLK is 100 MHz
*pCAN_TIMING = 0x0334 ;


*pCAN_MB31_ID1 = 0x1f7c;    //   CAN  ID is  0x7df
*pCAN_MB31_ID0 = 0 ;
 
*pCAN_MB31_LENGTH = 8 ;


*pCAN_MC2 = 0x8000 ;
//*pCAN_OPSS2 = 0x8000 ;


*pCAN_MBIM2 = 0x8000 ;   
*pCAN_GIM = 0x07ff ; 

   
//*pCAN_DEBUG = 0x8008 ;
//*pCAN_DEBUG = 0x8038 ;
  
 
*pCAN_CONTROL = 0 ;


while (  (*pCAN_STATUS & 0x0080) != 0 )

{
ctr1++;
 
}
   

*pTIMER_ENABLE=1;

    
while (1) ; 

}

 

</code>

Outcomes