Coder Social home page Coder Social logo

due_can's People

Contributors

adamvoss avatar collin80 avatar csbluechip avatar thomasonw avatar ttlappalainen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

due_can's Issues

Can't send CAN frame without declaring DLC

Hello collin,

Everytime I want to send frame without setting DLC frame on CAN bus is not correct. If I want to send correct frame I have to set DLC by CANFRAME.length .

So example CAN_SendingTest will not work correctly unless you previously define DLC.

Regards

Library Compatibility with CanOPEN

Hello, I'd like to use your library in a school project on a variable speed drive(SEVCON Gen4) which is communicating with the CanOPEN protocol. Apparently, this protocol is much more elaborated than the
the basic CAN one, and I wanted to know if you're library was designed to fit this particularity or not. Currently I'm trying to upgrade it by looking into another project which use an arduino and request some information from the SEVCON Gen4.
If you want to take a look, here it is :
https://github.com/SuperTango/TangoLogger

Various issues when re-using can0/can1

Hi, firstly, thanks for this library!

Brief TLDR into whats happening here for this odd use case. Essentially, im writing a J2534 driver for the Macchina M2 (Essentially an arduino Due with extra hardware), and am using the due_can library for interfacing with the CAN bus on ODB2 port.

The specification states that the device should terminate and re-use CAN Interfaces, So I wrote a custom wrapper class around your can0/can1 interfaces, a simplified version of the wrapper below:

#include "can_handler.h"
#include "pc_comm.h"

// Try to init CAN interface on one of the 2 avaliable built in interfaces
canbus_handler::canbus_handler(uint8_t id, uint32_t baud) {
    char buf[30] = {0x00};
    sprintf(buf, "CAN Speed: %lu bps", baud);
    PCCOMM::logToSerial(buf);
    switch(id) {
        case 0:
            PCCOMM::logToSerial("Setting up Can0");
            this->actLED = CAN0_LED;
            this->useCan1 = false;
            PCCOMM::logToSerial("Done");
            this->getIface().begin(baud);
            this->getIface().watchFor();
            PCCOMM::logToSerial("Done1");
            break;
        case 1:
            PCCOMM::logToSerial("Setting up Can1");
            this->actLED = CAN1_LED;
            this->useCan1 = true;
            PCCOMM::logToSerial("Done");
            this->getIface().begin(baud);
            this->getIface().watchFor();
            PCCOMM::logToSerial("Done1");
            break;
        default: // No more free CAN Interfaces! Alert the host driver
            PCCOMM::logToSerial("ERROR SETTING UP CAN INVALID ID");
            return;
    }
}

// Couldn't find a way to store references to can0 or can1 - Macchina freezes when
// attempting to access references to them??
// So do it this way instead
CANRaw canbus_handler::getIface() {
    return this->useCan1 ? Can0 : Can1;
}

// Set a filter on one of the Rx mailboxes
void canbus_handler::setFilter(uint8_t filterID, uint32_t canid, uint32_t mask, bool isExtended) {
    char buf[40] = {0x00};
    sprintf(buf, "Setting Rx Filters - MASK: 0x%04X, Filter: 0x%04X", mask, canid);
    PCCOMM::logToSerial(buf);
    for (int i = 0; i < 7; i++) {
        this->getIface().setRXFilter(filterID, canid, mask, isExtended);
    }
}

// Transmits a frame on the bus
void canbus_handler::transmit(CAN_FRAME f) {
    digitalWrite(this->actLED, LOW);
    char buf[100] = {0x00};
    sprintf(buf, "CAN Sending CAN Frame. ID: 0x%04X - DLC: %d", f.id, f.length);
    PCCOMM::logToSerial(buf);
    if (!this->getIface().sendFrame(f)) {
        PCCOMM::logToSerial("Error sending CAN Frame!");
    }
}
 // Attempts to read an avaliable frame from one of the mailboxes
bool canbus_handler::read(CAN_FRAME f) {
    if (this->getIface().available() > 0) {
        PCCOMM::logToSerial("CAN Frames avaliable");
        digitalWrite(this->actLED, LOW);
        this->getIface().read(f);
        return true;
    }
    return false;
}


void canbus_handler::reset() {
    PCCOMM::logToSerial("Resetting CAN Interface");
    //TODO Clear Tx and Rx buffers here, and put CAN To sleep
}

