Pages: 1 ... 21 22 [23] 24 25 ... 29   Go Down
Author Topic: Building a CAN API for Arduino DUE  (Read 130281 times)
0 Members and 2 Guests are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks,

already using a UNO with mcp2515 on J1939 Bus.
But its loosing frames...

Wan't to log can traffic in car, especially for programming over bus.
There are 2 separate buses with 125 and 250 kbits.
It would be fine to log both buses at the same time and output over serial bus or on SD-Card.

This unit seems to be powerful enough, but a working library makes the difference...
Logged

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

Hi Lukas and Dan,

I also would like to have an upper level library for both J1939 and OBDII. I ordered an Arduino DUE CAN-Shield from Dan to test the CAN functionalities from the current CAN Library. When I understand how this is done I hope there is a way to work together here on the Forum to develop an OBDII and J1939 upper level Library. That would be so great. For OBDII there is this library from SK PANG (distributed by Sparkfun too) which is used on an UNO: http://skpang.co.uk/catalog/arduino-canbus-shield-with-usd-card-holder-p-706.html

I am not sure how good this library is, but maybe it is straight forward to port it on top of the standard Arduino DUE library.

Somebody experienced with this SK Pang shield and the OBDII library?

Pieter
Logged

Let's make it !

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

On UNO i use that:
http://www.nunoalves.com/open_source/?p=475
but it's loosing frames...

If it makes sense, i will order one of this powerful units too?
Working together and bring this unit on a useful and practical background sounds like a good idea smiley

Also need the K-Line to unlock both can channels in car on the obd socket,
this should be not so hard with a transistor...

Collins library looks good, has anyone tested it successful?
« Last Edit: January 27, 2014, 03:15:57 pm by Lukas_ » Logged

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

I have looked at both of the above mentioned canbus libraries (SK-PANG and nunoalves). In either case the actual PID/OBDII processing is pretty basic and straight forward. There is no reason that such routines could not easily be constructed for the Due canbus library as well. The actual sending and receiving of OBDII frames over canbus is pretty simple. You generally send to a broadcast address a simple frame with 8 data bytes and you get back a frame from the ECU that chose to respond. This frame also has 8 bytes. The format is explained at: http://en.wikipedia.org/wiki/OBD-II_PIDs

As for testing my library successfully: A previous version of it has been used in an open source vehicle control unit for around a year now. The most recent version has been tested by me with various other devices and seems to function. I actually haven't gotten a lot of feedback on the newest version so buyer beware - it works for me though.

That ECU project actually has OBDII/PID code in it already in the WIP branch. I haven't gotten a chance to test it out yet but the basic idea is there. I think that someone suggested that it'd be good to build higher protocol layers into their own libraries and not muddy up the canbus library with all sorts of protocols. That's a good idea. The PID library would be really simple but that's OK. I'll try to create such a thing in the next week or so.
Logged

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

I have a periodic acquisition scheduler for CAN messages and an obd2 lib based upon Collins previous lib I've been working with as well. I will try to do a bit more testing with it and post it new
Logged

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

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

Wow, looks like a lot has been going on since I last looked on this forum.  That's awesome.  I see some people have mentioned J1939.  My immediate application involves J1939 and I have successfully sent messages and received them.  I have even changed the runtime hours and engine temperature on a J1939 display device.  However, in our water pumping schemes we need to vary the speed of the engines and I don't know what the PGN is for that or if it is proprietary data or whatever.  So I am looking forward to higher protocol layers being added by someone more knowledgeable about J1939 than me.  Keep up the good work guys!
Logged

Pacific Electro-Mechanical Inc. - Honolulu -

Indiana, USA
Offline Offline
Newbie
*
Karma: 1
Posts: 16
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

On UNO i use that:
http://www.nunoalves.com/open_source/?p=475
but it's loosing frames...

If it makes sense, i will order one of this powerful units too?
Working together and bring this unit on a useful and practical background sounds like a good idea smiley

Also need the K-Line to unlock both can channels in car on the obd socket,
this should be not so hard with a transistor...

Collins library looks good, has anyone tested it successful?

Try the MCP2515 library on my GitHub...
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

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

Hi,
I'm new to the forum and Arduino. I do know CAN however. Looking forward to getting started with Due CAN.

I don't quite understand the capacitor types specified in the diagram in reply #33. I'm not familiar with the symbols used. Is it a 10uF electrolytic and a 100nF Ceramic ?

Thanks,
Mark
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 129
Posts: 8594
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You cannot tell the type of cap from that schematic, if it's important it should be documented somewhere, either directly on the schem or in a BOM or other documentation.

However as they are just for decoupling I'd say the 100n is a ceramic and the 10u can be a tant or electro or whatever you have in the bottom of a drawer.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Venezuela
Offline Offline
God Member
*****
Karma: 17
Posts: 522
Ground, ground, always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Graynomad is right!

From Atmel's BOM:

ID          VALUE       DESIGNATION                                          REFERENCE                          MANUFR.         FOOTPRINT
---        -------         --------------                                       ------------                         ----------         -----------
C1/C3      10uF       LOW ESR TANTALUM CAPACITOR     TPSA106K010R1800                  AVX                        A 
C2/C4    100nF     Ceramic Capacitor                                  C1608X7R1C104KT                  TDK                       603

Regards,
Palliser
Logged

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

Thanks, I now have both CAN channels working.

I've written a very simple gateway (below) and tested it using CANalyzer. I used two messages for each CAN channel - each message containing 2 x 32 bit signals. I used a sine wave generator to provide a moving number. I varied the frequency of frames sent by CANalyzer in order to control bus load.

