Brennan Dayberry

MC9S08DZ60 MSCAN transmission almost works, but not quite

Discussion created by Brennan Dayberry on Apr 11, 2008
Latest reply on Apr 11, 2008 by Brett Wallace
    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;  
  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;
      *(&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.