Show Posts
Pages: [1] 2
1  Products / Arduino Due / Re: Building a CAN API for Arduino DUE on: March 06, 2014, 08:21:16 pm
Finally finished my shield.  The through holes are to give access to the header pins in the middle of the board.  I think the next version will just have the pins go through.  The header sockets were a little annoying to solder.  Solder paste does amazing things with surface mount chips.  No more frustrating solder joint problems.   Now just waiting for the engine to arrive.  smiley-grin

2  Products / Arduino Due / Re: Building a CAN API for Arduino DUE on: January 28, 2014, 06:37:54 pm
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!
3  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: July 29, 2013, 05:34:29 pm
So just an update on the J1939 endeavor.  I was able to find several parameters and PGN's to test.  However, most of them are just to read information not necessarily change throttle speed or even send stop/start signals.  In the picture you can see the Eng. Temp and Hours as N/A and 0.0 respectively.  I was able to send fake data on the bus and have the Dyna Gen pick it up and display it.  Pretty much made my day.

All in all this due is pretty awesome.  Thanks again to all those who worked on putting together the library! Now if only SAE and manufacturers would give access to all the PGN's and detailed descriptions of what each block of data does.  I could do a lot more.  But I'm just glad it worked.  So that's the scoops, and the next step is actually using the Due in a real application.

4  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: July 29, 2013, 12:34:43 pm
Hey Rich,

Check out Replies 229-231 also.  I was getting a bunch of errors too at first.
5  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: July 26, 2013, 04:24:47 pm
So I figured out my problem.  I needed to put a
CAN.global_send_transfer_cmd(CAN_TCR_MB0);

instead of
CAN.mailbox_send_transfer_cmd(0);

Success! Now I can actually try to do something with this.  I'm going to try to send some info to my DynaGen GSC 400.  If anyone has any knowledge of doing such things hit me up, otherwise I'll keep ya'll posted.   
6  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: July 25, 2013, 06:50:29 pm
Yes, I believe J1939 is a higher level than just the signals, but it does utilize the extended id.  I guess what I am trying to do first is just get the raw data, even though I might not know exactly what it means.  The only CAN thing I have is a dynaGen GSC 400.  There is a J1939 plug, and the manual is not very helpful about... well... anything.  Right now I am just trying to get my arduino to send extended id messages to itself.  So I tweaked the first example.  Here is my code:

Code:
// Required libraries
#include "variant.h"
#include <due_can.h>
#include <sn65hvd234.h>

#define TEST1_CAN_COMM_MB_IDX    0
#define TEST1_CAN_TRANSFER_ID    0xFEEE00
#define TEST1_CAN0_TX_PRIO       0
#define CAN_MSG_DUMMY_DATA       0x55AAAA55

// CAN frame max data length
#define MAX_CAN_FRAME_DATA_LEN   8

// Message variable to be send
uint32_t CAN_MSG_1 = 0;

void setup()
{
  // start serial port at 9600 bps:
  Serial.begin(9600);
  Serial.println("Type CAN message to send");
  while (Serial.available() == 0);
}
void loop(){

  while (Serial.available() > 0) {
    CAN_MSG_1 = Serial.parseInt();
    if (Serial.read() == '\n') {
      Serial.print("Sent value= ");
      Serial.println(CAN_MSG_1);
    }
  }
 
  CAN.reset_all_mailbox();
  CAN2.reset_all_mailbox();

  // Initialize CAN0 and CAN1, baudrate is 1Mb/s
  CAN.init(SystemCoreClock, CAN_BPS_1000K);
  CAN2.init(SystemCoreClock, CAN_BPS_1000K);

  // Initialize CAN1 mailbox 0 as receiver, frame ID is 0x07
  CAN2.mailbox_init(0);
  CAN2.mailbox_set_mode(0, CAN_MB_RX_MODE);
  CAN2.mailbox_set_accept_mask(0, 0, true);
  CAN2.mailbox_set_id(0, 0, true);

  // Initialize CAN0 mailbox 0 as transmitter, transmit priority is 15
  CAN.mailbox_init(0);
  CAN.mailbox_set_mode(0, CAN_MB_TX_MODE);
  CAN.mailbox_set_priority(0, TEST1_CAN0_TX_PRIO);
  CAN.mailbox_set_accept_mask(0, 0, true);
  // Prepare transmit ID, data and data length in CAN0 mailbox 0
  CAN.mailbox_set_id(0, TEST1_CAN_TRANSFER_ID, true);
  CAN.mailbox_set_datal(0, CAN_MSG_1);
  //CAN.mailbox_set_datah(0, CAN_MSG_DUMMY_DATA);
  CAN.mailbox_set_datalen(0, MAX_CAN_FRAME_DATA_LEN);

  // Send out the information in the mailbox
  CAN.mailbox_send_transfer_cmd(0);

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

  }

  RX_CAN_FRAME incoming;
  // Read the received data from CAN1 mailbox 0
  CAN2.mailbox_read(0, &incoming);
  Serial.println("CAN message received= ");
  Serial.print("ID:");
  Serial.println(incoming.id);
  Serial.print("FID:");
  Serial.println(incoming.fid);
  Serial.print("RTR:");
  Serial.println(incoming.rtr);
  Serial.print("IDE:");
  Serial.println(incoming.ide);
  Serial.print("DLC:");
  Serial.println(incoming.dlc);
  Serial.print("DATA:");
  Serial.print(incoming.data[0]);
  Serial.print(incoming.data[1]);
  Serial.print(incoming.data[2]);
  Serial.print(incoming.data[3]);
  Serial.print(incoming.data[4]);
  Serial.print(incoming.data[5]);
  Serial.print(incoming.data[6]);
  Serial.println(incoming.data[7]);
 
  // Disable CAN0 Controller
  CAN.disable();

  // Disable CAN1 Controller
  CAN2.disable();

  Serial.print("End of test");

  while (1) {
  }
}