I was able to post process the CANalyzer log to get an idea of the gateway performance: (all 500kBaud)
55.25% Busload - CAN0 Rx, CAN1 Tx 0.07% dropped,   CAN1 Rx, CAN0 Tx 0.10% dropped
69.0%  Busload - CAN0 Rx, CAN1 Tx 0.04% dropped,   CAN1 Rx, CAN0 Tx 0.06% dropped
91.5%  Busload - CAN0 Rx, CAN1 Tx 0.61% dropped,   CAN1 Rx, CAN0 Tx 2.61% dropped

This is pretty good, a typical vehicle bus would be less than 50% load at 500kBaud

To improve on this, I can think of two things:
1) CAN mailboxes - how are these accessed individually? Does CAN.get_rx_buff() get the last received frame? Is there any way to get all frames from all mailboxes, then clear all mailboxes?
2) Event based code - Is there anyway to set up the code to trigger functions on receiving a new frame?


Code:
/*
V1.0 - 08-Feb-2014 - First version. Total Pass-through CAN gateway


V1.0 Test results as follows:
55.25% Busload - CAN0 Rx, CAN1 Tx 0.07% dropped, CAN1 Rx, CAN0 Tx 0.10% dropped
69.0%  Busload - CAN0 Rx, CAN1 Tx 0.04% dropped, CAN1 Rx, CAN0 Tx 0.06% dropped
91.5%  Busload - CAN0 Rx, CAN1 Tx 0.61% dropped, CAN1 Rx, CAN0 Tx 2.61% dropped //see code ordering to explain
*/

// Required libraries
#include "variant.h"
#include <due_can.h>
CAN_FRAME frameRx0, frameRx1; //Gateway frames received by CAN0 and CAN1
boolean extdCAN = false;

void setup() {

  // start serial port at 9600 bps for debug
  Serial.begin(9600);

  // Verify CAN0 and CAN1 initialization, set baudrate below:
  if (CAN.init(CAN_BPS_500K)) {
    Serial.println("CAN ONE initialization (sync) OK");
  }
  else {
    Serial.println("CAN ONE initialization (sync) ERROR");
  }

  if (CAN2.init(CAN_BPS_500K)) {
    Serial.println("CAN TWO initialization (sync) OK");
  }
  else {
    Serial.println("CAN TWO initialization (sync) ERROR");
  }

//Copied from echo example
  //By default there are 7 mailboxes for each device that are RX boxes
  //This sets each mailbox to have an open filter that will accept all frames
  int filter;
  for (int filter = 0; filter < 7; filter++) {
    CAN.setRXFilter(filter, 0, 0, extdCAN);
    CAN2.setRXFilter(filter, 0, 0, extdCAN);
  }
  LoopFuncn();
}

// Gateway frames between CAN 0 and CAN 1
static void LoopFuncn(void)
{
  Serial.print("Begin gateway loop");
  Serial.println();

  while (1 == 1) {
    CAN_FRAME frameRx0;
    CAN_FRAME frameRx1;

    if (CAN.rx_avail()) {
      CAN.get_rx_buff(frameRx0);
      CAN2.sendFrame(frameRx0);
    }
    if (CAN2.rx_avail()) {
      CAN2.get_rx_buff(frameRx1);
      CAN.sendFrame(frameRx1);
    }
  }
}

void loop()
{
}

Logged

Venezuela
Offline Offline
God Member
*****
Karma: 17
Posts: 522
Ground, ground, always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Mark and thanks for your contribution with the gateway.  Looks promising as a base for future applications.
Are you using the CAN analyzer from Microchip or  ADFweb? It would be great also if you show us pictures of your DUE and transceiver with the analyzer.

Regards!
Palliser
Logged

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

Hi Palliser,
Canalyzer is a Vector product. I'm afraid I was borrowing the Canalyser hardware so can't take any pics now.

Has anyone got any tips on either of my two questions?

Quote
To improve on this, I can think of two things:
1) CAN mailboxes - how are these accessed individually? Does CAN.get_rx_buff() get the last received frame? Is there any way to get all frames from all mailboxes, then clear all mailboxes?
2) Event based code - Is there anyway to set up the code to trigger functions on receiving a new frame?
Logged

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

Sorry Mark, I should have answered those questions before.

1. CAN.get_rx_buff() grabs the first canbus frame in the receive buffer. The receive buffer is filled as frames come in to the RX mailboxes. There is currently no way to easily figure out which mailbox the frame came from.  The mailboxes are automatically cleared as soon as their frame is placed into the receive buffer. If a frame is being dropped then one of these things happened: all mailboxes that could accept the given frame were still full and the frame could not be received or the software did something dumb and lost the frame. The first possibility shouldn't actually drop the frame because canbus resends until somebody acks the frame. So, the only way it would be "dropped" at the Due is if the Due could not accept it but something else on the bus did set acknowledge on the frame. The second possibility could be a race condition in the interrupt code. It might be harder to find.
2. Not currently. The frames are automatically stuck into the receive buffer for you to check later on. There isn't a way to register a callback right now.

I have a kvaser leaf light so I might be able to do some testing to see if I can get the Due to drop frames. I know it does sometimes because I've tried to capture a firmware update between an ECU programmer and a motor controller and the Due could not keep up with the traffic. The Kvaser leaf does.
Logged

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

Hello,

can I use SN65HVD230 based can boards on arduino nano/pro micro?
Logged

Pages: 1 ... 21 22 [23] 24 25 ... 29   Go Up
Jump to: