Nicholas LaBonte

MCF51JM128 CAN tx issues

Discussion created by Nicholas LaBonte on Feb 24, 2009
Latest reply on Feb 25, 2009 by kef

I'm writing a CAN transmit function and I'm having problems with the wrong data being transmitted onto the bus.  The data that is transmitted on to the bus (and received when in loopback mode) is not what I am writing into the IDR0..3, DSR0..7, and DLR registers.  I can scope the tx line and see the data transmitted is, indeed, what is being received in loopback mode: the wrong data.

 

I'm using Codewarrior V6.2 and the DEMOJM board.  The tx function follows:

 

 

 


void CAN_send_bytes(N_AI_t N_AI, N_data_t* data, signed int len)
{
  char *dataptr;
  volatile char temp0, temp1, temp2, temp3;

DisableInterrupts;
//standard (11-bit) addressing only
    temp0 = (char)( N_AI.CANID >> 3 );
    temp1 = (char)( N_AI.CANID << 5 );
    temp1 &= ~0x10;//    CANRIDR1_IDE = 0;
  
    if(N_AI.RTR)
      temp1 |= 0x08;
    else
      temp1 &= ~0x08;
  
    temp2 = 0;
    temp3 = 0;
  
    CANRIDR0 = temp0;
    CANRIDR1 = temp1;
    CANRIDR2 = temp2;
    CANRIDR3 = temp3;

    CANRDLR = 8;//(char)len + 1; //data + 1 N_PCI byte
  
    temp0 = (char)(len & 0x0F);
    CANRDSR0 = temp0;
  
    dataptr = (char*)&CANRDSR1;
  
    while(len--)  
    {
      *dataptr = *data;
      ++dataptr;
      ++data;
    }

  do
  {
    CANTBSEL = CANTFLG;
  }while(!CANTBSEL); //select available transmit register.  keep looping until one is available.

  CANTFLG = CANTBSEL;
EnableInterrupts;
}

I think that I'm using the process stated in the Functional Description and Programmer's Model sections of the data sheet.  Any ideas on where I'm going wrong?

 

 

Message Edited by ElBonte on 2009-02-24 04:13 PM

Outcomes