and my output on the serial monitor below.  Notice the Data is all zeroes.  This the case no matter what i put in.  Any ideas of why I can't get the data through?

Thanks!

7  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: July 24, 2013, 04:37:31 pm
Thanks Palliser,

I didn't have newline mode on, which caused the "Sent Value" to not show up.  And I have at least one bad connection which is what kept the while loop going. (i am starting to dislike surface mount chips).  After I finish with these simple connection issues I want to be able to communicate J1939.  Anyone else know about J1939?  I want to be able to read and maybe write to diesel engines that are J1939 compatible. However, its pretty murky waters to me right now.  If anyone else is also doing stuff, any help is greatly appreciated.

Thanks!
8  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: July 22, 2013, 08:46:48 pm
Yes, actually I was just re reading that.  this is what i have in my variant.h

/*
 * Complementary CAN pins
 */
static const uint8_t CAN1RX = 88;
static const uint8_t CAN1TX = 89;

// CAN0
#define PINS_CAN0            (90u)
// CAN1
#define PINS_CAN1            (91u)

I believe that is correct, and my variant.cpp

// 88/89 - CANRX1/CANTX1 (same physical pin for 66/53)
  { PIOB, PIO_PB15A_CANRX1,     ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL,                  NO_ADC, NO_ADC, NOT_ON_PWM,  NOT_ON_TIMER }, // CANRX1
  { PIOB, PIO_PB14A_CANTX1,     ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL,                  NO_ADC, NO_ADC, NOT_ON_PWM,  NOT_ON_TIMER }, // CANTX1

  // 90 .. 91 - "All CAN pins" masks
  // 90 - CAN0 all pins
  { PIOA, PIO_PA1A_CANRX0|PIO_PA0A_CANTX0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC,  NO_ADC, NOT_ON_PWM,  NOT_ON_TIMER },
  // 91 - CAN1 all pins
  { PIOB, PIO_PB15A_CANRX1|PIO_PB14A_CANTX1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM,  NOT_ON_TIMER },


which i also believe is correct.  I tried all the examples, but to no avail.  If i comment out the while loop in the example one that i alluded to above, it prints out 00000000.

9  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: July 22, 2013, 04:00:49 pm
So I got the signal to go all the way to the CANRX in to DAC0.  But the serial monitor still does nothing when I press send.  I can't get past the line:

while (!(CAN2.mailbox_get_status(0) & CAN_MSR_MRDY)) {
  }


Any help is greatly appreciated.
Thanks!
10  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: July 19, 2013, 04:35:09 pm
Hello, so i found time to go back to my arduino due.  Still same problem as before.  I did hook up an oscilloscope as you suggested Collin80 in a previous post:



It can be hard to say. If you have an oscilloscope or logic analyzer you could try scoping the H and L pins at the output of the transceivers or scope the CANTX and CANRX pins at the Due to see if any form of signal is getting out. What you'd expect to see is a momentary signal as the frame is transmitted from one canbus device to the other. If there is as problem but it is trying to send you should see the frame very rapidly resending forever. This is pretty easy to see on a scope. If you are getting constant resends then either you aren't looped back, the signal is corrupt, or the receiver is not responding.

I hooked up just the due CANTX and GND. When i start the serial monitor I get a solid 3.2 V.  When i press "Send", I see the following screen.  Is that the resending forever you were mentioning?

Thanks!
11  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: July 02, 2013, 08:42:06 pm
When I press "Send" in the following screen, I get nothing.  The input box goes blank and the message is the same.  Just a TX blinking, but that's it.  Any ideas as to what is wrong? Here is my code

// Arduino Due - CAN Sample 1
// Brief CAN example for Arduino Due
// Test the transmission from CAN0 Mailbox 0 to CAN1 Mailbox 0
// By Thibaut Viard/Wilfredo Molina/Collin Kidder 2013

// Required libraries
#include "variant.h"
#include <due_can.h>