// nullptr implies they are not used yet
extern canbus_handler *h0 = nullptr; // First avaliable interface  (Use can0)
extern canbus_handler *h1 = nullptr; // Second avaliable interface (Use can1)

Bare in mind that these classes get disposed quite reguarly and a new one is created whenever the API asks for it.

With that in mind, I've observed the following issues:

  1. Attempting to reference can0/can1 as a reference will cause a hard lockup when calling any method on the can interfaces (hence now the use of the getIface function in my code)
  2. After a re-use of my class, transmitting no longer works! - I have a arduino with an mcp2515 module hooked up to the macchina attempting to read incomming can frames
  3. read() does not read anything for some reason?, again, this is only after a deletion and re-creation of my handler class.

Any help much appreciated with this! - You can find the full macchina code base here if it is of any use.

Confirm receiving

How can i undrestand that my data frame has been received by receiver device?is there any confirmation code ?

contact

Hi Collin, is there a way I can contact you directly? For business purpose...

Why does this work?

Hi collin80,
Great work! I'm using SavvyCan(OSX) with GVRET on a Togglebit due Shield with my own SWCan addition to look at the Chevy Spark EV. I'm capturing frames! Looking forward to more cool stuff in SavvyCan.

What I don't understand is how the can1 pin assignments work in variant.h:
CANRX = 68 and CANTX = 69 for can0 seem ok and match the due pins
CAN1RX = 88 and CAN1TX = 89 seem like they should be 66 and 53?

Thanks for your help. Is there a better place to post a question like this?

Problems with DLC=1

Hello,
I started a project with the due_can library. But I have some problems and want to ask for your help to solve them one after the other.

  1. My project is small at the moment and works well, if I send a 8 byte long frame inside the main loop by the sendFrame method. Trying to send another frame with a DLC (datalength) of 1 byte, only the ID and the data length code will transmitted. Changing the DLC to 2 two bytes of data are sended. Do anybody have an idea?
  2. I do not receive any frames. I initialized the library with Can0.begin(250000); ank check for frames by Can0.available() > 0 in a cycling task loop. Is it okay so far or is some initialisatin missing?

Thank's for you help
Michael

Due_can execute code in ram classe error

Hi,
I tested Due_can code in flash runnig ok.
now compile program for execute in RAM, cause error.

I tested IDE PIO and eclipse.

othes function with ISR ok, serial, TC2...

Problems " ", call classe CANRaw, and write register in m_pCan

see my function test:
can_classe error

if write register error,
Can0.init( CAN_BPS_500K);
Can0.watchFor();

thanks,
Carlos.

Communication problem between Arduinos

I need to make two Arduino boards communicate. I've written this code to send messages:

void setup() {
  etc..
  Can0.begin(CAN_BAUD_RATE);
  etc..
}

void loop() {
  CAN_FRAME canFrame;
  uint16_t varA, varB, varC;

  etc..

  canFrame.extended = false;
  canFrame.id = MY_ID;
  canFrame.length = 6;

  canFrame.data.byte[0] = (varA & 0xFF00) >> 8;
  canFrame.data.byte[1] = (varA & 0xFF);

  canFrame.data.byte[2] = (varB & 0xFF00) >> 8;
  canFrame.data.byte[3] = (varB & 0xFF);

  canFrame.data.byte[4] = (varC & 0xFF00) >> 8;
  canFrame.data.byte[5] = (varC & 0xFF);

CAN.sendFrame(canFrame);
}

I can read messages using a CAN-bus analyzer with correct data and timing.

To read messages I've written another program, loaded on another Arduino, connected to the first:

void setup() {
  etc..
  Can0.begin(CAN_BAUD_RATE);
  for (int i=0; i<7; i++) Can0.setRXFilter(i, 0, 0, false);
  etc..
}

void loop() {
  if (Can0.available()) {
    CAN_FRAME incomingCanFrame;
    Can0.read(incomingCanFrame);
    // Code to use message's data
  }
}

This Arduino can't read data, even if it is correctly sent by the first arduino and received by the CAN-bus analyzer.
The thing that most I can not understand is that if I copy the message received by the CAN-bus analyzer and I send it back, Arduino can receive it and it does everything it has to do.

Can you help me to solve this problem?

Data modification issues

I've got this working really well as a gateway using a DUE board and a home built shield using two MCP2562's. My problem is when I try to modify vertain bytes in a particular id, I get all of the bytes in every id modified.

