Go Down

Topic: Building a CAN API for Arduino DUE (Read 150534 times) previous topic - next topic

djkrugger

For those looking for an easy solution for the transceiver, i'm using a pair of SN65HVD230 eveluation boards (Amazon) probably you can find them cheaper.

  I could get some commands to be recognized by some car units in the bench, but i need to send timed messages, is there any timing function in the library itself or i just need to stick to "millis"?

McNeight

Is anyone still working on integrating the Due CAN libraries into the mainstream Arduino release?

I've been working on a "unified" CAN library that works for both the SAM3X8E and MCP2515. The library syntax follows Arduino conventions (begin(), available(), read(), write() and end()), and right now I've gotten it down to a pair of #if defined() statements needed in the main .ino to separate the two hardware implementations.

I'm wondering if it's possible to combine the two hardware implementations even further to reduce confusion to new CAN users? Possibly having just a single CAN() class that covers multiple hardware implementations?

Thanks!

-Neil

Jasoncha

Is there any working samples that simply receives data from ecu such as  motec?

Palliser

Hello Jason,
You can try the CAN_TrafficSnooper example from Collin's library. Regards.
https://github.com/collin80/due_can

p

rtfh

#409
Jun 16, 2014, 11:45 pm Last Edit: Jun 16, 2014, 11:56 pm by rtfh Reason: 1
So I have a CAN network already established with multiple nodes fully functional. I have just aquired a Due and would like be able to use the Due to see the traffic on the CAN bus and also be able to send messages. Most/all of these posts deal with using CAN0 and CAN1 to communicate back and forth. I want to be able to see the traffic from an already existing CAN bus, and no this is not in my car...

I have the WaveShare CAN board as I was told these would be good to use for this kind of application because they function at 3.3V. These are the boards: http://www.wvshare.com/product/SN65HVD230-CAN-Board.htm

Can any of you guys provide some help with this?

McNeight

rtfh,

It looks like you are off to a good start with that board. Connect CAN TX on the Due to CAN TX on the board, and the same for CAN RX. Hook up power and ground, and check your termination, and you should be good to go.

And since nobody else had mentioned it, I went ahead and implemented a "unified" CAN library. One API gets you functionality for three different types of CAN controller; Microchip MCP2515, Atmel SAM3X (Due), and Freescale K2x (Teensy 3.1). It's not quite finished yet, but if you are interested in using it, take a look at https://github.com/McNeight/CAN-Library/

-Neil

Jasoncha

Hey Palliser,

I having many problems running the traffic snooper file



CAN_TrafficSnooper:15: error: variable or field 'printFrame' declared void
CAN_TrafficSnooper:15: error: 'CAN_FRAME' was not declared in this scope
CAN_TrafficSnooper:15: error: 'frame' was not declared in this scope
CAN_TrafficSnooper.ino: In function 'void setup()':
CAN_TrafficSnooper:19: error: no matching function for call to 'CANRaw::init(int)'
C:\Users\jj\Desktop\arduino\arduino-1.5.2\hardware\arduino\sam\libraries\CAN/due_can.h:185: note: candidates are: uint32_t CANRaw::init(uint32_t, uint32_t)
CAN_TrafficSnooper:20: error: no matching function for call to 'CANRaw::init(int)'
C:\Users\jj\Desktop\arduino\arduino-1.5.2\hardware\arduino\sam\libraries\CAN/due_can.h:185: note: candidates are: uint32_t CANRaw::init(uint32_t, uint32_t)
CAN_TrafficSnooper:28: error: 'class CANRaw' has no member named 'setRXFilter'
CAN_TrafficSnooper:29: error: 'class CANRaw' has no member named 'setRXFilter'
CAN_TrafficSnooper:33: error: 'class CANRaw' has no member named 'setRXFilter'
CAN_TrafficSnooper:34: error: 'class CANRaw' has no member named 'setRXFilter'
CAN_TrafficSnooper.ino: At global scope:
CAN_TrafficSnooper:39: error: variable or field 'printFrame' declared void
CAN_TrafficSnooper:39: error: 'CAN_FRAME' was not declared in this scope
CAN_TrafficSnooper:39: error: 'frame' was not declared in this scope


any advise?

Collin80

Try to make sure that you really are compiling for the Arduino Due, using the 1.5.4 IDE or newer, and that you don't have any older copies of the library around. I've had people accidentally have two copies with an older one in the first place Arduino looks.

Palliser


Hey Palliser,

I having many problems running the traffic snooper file

[code errors]
any advise?



Hello Jason. It sounds like you have selected the wrong board in your IDE 1.5.X.

p

Hello guys,
i have a so many mcp2551 transceiver chip. and i dont want to wait for work (china ship time 15 days  :smiley-roll: )
so they are 5v level, due is 3.3v level
after the level harmonize (5v>3.3v)
can i use them together with this can api?
Thank you so much
Tufan.

Collin80


Hello guys,
i have a so many mcp2551 transceiver chip. and i dont want to wait for work (china ship time 15 days  :smiley-roll: )
so they are 5v level, due is 3.3v level
after the level harmonize (5v>3.3v)
can i use them together with this can api?
Thank you so much
Tufan.


Sure, I don't see why not. We had standardized on a different chip just because it is 3.3v, reasonably respected, and easy to obtain. But, within reason you can use any canbus transceiver chip you want. The transceiver is almost completely transparent as far as the library goes. The only reason we even have code for the transceiver at all is because the SN65HVD chip we're using has an enable pin so you can turn the transceiver on and off. If you don't care about this you can just hard wire it to on or use a chip that doesn't have an enable pin.

As you mentioned, using a 5V chip will necessitate a level shift. You will, at the least, need to turn the 5V CAN_RX output from the MCP2551 into 3.3V for the Due. I'll bet the 3.3V CAN_TX signal from the Due will trigger the MCP just fine but you'll have to try it.

#416
Jul 14, 2014, 10:03 pm Last Edit: Jul 14, 2014, 11:58 pm by gambit1244 Reason: 1
thank you so much collin80,

i see a howtouse.txt file in new github

but examples are very hard for me
i need to send simple can message
how can i do that? can you show me please a very very simple code like this
because this is doesnt work :(


Code: [Select]


#include "variant.h"
#include <due_can.h>

void setup()
{
CAN.init(250000);
}

void loop()
{
uint32_t id ;
uint8_t length;
uint8_t data[8];

CAN_FRAME myFrame;
myFrame.id = 7E0;
myFrame.length = 1
myFrame.data[0] = 0xFF;
CAN.sendFrame(myFrame);
delay(100);
}



i have a peak system can bus interface  for watch
i want to test my mcp2551  with simple code
thank you so much

anybody can help me please    :~
i need a very simple code for send can message

warm regards.

Collin80

Sorry, I wanted to help but but I've been unable to log into this forum for the past few days. It seems to be fixed now.

Anyway, your code looked right except that you were missing a semi-colon and a hexadecimal prefix. The below two lines are what would have to change:

myFrame.id = 0x7E0;
myFrame.length = 1;

Those are the correct lines.

Thank you so much Collin,
but i cant compile this code where is the bug :(
i am watcihng the can1-can2 tx rx pins of arduino with my saleae logic analyzer

this is the screenshot
thank you for your help

Go Up