Go Down

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

gone

hello, Dan.
i bought your can shield, it's put together now. what a NICE JOB Y0U did there, nice quality. Thanks !!
im doing the same , doing CAN-BUS monitoring on Jeep 2008 bus. (for diagnosing com issues,,etc) I have full scan tools but need
to see if there are errors say from BCM out bound with  switches turned, like blinkers, HL, or other critical functions.

I saw that one guy here, used a filter to stop the repeats. (from low priority task outbound commands)   
but first i want to get  this working below.
id like to do the loop back test.  port 1 to 2  loop jumper-ed. (first)
does your software library support that?
I see the arduino lib does, but will their (here) application ino, run with your installed lib?
i followed your on line instructions, as to putting your unzipped files. 
my plan is.
loop back , app.
then monitor , app.
then monitor with filters.

thanks again and with any hints. 


togglebit, CAN shield, WIP (to build a jeep CAN monitor)

#376
Apr 03, 2014, 03:04 am Last Edit: Apr 03, 2014, 03:06 am by dan@togglebit.net Reason: 1
Thank you for the kind words and the order! ( flattery will get you everywhere).  Here is a quick mod on the CANexample2 where port 0 is transmitting message ID 0x100 and port 1 is receiving  message ID 0x100.

This builds but i didn't test it, so let us know how it goes.To test: connect the buses (don't forget your termination!), load the code and watch the serial monitor. You should see the println value count upward and roll over. Disconnect the buses (or perhaps just pull termination) and the value should stop increasing. (if i don't have any bugs)

Hope this helps and thanks again!
Dan

Code: [Select]

#include <OBD2.h>
#include <DueTimer.h>

//create the CANport acqisition schedulers
cAcquireCAN CANport0(CAN_PORT_0);
cAcquireCAN CANport1(CAN_PORT_1);


/***** DEFINITIONS FOR RAW CAN FRAME *****/      
cCANFrame  RAW_CAN_Frame1;
cCANFrame  RAW_CAN_Frame2;

void setup()
{
//start serial port
Serial.begin(115200);

//debugging message for monitor to indicate CPU resets are occuring
Serial.println("System Reset");

//start CAN ports, set the baud rate here
CANport0.initialize(_500K);
CANport1.initialize(_500K);

//initialize the items needed to TX/RX raw CAN mesasges
RAW_CAN_Frame1.ID = 0x100;
RAW_CAN_Frame1.rate  = _1Hz_Rate;
 
RAW_CAN_Frame2.ID = 0x100;
RAW_CAN_Frame2.rate  = _1Hz_Rate;
   
//add our raw messages to the scheduler 1
CANport0.addMessage(&RAW_CAN_Frame1, TRANSMIT);
CANport1.addMessage(&RAW_CAN_Frame2, RECEIVE);


//set up the transmission/reception of messages to occur at 500Hz (2mS) timer interrupt
Timer3.attachInterrupt(CAN_RxTx).setFrequency(500).start();

//output pin that can be used for debugging purposes
pinMode(13, OUTPUT);      
}


UINT8 i;

void loop()
{
// this single byte should continously change in our raw CAN transmissions
RAW_CAN_Frame1.U.b[0] = i++;

//print byte from the CAN message we are receiving
Serial.println(RAW_CAN_Frame2.U.b[0],HEX);

//pass control to other task
delay(1000);
}

//this is our timer interrupt handler, called at XmS interval
void CAN_RxTx()
{
//run CAN acquisition schedulers on both ports including OBD and RAW CAN mesages (RX/TX)
CANport0.run(TIMER_2mS);
CANport1.run(TIMER_2mS);
}
Dan - www.togglebit.net - Arduino DUE proto shields - Arduino DUE CAN shields

gone

thanks so very much.
and the code.  ill report back soon.   
I will add a web page showing , my jeep data. 


i will check all that, out... thanks for the test code, very very much.
togglebit, CAN shield, WIP (to build a jeep CAN monitor)

yazen

I am using Arduino Due with external transceiver MCP2551. It worked and I can send and receive messages from the node, but when I put output.rtr = 0 to send a remote request message it doesn't work.
here is my code:

#include <due_can.h>
#include <sn65hvd234.h>
int ch=0;
int id;
void setup() {
  Serial.begin(9600);
CAN.init(CAN_BPS_1000K);
int filter;
//standard
  for (int filter = 3; filter < 7; filter++) {
   CAN.setRXFilter(filter, 0, 0, false);
  }
}

void loop() {
  CAN_FRAME incoming;
  if (CAN.rx_avail()) {
    CAN.get_rx_buff(incoming);
   printFrame(incoming);
  }
  if(Serial.available()>0){
    id=Serial.parseInt();
CAN_FRAME output;
output.id = id;
output.length = 8;
output.data.low = 0x0005f000;
output.data.high = 0x12345678;
output.extended = 0;
output.rtr = 1;
  CAN.sendFrame(output);
    }
}

void printFrame(CAN_FRAME &frame) {
   Serial.print("ID: 0x");
   Serial.print(frame.id, HEX);
   Serial.print(" Len: ");
   Serial.print(frame.length);
   Serial.print(" Data: 0x");
   for (int count = 0; count < frame.length; count++) {
       Serial.print(frame.data.bytes[count], HEX);
       Serial.print(" ");
   }
   Serial.print("\r\n");
}

I have tried putting output.rtr = 1, it gives me the same thing.
any solution for this.

gone

hello dan,  (per your echo code above, and thanks)
i get this error. at compile time.
quote:
Quote
Arduino: 1.5.6-r2 (Windows 7), Board: "Arduino Due (Programming Port)"

Build options changed, rebuilding all

K:\Program Files (x86)\Arduino/hardware/tools/g++_arm_none_eabi/bin/arm-none-eabi-g++ -c -g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=156 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Due" -IK:\Program Files (x86)\Arduino\hardware\arduino\sam\system/libsam -IK:\Program Files (x86)\Arduino\hardware\arduino\sam\system/CMSIS/CMSIS/Include/ -IK:\Program Files (x86)\Arduino\hardware\arduino\sam\system/CMSIS/Device/ATMEL/ -IK:\Program Files (x86)\Arduino\hardware\arduino\sam\cores\arduino -IK:\Program Files (x86)\Arduino\hardware\arduino\sam\variants\arduino_due_x C:\Users\xxxxx\AppData\Local\Temp\build5265564629386830732.tmp\echotest.cpp -o C:\Users\xxxxx\AppData\Local\Temp\build5265564629386830732.tmp\echotest.cpp.o

In file included from K:\Program Files (x86)\Arduino\hardware\arduino\sam\cores\arduino/OBD2.h:17,
                 from echotest.ino:1:
K:\Program Files (x86)\Arduino\hardware\arduino\sam\cores\arduino/due_can.h:72: fatal error: sn65hvd234.h: No such file or directory
compilation terminated.


i look in that folder for due_can.h and it's there.
my K: drives is HDD, my C: drive is SSD, i never install apps to the SDD.

i guess im missing this,  but where it and what folder does it belong? 
sn65hvd234.h

thanks for any help. !!!
togglebit, CAN shield, WIP (to build a jeep CAN monitor)

sorry left these of the first commit, now included on github. They go with the rest of the files in "C:\Program Files (x86)\Arduino\hardware\arduino\sam\cores\arduino"
Dan - www.togglebit.net - Arduino DUE proto shields - Arduino DUE CAN shields

gone

#381
Apr 06, 2014, 03:30 pm Last Edit: Apr 06, 2014, 03:41 pm by gone Reason: 1
thank you Dan !
ok that is done. and good, but ..... now....
now missing duetimer.h

what ive done so far.  (i dont know prerequisites, at all. )
installed newest IDE.
then installed your library parts , dans CAN  zip from your  github , and followed, your instructions page.
i have no other extra libs. installed.
does your lib, build off base IDE package or do i need other libs installed.?
thanks for the help , greatly appreciated.

does your code, Dan , build off this? (or part?)   
https://github.com/arduino/Arduino/tree/can
togglebit, CAN shield, WIP (to build a jeep CAN monitor)

Sorry, these are the files from ivan seidel's DUE Timer library. I put these up, they need to also go into:
C:\Program Files (x86)\Arduino\hardware\arduino\sam\cores\arduino
Thanks for testing all of this! sorry for my assumptions and omissions.
Dan - www.togglebit.net - Arduino DUE proto shields - Arduino DUE CAN shields

yazen

Has anyone worked with the remote request using the due_can library.
according to the library you have to put the frame name with (.rtr) and set it to one for example:

output.rtr = 1;

I have tried this but it didn't work.
should I use another library or is there an alternative solution.

gone

#384
Apr 07, 2014, 01:15 pm Last Edit: Apr 07, 2014, 06:43 pm by gone Reason: 1
thanks dan
i know how hard it is to keep track of what one has in ones library, after a long time and many projects.
i started with a clean install, so im a good tester in this case.
thanks again.

i followed the instructions from mr. ivan
modify the Folder name to "DueTimer", done. all works.
and it compiles now,!,  and uploads. ok.
now to run tests...
loop test passes,
the counts roll from 00 to FF(hex)  Thanks Dan.
[font=Verdana]hoo-hooh[/font]

next stop, a traffic snooper, does anyone have an example for snoop monitor, no transmissons. ( car can snoop)




togglebit, CAN shield, WIP (to build a jeep CAN monitor)

Collin80

My library (https://github.com/collin80/due_can) has a traffic snooper example. The library you're using I believe was based off of my version of the DueCan library so you might be able to retrofit the example to your library. The library you found a while back in the official Arduino tree is an older copy of what my library is based off of. I don't remember if it was an earlier version of my library or what I based my code on. Either way it's fairly old. But, the CAN_TrafficSnooper example from my current library should point you in the right direction.

gone

thanks , C80
ill give that as spin.


togglebit, CAN shield, WIP (to build a jeep CAN monitor)

MorgKrig

Somebody cann tell me if there is a Way to use the CAN on the DUE?
I must works well and it must work guaranteed. :-)

Would be great if someone with Arduino/CAN/DUE experience can talk to me in a pm. Thx a lot.

Paul Stoffregen


I must works well and it must work guaranteed. :-)


Do you realize you're asking for a guarantee on free software written by unpaid volunteers?

What if it doesn't work?  Will you need a refund?

gone

Morg.
yes it will work , the hardware works.
the software is being developed here. if you read all posts, you can see that (no pun)
there is no guarantee, you are the engineer you do that.  (you build it, test it and debug it, )
this IDE, is just that.
why not post your Goal?, to do what? with what other system? (mine is CAR CAN)?
Post your goal.
Post your code. if it fails
State what works and what don't with examples.
does the loop back test work? ;like mine above.?
many here are pleased to help you.   



togglebit, CAN shield, WIP (to build a jeep CAN monitor)

Go Up