MC9S08DZ60 MSCAN transmission almost works, but not quite

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

MC9S08DZ60 MSCAN transmission almost works, but not quite

2,934 Views
bdayberr
Contributor I
    I am using the MSCAN module on the MC9S08DZ60 to communicate with vehicles. The vehicle bus runs at 500 kbps and uses the CAN2.0A (standard 11-bit id) standards. I have followed application note AN3034 which has been most helpful in utilizing the MSCAN. I have used their code for the most part, with a minor modification to avoid nasty pointer dereferencing. The problem is this: I can hook up a scope to CANH-CANGND and see plausible data, and also can freeze the data and look at the pulse width to confirm that it is running at 500 kbps. However, when I hook up a CANUSB device that displays CAN messages on my laptop, it does not receive any of the messages. I hook the same device up to a PIC with CAN and it works fine. I have also made sure that the Ohms from CANH to CANL on the demo board reads about 120. Within the code, it seems to always get hung up waiting for a transmit acknowledge or finish, in the portion of the code at the end of the transmit function:

unsigned char CAN0SendFrame(unsigned long msgid, unsigned char priority, unsigned char length, unsigned char *txdata){
  unsigned int txbuffer;
  unsigned int index = 0;
  if (!CANTFLG){
    return 1;  
  }                          
  CANTBSEL = CANTFLG;      
  txbuffer = CANTBSEL;     

  /* Load Id to IDR Register */
  /*((unsigned long *) ((unsigned long)(&CANTIDR0))) = msgid;*/ This is the original pointer dereference I mentioned which I commented out and used my own below. CANTIDR_ARR is a pointer to the first CANTIDR0 register and the memory beyond. Maybe this is part of the problem, but I could never get the original commented line to ever compile
  *CANTIDR_ARR = (unsigned long)msgid;
  for(index=0;index<length;index++)
  {
      *(&CANTDSR0 + index) = txdata[index];   /* Load data to Tx buffer
                                                  * Data Segment Registers
                                                  */
  }
  CANTDLR = length;                           /* Set Data Length Code */
  CANTTBPR = priority;                        /* Set Priority */
  CANTFLG = txbuffer;                          /* Start transmission */
  /*while ( (CANTFLG & txbuffer) != txbuffer);  /* This is where the program would always hang and get stuck, even with my different while loop below, it always hangs here. I am not sure if this is part of the problem or a result of the problem.
                                                  */
  while ( CANTFLG != txbuffer );   
   
}

Any help that anyone can offer is most appriciated. Thank you.
Labels (1)
0 Kudos
Reply
1 Reply

274 Views
allawtterb
Contributor IV


bdayberr wrote:
  /*((unsigned long *) ((unsigned long)(&CANTIDR0))) = msgid;*/ This is the original pointer dereference I mentioned which I commented out and used my own below. CANTIDR_ARR is a pointer to the first CANTIDR0 register and the memory beyond. Maybe this is part of the problem, but I could never get the original commented line to ever compile
  *CANTIDR_ARR = (unsigned long)msgid;



I don't think your line of code will work the way you want.  This is only going to set the MSB in the ID register.  The line you commented out should work, what errors did you get?
0 Kudos
Reply