#define TEST1_CAN_COMM_MB_IDX    0
#define TEST1_CAN_TRANSFER_ID    0x07
#define TEST1_CAN0_TX_PRIO       15
#define CAN_MSG_DUMMY_DATA       0x55AAAA55

// CAN frame max data length
#define MAX_CAN_FRAME_DATA_LEN   8

// Message variable to be send
uint32_t CAN_MSG_1 = 0;

void setup()
{
  // start serial port at 9600 bps:
  Serial.begin(9600);
  Serial.println("Type CAN message to send");
  while (Serial.available() == 0);
}
void loop(){

  while (Serial.available() > 0) {
    CAN_MSG_1 = Serial.parseInt();
    if (Serial.read() == '\n') {
      Serial.print("Sent value= ");
      Serial.println(CAN_MSG_1);
    }
  }

  // Initialize CAN0 and CAN1, baudrate is 1Mb/s
  CAN.init(SystemCoreClock, CAN_BPS_1000K);
  CAN2.init(SystemCoreClock, CAN_BPS_1000K);

  // Initialize CAN1 mailbox 0 as receiver, frame ID is 0x07
  CAN2.mailbox_init(0);
  CAN2.mailbox_set_mode(0, CAN_MB_RX_MODE);
  CAN2.mailbox_set_accept_mask(0, 0x7FF, false);
  CAN2.mailbox_set_id(0, TEST1_CAN_TRANSFER_ID, false);

  // Initialize CAN0 mailbox 0 as transmitter, transmit priority is 15
  CAN.mailbox_init(0);
  CAN.mailbox_set_mode(0, CAN_MB_TX_MODE);
  CAN.mailbox_set_priority(0, TEST1_CAN0_TX_PRIO);
  CAN.mailbox_set_accept_mask(0, 0, false);
  // Prepare transmit ID, data and data length in CAN0 mailbox 0
  CAN.mailbox_set_id(0, TEST1_CAN_TRANSFER_ID, false);
  CAN.mailbox_set_datal(0, CAN_MSG_1);
  CAN.mailbox_set_datah(0, CAN_MSG_DUMMY_DATA);
  CAN.mailbox_set_datalen(0, MAX_CAN_FRAME_DATA_LEN);

  // Send out the information in the mailbox
  CAN.global_send_transfer_cmd(CAN_TCR_MB0);

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

  RX_CAN_FRAME incoming;
  // Read the received data from CAN1 mailbox 0
  CAN2.mailbox_read(0, &incoming);
  Serial.print("CAN message received= ");
  Serial.print(incoming.data[0]);
  Serial.print(incoming.data[1]);
  Serial.print(incoming.data[2]);
  Serial.print(incoming.data[3]);
  Serial.print(incoming.data[4]);
  Serial.print(incoming.data[5]);
  Serial.print(incoming.data[6]);
  Serial.println(incoming.data[7]);
  
  // Disable CAN0 Controller
  CAN.disable();

  // Disable CAN1 Controller
  CAN2.disable();

  Serial.print("End of test");

  while (1) {
  }
}


Thanks!
12  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: July 02, 2013, 08:37:03 pm
Oh duh, I see, there was a random sn65hvd234.c file.... so i just deleted it and it works fine.  There already was a sn65hvd234.cpp file. 

Thanks!
13  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: July 02, 2013, 08:16:18 pm
Why am I getting these errors?

In file included from C:\Users\johnp.PEM\Documents\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\libraries\CAN\sn65hvd234.c:26:
C:\Users\johnp.PEM\Documents\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\libraries\CAN\/sn65hvd234.h:30: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'SSN65HVD234'
C:\Users\johnp.PEM\Documents\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\libraries\CAN\sn65hvd234.c:37: error: expected ')' before '*' token
C:\Users\johnp.PEM\Documents\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\libraries\CAN\sn65hvd234.c:54: error: expected ')' before '*' token
C:\Users\johnp.PEM\Documents\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\libraries\CAN\sn65hvd234.c:72: error: expected ')' before '*' token
C:\Users\johnp.PEM\Documents\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\libraries\CAN\sn65hvd234.c:88: error: expected ')' before '*' token
C:\Users\johnp.PEM\Documents\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\libraries\CAN\sn65hvd234.c:103: error: expected ')' before '*' token
C:\Users\johnp.PEM\Documents\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\libraries\CAN\sn65hvd234.c:118: error: expected ')' before '*' token
C:\Users\johnp.PEM\Documents\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\libraries\CAN\sn65hvd234.c:135: error: expected ')' before '*' token
14  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: July 02, 2013, 07:41:17 pm
Thanks! that's what I was looking for.  Boy that was getting frustrating. smiley
15  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: July 02, 2013, 06:39:17 pm
Hello, sorry to ask a simple question, but I am trying to re-download the files again after reinstalling windows.  I don't see anywhere on this page that I can download the header and .cpp files and examples and such. 
https://github.com/arduino/Arduino/tree/can/hardware/arduino/sam/libraries/CAN#due_can
thanks!
Pages: [1] 2