I started with the example CAN_TrafficModifier but I can either get no modification or I get the correct modification but also the same bytes modified in every ID.

I've currently got an if statement set up to pick the address I want out. However, it doesn't seem to acknowledge the address.

Also, I don't think I'm understanding the watchFor or watchForRange at all. I ahve not been able to get them to work in any format.

Offending code attached. This one does nothing but it does gateway perfectly. Just no mods.

The commented lines are failed attempts

<
if (Can0.available() > 0) {
Can0.read(incoming);
if (incoming.id == 0x740) {
// incoming.id == 0x740;
incoming.data.bytes[1] *= 1.1;
incoming.data.bytes[3] *= 1.1;
incoming.data.bytes[5] *= 1.1;
incoming.data.bytes[7] *= 1.1;
Can1.sendFrame(incoming);
}
else {
// incoming.data.bytes[1] = incoming.data.bytes[1];
// incoming.data.bytes[3] = incoming.data.bytes[3];
// incoming.data.bytes[5] = incoming.data.bytes[5];
// incoming.data.bytes[7] = incoming.data.bytes[7];
Can1.sendFrame(incoming);
}
}

ACK bit should be 0?

I am trying to emulate some CAN frames on my due with my very limited C++ abilities, my background is more hardware oriented and I am very new to the due.
When I scope the CAN output of my due I see that the ACK bit is always 1 whereas on the frames I am trying to emulate the ACK bit is always 0 which I believe is correct. Is there a command in due_can to clear the ACK bit

How to use this library

Hello @collin80 ,

We are looking for using due_can library for our project, We have Arduino due and we are new to CAN protocol.
We need some clarity on how to use your library .

  1. Is there any hardware dependency ? (does it need seperate transceiver etc ?)
  2. Can OBD2 be directly connected to Due ? Are these compatible ?

Thanks in Advance

Quick data exchange

Hey collin,
I am trying to receive 4 standard CAN frames, which are sent by an ECU, and respond to them in time. The frames are sent in a cycle of 10 ms. I setup a mailbox for each frame (e.g. 0x110, 0x111, 0x112, 0x113) and tell the callback to respond with my own frames (e.g. 0x210, 0x211, 0x212, 0x213) but when I look at the CAN log I can see that my frames are to slow to be transmitted before I get the next frames form the ECU. Is the system too slow or am I doing something wrong?

Problem with buffer overflow

In
void CANRaw::sendFrame(CAN_FRAME& txFrame)

there is a test missing, if the buffer is allready full.

If the buffer gets full, all messages already in the buffer are lost.

There should be a return value, that the sketch can check, if the messages is stored.

Help with CAN

Good afternoon.
I'm doing a project with Arduino DUE to their due_can library. But I have a problem. The function Can1.available( ) does return a value of 0. I'm sure all the hardware and software are correct. If possible, I would like your help. Thank you very much.

Add time triggered frame sending

Add a mode where a given frame can be set up to be sent every X milliseconds and the firmware will automatically do this until told otherwise

Single Wire CAN functionality

I'm working with the EVTV CanDue 2.0 shield. Documentation has lead me to your repo but I think I might be missing something. I haven't been able to find any functionality in your source code that mentions "swcan" or "single wire" for transmitting or receiving messages. Did I miss a file? If not, do you have a suggestion for where to go next?

Failure to receive extended frames

Hi Collin,

I am experiencing a problem with receiving extended frames, I ran the CAN_ExtendedPingPong example on the GEVCU board and the seminal frame sent here:

  // Send out the first frame
  Can0.sendFrame(frame2);
  sentFrames++;

Is never received. I moved the counter to the top of the while and got this output (continuous):

S: 1 R: 0
S: 1 R: 0
S: 1 R: 0
S: 1 R: 0

This duplicates the experience I am having with the GEVCU software not receiving extended frames. I thought I was doing something wrong, but maybe not.

Extended frames are being sent with no problems.

current library in master fails to transmit

Testing the current master branch and it receives fine but fails to transmit using the following code:

int send_frame()
{
int r;
CAN_FRAME tx;
tx.id = 0x100;
tx.length = 4;
tx.extended = 0;
tx.data.byte[0] = 0x01;
tx.data.byte[1] = 0x02;
tx.data.byte[2] = 0x03;
tx.data.byte[3] = 0x04;
r = Can0.sendFrame(tx);
Serial.print("sent tx r = ");
Serial.print(r);
Serial.print("\n");
return r;
}

