Pages: 1 ... 20 21 [22] 23 24 ... 27   Go Down
Author Topic: Building a CAN API for Arduino DUE  (Read 94026 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well I finally got my shield to work reliably, bad soldering was the problem.
Now I am faced with a 29 bit extended frame problem.
I modified the Sample 4 to Serial print some data

#define TEST1_CAN_TRANSFER_ID    0x11AE756A //random 29 bits

          CAN.get_rx_buff(&inFrame);  //read the message
          //display the message
          Serial.print(" fid ");Serial.println(inFrame.fid);
          Serial.print(" ide ");Serial.println(inFrame.ide);
          Serial.print(" inFrame id = "); Serial.println(inFrame.id, HEX);
          Serial.print("  id len = "); Serial.println(sizeof(inFrame.id), HEX);         
         
What I don't see correctly is the inFrame.id.
This is what I get:   
     inFrame id = 2756A
     id len = 4
     fid 40000000
     ide 1

The due_can.cpp file has the following:
        ul_id = m_pCan->CAN_MB[uc_index].CAN_MID;
   if ((ul_id & CAN_MID_MIDE) == CAN_MID_MIDE) { //extended id
      rxframe->id = ul_id & 0x3ffffu;
      //rxframe->id = (ul_id);     // I wanted to look at the id - it always returns a 3 in the leftmost position
      rxframe->ide = 1;
   }
   else { //standard ID
        rxframe->id = (ul_id  >> CAN_MID_MIDvA_Pos) & 0x7ffu;
      rxframe->ide = 0;
   }

        inFrame id = 2756A  //should be  11AE756A that was set as the id
        id len = 4
        fid 40000000
        ide 1
Here is the modified cpp file result:
 inFrame id = 31AE756A

I modified the file to look at the id and it returns 31AE756A (always a 3 in front)

I am hoping someone will show me just how dumb I am that I am overlooking an obvious parameter.




Logged

Earth
Offline Offline
Sr. Member
****
Karma: 12
Posts: 312
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm fairly sure that extended frames are messed up in a variety of ways currently. I'm going back through this library once again and fixing it up so the problems should be corrected within a week or so.  Also, I'm vastly simplifying the interface for most uses so it should be a lot easier to use too.
Logged

Earth
Offline Offline
Sr. Member
****
Karma: 12
Posts: 312
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have just pushed a commit to github. There are two examples now (as opposed to the previous four) but they show how to use the library now. Word of warning: If you update to this version of the library you will very likely need to update your sketch. Some things have changed. The function to get frames (get_rx_buff) now takes a reference parameter instead of a pointer. This should be easier for most people to use. There are now easy functions for sending frames, receiving frames, and setting filters. There is now less need to directly call low level functions or have to mess with the interrupts. A lot more things are handled within the library now. Additionally, all can frames now use CAN_FRAME instead of having different versions for RX and TX. CAN_FRAME now uses a union for the data bytes so you can directly set things 1 byte, two bytes, 4 bytes, or all 8 bytes all at once.

I have done various tests and this version of the library seems to properly send frames in both standard and extended mode. I have tested reception of standard frames but haven't tested reception of extended frames yet. Both included examples have been verified by connecting a Kvaser Leaf Light to a dual canbus board to scope the traffic.

More changes are coming soon. I'll also create a document that details how to use the new functions.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I recently started following this thread and I was trying to see if I could get it to work on my own. I cant, however , seem to get the examples to compile and I keep getting the following errors.

CAN_EchoTest.ino:7:21: error: variant.h: No such file or directory
In file included from C:\Users\jhsieh\Documents\Arduino\libraries\due_can/due_can.h:72,
                 from CAN_EchoTest.ino:8:
C:\Users\jhsieh\Documents\Arduino\libraries\due_can/sn65hvd234.h:34: error: 'uint32_t' does not name a type
C:\Users\jhsieh\Documents\Arduino\libraries\due_can/sn65hvd234.h:37: error: 'uint32_t' does not name a type
C:\Users\jhsieh\Documents\Arduino\libraries\due_can/sn65hvd234.h:39: error: 'uint32_t' does not name a type
etc...

I'm sure I have done something obviously wrong. Can anyone point it out?
Logged

Earth
Offline Offline
Sr. Member
****
Karma: 12
Posts: 312
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well I finally got my shield to work reliably, bad soldering was the problem.
Now I am faced with a 29 bit extended frame problem.

The due_can.cpp file has the following:
        ul_id = m_pCan->CAN_MB[uc_index].CAN_MID;
   if ((ul_id & CAN_MID_MIDE) == CAN_MID_MIDE) { //extended id
      rxframe->id = ul_id & 0x3ffffu;
      //rxframe->id = (ul_id);     // I wanted to look at the id - it always returns a 3 in the leftmost position
      rxframe->ide = 1;
   }
   else { //standard ID
        rxframe->id = (ul_id  >> CAN_MID_MIDvA_Pos) & 0x7ffu;
      rxframe->ide = 0;
   }

Your problem with the extended ID was not your fault at all. You can see in the snippet you posted this line:

rxframe->id = ul_id & 0x3ffffu;

I'm not sure what sort of brain malfunction beset me or whoever wrote that but the proper mask for extended frames is 0x1FFFFFFF not 0x3FFFF. I just fixed that in the git repo. Extended IDs are stored in the bottom 29 bits of the register so all you have to do is mask off the extended bit which is what that line was supposed to do. Try your sketch again and I think you'll see it work better now. Sorry about that.
Logged

Earth
Offline Offline
Sr. Member
****
Karma: 12
Posts: 312
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I recently started following this thread and I was trying to see if I could get it to work on my own. I cant, however , seem to get the examples to compile and I keep getting the following errors.

CAN_EchoTest.ino:7:21: error: variant.h: No such file or directory
In file included from C:\Users\jhsieh\Documents\Arduino\libraries\due_can/due_can.h:72,
                 from CAN_EchoTest.ino:8:
C:\Users\jhsieh\Documents\Arduino\libraries\due_can/sn65hvd234.h:34: error: 'uint32_t' does not name a type
C:\Users\jhsieh\Documents\Arduino\libraries\due_can/sn65hvd234.h:37: error: 'uint32_t' does not name a type
C:\Users\jhsieh\Documents\Arduino\libraries\due_can/sn65hvd234.h:39: error: 'uint32_t' does not name a type
etc...

I'm sure I have done something obviously wrong. Can anyone point it out?

Hmm... variant.h does exist. My guess is maybe you aren't using the proper Arduino IDE (you need 1.5.2 or newer) or that you forgot to set the board to Arduino Due (programming or native port).  Otherwise, you do have the library installed to the proper place so it should work.
Logged

Earth
Offline Offline
Sr. Member
****
Karma: 12
Posts: 312
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I posted another example (a traffic snooper). But, does anyone have any other requests or suggestions? Maybe an example of how to do PID requests and parse responses for OBDII? I'd like at least some of the examples to be useful right off the bat for various things instead of being pointless demonstrations of features.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So originally I noticed I needed to update arduino and I did, but my stupid self forgot to switch the board back after updating. Thanks for the help!
Logged

Munich
Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Collin,

Respect for doing this. I will read this topic in more detail ASAP, because I am now using a UNO with a CAN-bus shield. To use the DUE will be a big inprovement.

Thanks! I will give you feedback and I am willing to help further develop this. You can always PM me if you need help with something. I am not an expert, but  maybe there is something I can do.

Pieter

I have just pushed a commit to github. There are two examples now (as opposed to the previous four) but they show how to use the library now. Word of warning: If you update to this version of the library you will very likely need to update your sketch. Some things have changed. The function to get frames (get_rx_buff) now takes a reference parameter instead of a pointer. This should be easier for most people to use. There are now easy functions for sending frames, receiving frames, and setting filters. There is now less need to directly call low level functions or have to mess with the interrupts. A lot more things are handled within the library now. Additionally, all can frames now use CAN_FRAME instead of having different versions for RX and TX. CAN_FRAME now uses a union for the data bytes so you can directly set things 1 byte, two bytes, 4 bytes, or all 8 bytes all at once.

I have done various tests and this version of the library seems to properly send frames in both standard and extended mode. I have tested reception of standard frames but haven't tested reception of extended frames yet. Both included examples have been verified by connecting a Kvaser Leaf Light to a dual canbus board to scope the traffic.

More changes are coming soon. I'll also create a document that details how to use the new functions.
Logged

Let's make it !

Indiana, USA
Offline Offline
Newbie
*
Karma: 1
Posts: 8
I'm a self-taught electronics engineer from Columbus, Indiana. I've only recently become involved in the Ardunio community.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've read most of this topic, then started skimming though it as troubleshooting questions took up most of the posts.  I wanted to clarify some things and also add to the discussion about the MCP2515 CAN protocol controller that has been used on the ATmega328 among other legacy Arduinos as I have experience with it.  At some point I, if someone else does not try to first, want to make it interoperable with the Due's CAN library so more than two transceivers could be used with the Due.  I suspect after the modifications I recently made to the MCP2515 library that it might work now, but I do not have a Due, yet, to test with.

As for J1939 and other High-Level "CAN" protocols.  Those should be ENTIRELY supported with the CAN controllers on the Due.  I've used the ATmega328 with the MCP2515 to interface directly with J1939 systems.  J1939 really is just a specification to make smart engine sensors and components work between manufactures.  It transmits extended CAN IDs and 8 data bytes.  The only catch is, you have to figure out the CAN ID from the PGN and source address which is not that hard.  If you have access to a list of PGNs and SPNs, you can figure out a lot of what goes on in a J1939 bus.  I used J1939 at my employer, and I have become very familiar with it.

I also want to say that support for higher-level protocols should be made in an additional library that takes use of the CAN library.  There is no reason to add high-level bloat to the low-level library that not everyone will want or need, but that is my opinion.

As for what IC should be implemented on the Due CAN Shield, I would really like to see the 235 used because the ability for auto-baud selection without sending errors to the bus would be very useful to me.  I would also suggest that the standard CAN pin-out be used if a DE9 is put on the shield.
Logged

"Taking the time to make a proper, punctuated, post is a mark of courtesy and respect."  http://forum.arduino.cc/index.php?topic=149022.0

US
Offline Offline
Newbie
*
Karma: 1
Posts: 39
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

FWIW - we have a production run of protoshields with CAN support now available. http://togglebit.net/product/arduino-due-can-shield/. Also found on Ebay. Thank you to everyone who helped and provided feedback!
Logged

Dan - www.togglebit.net - Arduino DUE proto shields - Arduino DUE CAN shields

Venezuela
Offline Offline
Sr. Member
****
Karma: 12
Posts: 430
Ground.......ground........always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice product! Thank you Dan for your contribution to make the Arduino DUE CAN interface easy to access using your protoshield. Please, keep us posted about the feedback from your curstomers. Regards, Palliser.
Logged

Munich
Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys,

I also ordered a prototype shield from Dan. Looking forward to working with it smiley
Logged

Let's make it !

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

is this junit fully working with J1939 CAN-Bus on both channels?
Thought about buying a chipkit max32, but arduino convinced me more if it is working.
Logged

US
Offline Offline
Newbie
*
Karma: 1
Posts: 39
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The unit is "working", in that you can communicate via CAN bus using the libraries published here. Understand J1939 is a higher level protocol that would need to be developed to sit "on top of" the CAN libraries. J1939 is implemented over CAN bus as it's "physical layer". So yes, the hardware works but there would be some software work involved. Perhaps someone on the board has done 1939 work with the DUE and can respond. Feel free to contact me directly as well.
Logged

Dan - www.togglebit.net - Arduino DUE proto shields - Arduino DUE CAN shields

Pages: 1 ... 20 21 [22] 23 24 ... 27   Go Up
Jump to: