Go Down

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

Transistorfips

Don't you have a schematic of the board you want to connect to?
Usually to connect to the CAN Transceivers is pretty straightforward. Maybe even they are Pin compatible to others too, so simply watch the footprints and follow the lines. Some are high-speed, some aren't. The best expierince I made was with TI's SN65 series which are avavilable for 5V, too. They can be used for both speed ranges. The High-Speed TJA1050 have a strange behaviour when testing with a multimeter, mine lost the signals after some usec and reacted like a monoflop.

jspobuk

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!
Pacific Electro-Mechanical Inc. - Honolulu -

Collin80

Well, I can't seem to find a way to do that either. But, you can do it at my repo: https://github.com/collin80/due_can

jspobuk

Thanks! that's what I was looking for.  Boy that was getting frustrating. :)
Pacific Electro-Mechanical Inc. - Honolulu -

jspobuk

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
Pacific Electro-Mechanical Inc. - Honolulu -

Graynomad

Maybe sn65hvd234.c should have a CPP extension to invoke the C++ parser/compiler/whatever

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

jspobuk

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!
Pacific Electro-Mechanical Inc. - Honolulu -

jspobuk

#232
Jul 03, 2013, 03:42 am Last Edit: Jul 03, 2013, 03:44 am by jspobuk Reason: 1
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!
Pacific Electro-Mechanical Inc. - Honolulu -

Graynomad

To test I would forget about the UI stuff and just send a hard-coded value. Then test the UI by itself and finally put them together.

Where are CAN and CAN2 defined? Are they created in the library?

_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Collin80

Your code looks suspiciously like one of the included examples. I don't see any obvious changes so I'm going to assume you're basically trying to run one of the examples. The most obvious reasons it might not be working:

1. Have you hooked the high and low lines together for the two can outputs? CANH1 to CAN2H, CAN1L to CAN2L? The tests assume you've done this.
2. It is possible that you don't have the proper pins specified. In due_can.h you'll find these defines:
#define CAN0_RS  61
#define CAN0_EN  62
#define CAN1_RS  63
#define CAN1_EN  64

They should match your board. You could hardwire your canbus shield to always be enabled and handle its own RS or you can set these defines and the library will do it.
3. Maybe the canbus shield doesn't work?

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.

newhobby

Is there such a thing as a CAN I/O expander chips?
One that would work similar to I2C I/O expanders?

Graynomad

Not AFAIK, if you're keen you could DIY one by using an LPC11C24 processor.

_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Transistorfips

>Is there such a thing as a CAN I/O expander chips?
Microchip MCP2502 CAN I/O Expander Family

http://ww1.microchip.com/downloads/en/devicedoc/21664d.pdf



Hope this helps,

Joachim

Graynomad

Ooo nice Joachim, I didn't know about them. Thanks.

_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com

newhobby


>Is there such a thing as a CAN I/O expander chips?
Microchip MCP2502 CAN I/O Expander Family

http://ww1.microchip.com/downloads/en/devicedoc/21664d.pdf



Hope this helps,

Joachim

Have you used them yet?
I heard it's a pain to program them.
It seems to be a one shot deal and the dev kit has some issues burning it and you end up with bricked chips.
Just wanted to have anyone else's experience with them.

Go Up