It returns true for 10 or so attempts then returns false and no frames make it to the bus. Also receive appears to start missing frames every time i attempt to transmit. I am using the CAN_TrafficSnooper example and just added this send_frame() function. I tried sending a couple different ways like on a 500ms SimpleTimer and just a 1 shot after receipt of a given frame for example. Before I start digging deeper and troubleshooting the library further I wanted to see if this is still a work in progress and is this already known behavior.

False zero id packets

Hello Collin,
I've been trying your library. First, let me say, it looks great, good work on that one.

I am however facing a strange issue. Sometimes after calling Can0.read(in), the id member of the structure is set to zero although I am quite sure the the ID is something like 0x5FE. This is a CANOpen node and an SDO response. Most of the times, the id is filled in correctly but sometimes, there is just zero. And no, it's not NMT signal or anything. I can read the rest of the packet and the content is OK, only the id is filled in incorrectly.

Any idea?

I don't use any filter I just read the packets like this:

if (can.available()){
	can.read(incoming);
	...
}

Also might be worth mentioning... I use 5V transciever, not 3.3V because I couln't get one anywhere. I have connected some resistors to make it 3.3V and it seems to work. This may not be relevant at all, I just thought you should know.

Thanks...

CAN received with wrong ID

Thank you for this package. I really appreciate it!

I am transmitting a message on the CAN bus with the ID 0xFF0400. I have a CAN monitor on the line and it confirms that the message is sent out with that ID, and the extended ID flag set to true.

However, when I receive the frame from due_can, the frame->id is 0xFC0000. That is to say, I don't receive the 0xFF0400 frame, but I do receive a 0xFC0000 which I am not sending and is not seen on the CAN bus monitor.

Any ideas why my CAN bus ID is changing?

crc

Hello, I send data from arduino and analyze it with CANanalyzer, but I'm missing crc_summ for decoding. Does it calculte crc for sending or not? Thanks.

Problem with CAN-Bus speeds

Hello Collin,
I'm having some problems using your library.
I'm trying to use your TrafficSnooper example but when I open the Can Interface with

Can0.begin(CAN_BPS_125K);

it doesn't work at all.
But when I use

Can0.beginAutoSpeed();

instead it detects the proper speed and works perfectly fine.
I am using a Can Transciever based on a TJA1042T/3 chip I've build myself and I doubt it's the source of the problem since it works without issues when I use the automatic speed detection.

Thanks in advance for your answer!

I'd like to use your library to make a canbus proprietary arbid decoder.

the idea is to use mode 1/22 to request live data from ecu then compare that to all live traffic to find matching bytes. I've got the basis wrote but am struggling to figure out if I should store frames in a buffer while comparing frames?
I used your library to write some glue-ware to connect two separate can bus systems together and now I need to decode proprietary ids to find the rest of the data I need to transfer.
how would you recommend comparing live data to a response from ecu?

Error in DUE_2CAN_Channel_TEST Sketch file

Hi,
I've just downloaded the Due_2CAN_Chyannel_Test sketch and uploaded to my arduino 2.

After file compilation, the following error appeared:

Arduino:1.8.4 (Windows 7), Scheda:"Arduino/Genuino Uno"

In file included from sketch\DueCANLayer.h:4:0,

             from sketch\DueCANLayer.cpp:4:

due_can.h:177: error: 'Can' does not name a type

Can* m_pCan ;

^

due_can.h:195: error: expected ')' before '*' token

 CANRaw( Can* pCan, uint32_t En);

            ^

exit status 1
'Can' does not name a type

Someone could help me, please?

I think that the problem is with the setting of the variable type for "Can".

There could be some other issue like that?

THank You in advance
Bye

Stops to receive after send

Hi Colin.
I have an odd issue with the library. I did basically modify the example: Can_SendingTest
I have removed all CAN1 related information and i have added the function to print the output message.
The issue is when it sends data 2 times it suddenly stops receiving data in.

The set up is the following Arduino UNO with mcp2515 sending some data.
Then Arduino Due gets it via SN65HVD230 module.

The first thing is the receive buffer seems to not be cleared after read. so i get rapidly same thing that got in once.
Second thing is that after a few sends the receiving stops stops.
Last problem i have is that the sent data can't be read on my Uno it is like it was never sent out.

Here is the modified sketch :
#include "variant.h"
#include <due_can.h>

