AnsweredAssumed Answered

How to receive a CAN message with MM9Z1J638

Question asked by kadir uzun on Jul 12, 2016
Latest reply on Jul 27, 2016 by kadir uzun

Hello all,

 

I am dealing with DEMO code of MM9Z1J638 intelligent battery sensor for a while. I am pretty new with embedded coding, C and all of these topics. As I learn more, I have much more questions.

 

I get how to transmit a CAN message. I made some changes in DEMO code so that I can send whatever the message I want to be sended. Now,, I am trying to understand how receive routine works. In can.c file I found the following piece of C code:

 

interrupt VectorNumber_Vcan0rx void isrCANRx(void)  {

  TYPE_RETURN_CODE can_errorflag;

  u8 length, index, hitid;

 

  hitid = CAN0IDAC & 0x7;

  length = (CAN0RXDLR & 0x0F);

 

  can_errorflag = NO_ERR;

  switch(hitid) {

 

  case 0: // Acceptance code 0 hit

  for (index=0; index<length; index++) {

  rx0_buf[index] = *(&CAN0RXDSR0 + index); /* Get received data */

  }

  rx0_flag = 1;

  break;

  case 1:

  for (index=0; index<length; index++) {

  rx1_buf[index] = *(&CAN0RXDSR0 + index); /* Get received data */

  }

  rx1_flag = 1;

  break;

  case 2:

  for (index=0; index<length; index++) {

  rx2_buf[index] = *(&CAN0RXDSR0 + index); /* Get received data */

  }

  rx2_flag = 1;

  break;

  case 3:

  for (index=0; index<length; index++) {

  rx3_buf[index] = *(&CAN0RXDSR0 + index); /* Get received data */

  }

  rx3_flag = 1;

  break;

  default:

  can_errorflag = ERR_NO_ACC_HIT;

  break;

  }

  CAN0RFLG = 0x01;   /* Clear RXF */

}

 

I did not really understand how this code works, how it gets the message from transmitter. Where is the message kept? There is a switch-case statement for different can message IDs, but What happens if the id is not 0,1,2, or 3 but something like 143? These are some of the questions I can not answer.

 

I will be glad if you have any idea or recommendations.

Outcomes