Receive data uninterruptedly from a CAN module

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

Receive data uninterruptedly from a CAN module

682 Views
shiyinbiao
Contributor II

How can I use a CAN module to receive ten frame data uninterruptedly.Because when I send data to MPC5606B, I can only received two frame data at the most.My code based on MPC5606B as follows:

 

void RecieveMsg (void)
{
   uint8_t j;
   vuint32_t dummy;
   vuint32_t RxID=0;
   if(CAN_0.IFRL.B.BUF04I == 1)
    {
         RxCODE = CAN_0.BUF[4].CS.B.CODE; 
         RxID = CAN_0.BUF[4].ID.R;
         RxLENGTH = CAN_0.BUF[4].CS.B.LENGTH;
         for (j=0; j<RxLENGTH; j++)
         {
            RxDATA[j] = CAN_0.BUF[4].DATA.B[j];
            printf("RxDATA :%x\r",(uint16_t)RxDATA[j]);/*Via a serial port to print data to screen*/
         }
         RxTIMESTAMP = CAN_0.BUF[4].CS.B.TIMESTAMP;
         dummy = CAN_0.TIMER.R; 
         CAN_0.IFRL.R = 0x00000010; 
    }

}

Labels (1)
2 Replies

591 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

I checked your code and the problem is most probably in function printf. Calling this function has huge overhead and during the printing message via UART, CAN messages get lost except the first one you receive and the last one, which stays in SMB.

There are few ways, how to solve this problem.

The simplest one is to configure individual masking and initialize 10 message buffers.

Second way is to create buffer in RAM memory and send data from this buffer outside the FlexCAN interrupt.

Regards,

Martin

591 Views
shiyinbiao
Contributor II

Thank you very much.

0 Kudos