//Leave defined if you use native port, comment if using programming port
//#define Serial SerialUSB

void setup()
{

Serial.begin(115200);

// Initialize CAN0 and CAN1, Set the proper baud rates here
Can0.begin(CAN_BPS_500K);

Can0.watchFor();
}

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("0x");
if(frame.data.bytes[count]<10)
Serial.print("0");
Serial.print(frame.data.bytes[count], HEX);
Serial.print(" ");
}
Serial.print("\r\n");
}

void sendData()
{
CAN_FRAME outgoing;
outgoing.id = 0x688;
outgoing.extended = false;
outgoing.priority = 4; //0-15 lower is higher priority
outgoing.length = 8;
outgoing.data.byte[0] = 0x55;
outgoing.data.byte[1] = 0x11;
outgoing.data.byte[2] = 0xDD;
outgoing.data.byte[3] = 0x33;
outgoing.data.byte[4] = 0x44;
outgoing.data.byte[5] = 0x55;
outgoing.data.byte[6] = 0x66;
outgoing.data.byte[7] = 0x77;

Can0.sendFrame(outgoing);

printFrame(outgoing);
}

void loop(){
CAN_FRAME incoming;
static unsigned long lastTime = 0;

if (Can0.available() > 0) {
Can0.read(incoming);
printFrame(incoming);
}

if ((millis() - lastTime) > 1000)
{
lastTime = millis();
sendData();
}
}

Output frame from Arduino Due CAN bus is not same as expected

I am trying to transmit data through CAN bas using Arduino Due. I have used following code :

#include <due_can.h>; //This is an include statement

void setup() {
CAN_FRAME myFrame;
Can0.begin(CAN_BPS_250K);
}

void loop() {
// put your main code here, to run repeatedly:
CAN_FRAME myFrame;
myFrame.id= 0x25A; // EID if ide set, SID otherwise
myFrame.rtr=0; // Remote Transmission Request
//myFrame.priority; // Priority but only important for TX frames and then only for special uses.
myFrame.extended=0; // Extended ID flag
myFrame.length=1; // Number of data bytes
myFrame.data.bytes[0] = 128;
Can0.sendFrame(myFrame);
}

The output observed from the CAN bus is as below.
image

Upto R0 output is as expected. Thereafter output signal is not as expected. Please help.

Bus speed at 500 K

I have no issues running my code at 125 K and all works great . The minute I run at 500 K my truck crashes .
I have all terminations done correctly and have termination resistors in place .

I was wondering if I had to play with TQ and sample points .
My truck seems to like 75 sample rate at 125 K speed .

It works perfect at 125K but i know the timing gets more critical the faster the bus speed .

Any help would be amazing .
Thanks

Here is my basic code .

//Reads all traffic on CAN0 and forwards it to CAN1 and modifies cluster frame first.
//Code based on samples provided by Thibaut Viard/Wilfredo Molina/Collin Kidder
//------------------------------------------------------------------------------------------------

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

//Leave defined if you use native port, comment if using programming port
//This sketch could provide a lot of traffic so it might be best to use the
//native port
#define Serial SerialUSB

void printFrame(CAN_FRAME *frame, int filter) {
Serial.print("Fltr: ");
if (filter > -1) Serial.print(filter);
else Serial.print("???");
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");
}

void gotFrame0(CAN_FRAME *frame)
{
//printFrame(frame, 1); //uncomment line to print frames that are going out
Can1.sendFrame(*frame);
}

void gotFrameCluster(CAN_FRAME *frame) //cluster
{
frame->data.byte[1]=0x08;
frame->data.byte[6]=0x01;
//printFrame(frame, 2); //uncomment line to print frames that are going out
Can1.sendFrame(*frame);
}

void gotFrame1(CAN_FRAME *frame)
{
//printFrame(frame, -1); //uncomment line to print frames that are going out
Can0.sendFrame(*frame);
}

void setup()
{

//Serial.begin(250000); //Uncomment for serial

// Initialize CAN0, Set the proper baud rates here
Can0.begin(CAN_BPS_500K);
// Initialize CAN1, Set the proper baud rates here
Can1.begin(CAN_BPS_500K);

//By default there are 7 RX mailboxes for each device - Standard frames
//Can0 Filters
Can0.setRXFilter(0, 0x372, 0x7FF, false); //Cluster

//Can1 Filters
Can1.setRXFilter(0, 0, false); //catch all mailbox - no mailbox ID specified

//now register all of the callback functions.
Can0.setCallback(0, gotFrameCluster);

//this function will get a callback for any mailbox that doesn't have a registered callback
Can0.setGeneralCallback(gotFrame0);
Can1.setGeneralCallback(gotFrame1);
}

