Building a CAN API for Arduino DUE

jeancarlo19:
After being successful in the test between CAN bus 0 and 1 in Arduino Due, I've tried to receive messages from an ECU. This ECU sends 13 CAN frames of 64 bytes each one.

Something is not right with this statement. You cannot send more than 8 bytes per frame. It is totally against the spec. This is not to mention that it is impossible to even set a DLC of more than 15 since it only uses 4 bits. So, you either mean 64 bits (8 bytes) or you mean that the ECU uses some form of higher level protocol to send messages as a series of frames. In the latter case there is no support for higher level protocols so that might be a problem.

I'm able to read the first frame but I have no idea about how to read the rest of them. By reading, I guess that the ECU is working with extended frame so I've been trying to mask the whole ID (CAN_ID and frame_ID), setting uc_id_ver=1 and some other options but nothing worked... Am I right with the extended frame CAN bus version? Has anybody experience on that? Is this library working with this kind of CAN bus?
Thanks!!

Yes, if you are using the official version of the library then uc_id_ver being set to 1 means extended frame. To tell you the truth, I have not tried the library (either the official one or the newer one I've worked on) with extended frames. It should work but I just haven't tested.

If you use my newer/modified version of the canbus library you will get hardware interrupts and a software buffer so you can just keep reading new frames out of the software buffer and not worry about messing with mailboxes. If you are using the official version then you need to check for whether a given mailbox has a new message and grab it if so. The act of grabbing the message clears the box to accept another message. So, that part is handled for you. Below are the relevant lines necessary to grab a message. If they're put in a loop you should be able to keep grabbing new messages as they come in.

  // Wait for CAN1 mailbox 0 to receive the data
  while (!(CAN.mailbox_get_status(CAN1, 0) & CAN_MSR_MRDY)) {
  }

  // Read the received data from CAN1 mailbox 0
  CAN.mailbox_read(CAN1, &can1_mailbox);

Of course, I'm going to suggest that you download the version of the library I posted a few messages back and use that. To me it's easier to work with. It will require quite a bit of changing your code around though since I changed so much. As luck would have it, I did update the examples so it should be pretty easy to get up to speed with the different way of doing things.

I will try to do some testing with extended frames to make sure that the library is working with them as well.