void loop(){ //note the empty loop here. All work is done via callback as frames come in - no need to poll for them
}

Issue with due can library and DUE

Hi,
I'm testing canbus using DUE and transceiver sn65hvd230 shield.
I have a canbus network as follows;

CANBUS NETWORK:

  • 2 arduinos NANO with MCP2515
  • 1 arduino MEGA 2560 with MCP2515
  • 1 arduino DUE with sn65hvd230

Network is property terminated with 120 ohm resistors.
Each arduino sends at least two canbus messages, each with 8 bytes and its own ID;
Each arduino reads canbus and shows at serial, messages received.

BEHAVIOR:

All arduinos (NANO/MEGA) read all messages on canbus network... BUT DUE only one message... Seems other messages are ignored. But there isn't can filter configured.
DUE sends one message, but none of arduinos can receive...

I think sketch from NANO and MEGA doesn't matter because they are working very well...

On DUE: (Simplified sketch)
#include <variant.h>
#include <due_can.h>

SETUP
void setup()
{
Serial.begin(115200);
Can0.begin(CAN_BPS_250K);
Can0.watchFor();
}

void CANBUSTX()
{
CAN_FRAME CANBus_TX;
CANBus_TX.id = 0x090;
CANBus_TX.extended = false;
CANBus_TX.priority = 4;
CANBus_TX.length = 8;
CANBus_TX.rtr = 0;
CANBus_TX.data.byte[0] = 24;
CANBus_TX.data.byte[1] = 33;
CANBus_TX.data.byte[2] = 23;
CANBus_TX.data.byte[3] = 11;
CANBus_TX.data.byte[4] = 0;
CANBus_TX.data.byte[5] = 0;
CANBus_TX.data.byte[6] = 0;
CANBus_TX.data.byte[7] = 10;
Can0.sendFrame(CANBus_TX);
}

void CANBUSRX()
{
CAN_FRAME CANBus_RX;
if (Can0.available() > 0)
{
Can0.read(CANBus_RX);
Serial.print(F(">>>>>>>>>> Received CANBUS!!! "));
Serial.println(CANBus_RX.id,HEX);
}
}

LOOP:
void loop()
{
CANBUSTX();
CANBUSRX();
}

Of course i had simplified the sketch. Arduinos are sending not only constant values, but values read from sensors (byte format).

What can be wrong? With MCP2515 on arduinos and sn65hvd230 on ESP32 (example), they works very well.

Thanks for any help
Regards
Alex

RTR is not returned

https://forum.macchina.cc/t/can-library-does-not-return-rtr-solved/610

I notice due_can declares a variable in which to hold RTR, but that variable is never populated.
This bug exists in (as far as I can tell) every version of the library.

I have patched the (6 month old) version of the library (as linked from the M2 Git repo), but it is not obvious how to properly fork/pullRq/submit the patch
...I have not yet patched the write function but...
...If you want to know if a CAN device is requesting data, here's the patch:

  • Open C:\Users\YourUserName\AppData\Local\Arduino15\packages\macchina\hardware\sam\0.2.1\libraries\due_can\due_can.cpp
    ...If you're not using Windows - you're just going to have to go hunting for that file - sorry.

  • Search for the string "fid" [Family ID] ...there's only one occurence of this string in this file:
    rxframe->fid = m_pCan->CAN_MB[uc_index].CAN_MFID;

  • Just after/before/near ^that^, line add this line:
    rxframe->rtr = (m_pCan->CAN_MB[uc_index].CAN_MSR & CAN_MSR_MRTR) ? 1 : 0 ;

  • That's it, you can now identify Remote Transmit Request packets with something like:
    if (frame.rtr) rtrHandler(frame) ;

  • If you like diff files, enjoy this:

--- C:\original\due_can.cpp	2018-03-03 15:35:22.000000000 -0000
+++ C:\rtr_fix\due_can.cpp	2018-03-03 15:38:02.000000000 -0000
@@ -1026,12 +1026,13 @@
 		rxframe->id = (ul_id  >> CAN_MID_MIDvA_Pos) & 0x7ffu;
 		rxframe->extended = false;
 	}
 	rxframe->fid = m_pCan->CAN_MB[uc_index].CAN_MFID;
 	rxframe->length = (ul_status & CAN_MSR_MDLC_Msk) >> CAN_MSR_MDLC_Pos;
     rxframe->time   = (ul_status & CAN_MSR_MTIMESTAMP_Msk);
+    rxframe->rtr    = (m_pCan->CAN_MB[uc_index].CAN_MSR & CAN_MSR_MRTR) ? 1 : 0;
     ul_datal = m_pCan->CAN_MB[uc_index].CAN_MDL;
 	ul_datah = m_pCan->CAN_MB[uc_index].CAN_MDH;
 
 	rxframe->data.high = ul_datah;
 	rxframe->data.low = ul_datal;```

RTR bit support confusion

I just wanted to get some clarification on the support for RTR bits in this library since in this open issue there's mention that the library doesn't support RTR bits and setting the existing flag does nothing. However, at the same time there is this merged pull request that seemingly added support for reading and writing RTR bits.

From my own use/testing with this library, it feels like the implementation/interpretation of the RTR bit exists but isn't quite right since the receiving CAN_FRAME object stores an RTR bit and increments the value with each frame received until it reaches 0x1F where it overflows back to 0.

Any insight/clarification on this issue would be greatly appreciated. Below is a snippet of my output from printing the received frames:

image

master version does not work ok

Hi collin,
Thank you for your nice job. I download master version, it is not OK when I test the examples. Eg,
CAN_EchoTest , can1 receives wrong messages. Even when I remove the transceivers which connect can0 and can1, it can still receive messages.
So, I try the release version due_can-2.0.1, it works very well. I don't know the reason, and wonder why.
I use Due, programming port for test. Thanks.

Bluetooth obdII "buffer full" (SOLVED)

Thanks for your work before I start !
I am using CAN_TrafficModifier. I have a Can Logger replaying a recorded stream from a LEAF.
I am single stepping thru the messages. All works fine, incoming message is displayed correctly once.
Out going message is monitored by a bluetooth odbii device, connected to a galaxy tab. It connects and displays data mostly correctly. However each single message transmitted on Can0 is repeated multiple times on the Tablet connected on Can0 via the bluetooth device using the ATMA command. The tab finally displays BUFFER FULL. I presume the program is re-sending the message until the next message comes along or something. I only know enough to be dangerous and so far have not been able to figure out how to prevent this. I did look at the callback apps you have I thought that it might solve my problem but I have not been able to figure out how to get it to re-transmit the message from Can0 to Can1. I am trying to implement a man in the middle to figure out communication between the LEAF Charger(OBC) and the VCM/BMS to try and set up the charger as a stand alone charger. Not sure what the RX error is but figure I can sort that out by fixing this oroble. Help appreciated. Screen shout of output on tablet attached. The other possibility is this is a problem with the dongle not clearing it's buffer ?
terminal screenshot

can_common.h: No such file - Where can I find it ?

Hello,
I got the error
In file included from ...Arduino/libraries/due_can/due_can.h:23:24: fatal error: can_common.h: No such file or directory #include <can_common.h>
A Google nor Github Search found anything, where can I find that file ?

DUE_CAN using interrupts

Hello,

I'm looking for example of code using interrupt when CAN packet is recieved.
I can not use main loop to check if data arrived.
Is possible to use your library with interrupt handling?

Thank you

Regards Skrenda

Transmitting causes too many interrupts

Problem can be solved by adding disable interrupt in due_can.cpp:

... for (uint8_t cnt = 0; cnt < 8; cnt++)
mailbox_set_databyte(mb, cnt, tx_frame_buff[tx_buffer_head].data[cnt]);
global_send_transfer_cmd((0x1u << mb));
tx_buffer_head = (tx_buffer_head + 1) % SIZE_TX_BUFFER;
} else {
disable_interrupt(0x01u << mb); //enable the TX interrupt for this box
}
break;
case 5: //producer - technically still a transmit buffer
break;...

twai_handle_tx_buffer_frame twai.c:183

Hello, I am using this library fork on Wemos D1 mini. On my simulator with some 50..60 messages per second it works fine. In my car, connected to the obd2 interface I obtain with certain frequency the following message after corruption crash:

assert failed: twai_handle_tx_buffer_frame twai.c:183 (p_twai_obj->tx_msg_count >= 0)
Backtrace: 0x40083841:0x3ffbf45c |<-CORRUPTED
ELF file SHA256: 1b576722c7d4efcc
Rebooting...

In the car there are some 250..260 rx callbacks per second.

As far as I coud read it looks like as there is a bug on Espressiv's TWAI. And as far as could understand it seems that the error appears due to high traffic.

Since I use Arduino IDE my possibilities of resolution are limited.

Is there any hint to help me out with this issue?

Many thanks in advance.

?Issue with transmitters?

I'm confused as to whether this is an issue, or my failure to understand...

https://github.com/collin80/due_can/blob/master/src/due_can.cpp#L1391
shows "consumer" grouped with "receiver"

...A few lines later
https://github.com/collin80/due_can/blob/master/src/due_can.cpp#L1430
shows "producer" separated from "transmitter"

The way I read it, "producers" can never send any data!?
Should the case 5 line be moved to pair up with the case 3 line?
...and thus 'enable' "producers"

Disable Interupt Pin on 2515.h

Hi i'm using due_can library, but when it comes to CAN1 MCP2515 the function of receiving can msgs not working, only if pull up the interupt pin and then live it floating.But also in this situation after a few second the esp32-wroom-32e is restarting continuously.In the other hand for sending Can msg over the CAN1 MCP2515 is working perfectly.Just for information CAN0 eps32 built in is working also perfect with new update code for espe E versions.

I will appreciate if you can help me.

watchFor()

Hi,
I use CAN_EchoTest.ino in exemple.
I try to use "Can0.watchFor();".
It does'nt work without id. (no interupt for the mailbox)
When i use "Can0.watchFor(0x007);" i recive my frame correctly.

I look in the due_can.cpp and i see :

int CANRaw::watchFor()
{
int retVal = setRXFilter(0, 0, false);
enable_interrupt(getMailboxIer(0));
setRXFilter(0, 0, true);
enable_interrupt(getMailboxIer(1));

return retVal;

}

I don't know if it's normal but i don't understand how it work.

Can0.available() return 0 all the time

In the example of CAN_SendingTest I just put some println and It seems that the function Can0.available() isn't working (return 0 all the time), the sending frames works (returning 1), and I don't have any idea why is available() not working...Is there some trick?? Are there some connections missed?

Support multiple listeners

A recent commit added native support for using a class method as a callback target with this library. However, only one such listening class can be registered. This neglects the very real possibility that the end user might have more than one class that must register to get messages. Support should be added to allow for multiple listeners. Some sane limit should be supported - perhaps 4 listeners. There is no real reason to support more than that. If a sketch needs more listeners it should be handling that itself.

Update library for CAN-FD?

Is the Arduino Due theoretically capable of supporting CAN FD? If so, would this library be able to be updated to support it? From the looks of it, CAN-FD is simply an extension that allows 64 data bytes per frame, rather than 8 data bytes. It looks to be compatible with existing CAN2.0 networks. If it is capable, I would be willing to help the programming/testing effort with a CAN-FD transceiver (maybe the MCP2562FD?).

How to use RTR with due_can library ?

Hi,

I'm working with your library and I will to send a RTR frame. In your library I found the CAN_FRAME struct definition, where I have found the rtr variable:

typedef struct {
uint32_t id;      // EID if ide set, SID otherwise
   uint32_t fid;     // family ID
   uint8_t rtr;      // Remote Transmission Request <-- THIS
   uint8_t priority; // Priority but only important for TX frames and then only for special uses.
   uint8_t extended; // Extended ID flag
   uint8_t length;      // Number of data bytes
   BytesUnion data;  // 64 bits - lots of ways to access it.
} CAN_FRAME;

I have tried to send a frame with this variable but nothing change. What's wrong ?

Sketch Code:

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

bool initDevices = false;

void setup() {
  Can0.begin(CAN_BPS_500K);
}

void loop() {
  CAN_FRAME output;

  if(!initDevices) { 
    output.id = 0x21;
    output.extended = false;
    output.length = 1;
    output.data.byte[0] = 0x05;
    CAN.sendFrame(output);
    
    initDevices = true;
  }

  output.id = 0x321;
  output.extended = false;
  output.rtr = 0x01;
  output.length = 0;
  CAN.sendFrame(output);

  delay(50);
}

Thank You in advance
Bye

P.S. Sorry for my English

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.