FlexCAN_T4 - FlexCAN for Teensy 4

Having troubel sending messages

@jmlima44 mine works like this:

Code:
#include <FlexCAN_T4.h>
CAN_message_t can_fwd_car;
FlexCAN_T4<CAN2, RX_SIZE_32, TX_SIZE_32> can_master;

void setup() {
  // put your setup code here, to run once:
  can_master.begin();
  can_master.setBaudRate(125000);
}

void loop() {
  // put your main code here, to run repeatedly:
  
  if (can_master.read(can_fwd_car)) {
    
    //  do something with the data in can_fwd_car
  
  }

  //  rest of code

}

Hi I am programming a micrcontroller to send messages to a chager, this is because I am currently in a formula student team and the charger will be used to charge the batteries. The problem is that I am sending the through the micro but they are not being sent because I have already tried to send the messages directly from my PC to the charger and it worked, so I can only imagine that my difficulties are inside the code. This is my code:


#include <Arduino.h>
#include <FlexCAN_T4.h>

FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> can1;

void setup() {
Serial.begin(9600);

can1.begin();
can1.setBaudRate(125000);


CAN_message_t msg; // power on all modules
msg.id = 0x02204000;
msg.len = 8;
msg.buf[0] = 0x10;
msg.buf[1] = 0x04;
msg.buf[2] = 0x00;
msg.buf[3] = 0x00;
msg.buf[4] = 0x00;
msg.buf[5] = 0x00;
msg.buf[6] = 0x00;
msg.buf[7] = 0x00;


can1.write(msg);

CAN_message_t msg2; // set an output reference of 100V
msg2.id = 0x02200000;
msg2.len = 8;
msg2.buf[0] = 0x10;
msg2.buf[1] = 0x02;
msg2.buf[2] = 0x00;
msg2.buf[3] = 0x00;
msg2.buf[4] = 0x00;
msg2.buf[5] = 0x06;
msg2.buf[6] = 0xED;
msg2.buf[7] = 0x70;
can1.write(msg2);

CAN_message_t msg3; // set an output reference of 10A
msg3.id = 0x02200000;
msg3.len = 8;
msg3.buf[0] = 0x10;
msg3.buf[1] = 0x03;
msg3.buf[2] = 0x00;
msg3.buf[3] = 0x00;
msg3.buf[4] = 0x00;
msg3.buf[5] = 0x00;
msg3.buf[6] = 0x27;
msg3.buf[7] = 0x10;
}

void loop() {
CAN_message_t msg4; //read output voltage of all modules
msg4.id = 0x02200000;
msg4.len = 8;
msg4.buf[0] = 0x12;
msg4.buf[1] = 0x00;
msg4.buf[2] = 0x00;
msg4.buf[3] = 0x00;
msg4.buf[4] = 0x00;
msg4.buf[5] = 0x00;
msg4.buf[6] = 0x00;
msg4.buf[7] = 0x00;

CAN_message_t message2;

if (can1.read(message2)) {
Serial.print("Received message with ID 0x");
Serial.print(message2.id, HEX);
Serial.print(": ");
for (int i = 0; i < message2.len; i++) {
Serial.print(message2.buf);
}
Serial.print('\n');
}

//Serial.println("teste");
delay(10);
}
 
Hi

I have a small problem and hope there is a solution for my problem.
I'm reading the data from a Scania. The CAN is complete open and there is a lot of traffic.
It seems that the FIFO is overflowing. Is there an option to erase the data from the FIFO. I have more sites on my tool and the idea is to start the FIFO new at every site.

Is it possible to erase all data from the FIFO?

Thanks
Gary
 
I have FIFO running on 3 busses at same time without loss. Are you using interrupts or loop method or polling?

FIFO clears when all messages are read
 
Hi

I have a small problem and hope there is a solution for my problem.
I'm reading the data from a Scania. The CAN is complete open and there is a lot of traffic.
It seems that the FIFO is overflowing. Is there an option to erase the data from the FIFO. I have more sites on my tool and the idea is to start the FIFO new at every site.

Is it possible to erase all data from the FIFO?

Thanks
Gary

Do you really need to fetch all the messages then? What specifically is it that you’re trying to get from that BUS? A good way would be to filter. Give me details and I’ll help. I got allot of experience with J1939.
 
Hi

I have a small problem and hope there is a solution for my problem.
I'm reading the data from a Scania. The CAN is complete open and there is a lot of traffic.
It seems that the FIFO is overflowing. Is there an option to erase the data from the FIFO. I have more sites on my tool and the idea is to start the FIFO new at every site.

Is it possible to erase all data from the FIFO?

Thanks
Gary

I read request messages from the CAN. But after some time there are missing responses. It looks like that this messages are away.

Okay, but why read all of it? Filter out what you don’t need. It would be much more helpful if you tell us what ID’s or what information you need from such a large network. Are you only trying to get for example, the RPM or Speed? Or do you need all the messages?
 
Hi

I have a small problem and hope there is a solution for my problem.
I'm reading the data from a Scania. The CAN is complete open and there is a lot of traffic.
It seems that the FIFO is overflowing. Is there an option to erase the data from the FIFO. I have more sites on my tool and the idea is to start the FIFO new at every site.

Is it possible to erase all data from the FIFO?

Thanks
Gary

I know that some of the CAN buses on the industrial machines and trucks have a lot of messages streamed.
Is there specific data that you are looking for? Or do you need to pass it though like a gateway? (I guess that's why you're using FIFO?)
 
Hi

I have a small problem and hope there is a solution for my problem.
I'm reading the data from a Scania. The CAN is complete open and there is a lot of traffic.
It seems that the FIFO is overflowing. Is there an option to erase the data from the FIFO. I have more sites on my tool and the idea is to start the FIFO new at every site.

Is it possible to erase all data from the FIFO?

Thanks
Gary

Okay so you’re only requesting standard OBD2 PID’s and the responses you get are massive?

So this shouldn’t really happen, or should work, I’ve used a Teensy on industrial machinery CAN BUS before.

So first basic questions, are you using the 120 ohm resistor? Is your device connected to the same Ground as the truck? What Transciever are you using?
 
I'm using the tools from skpang. They are very good..

I need the diagnostic messages from 0x18DAF100 to 0x18DAF13D. So i have tried to take a filter: can3.setFilterRange(0, 0x18DAF100, 0x18DAF13D, EXT). But there are problems because there are some messages which are not comming through the filter.
 
Hi

I have a small problem and hope there is a solution for my problem.
I'm reading the data from a Scania. The CAN is complete open and there is a lot of traffic.
It seems that the FIFO is overflowing. Is there an option to erase the data from the FIFO. I have more sites on my tool and the idea is to start the FIFO new at every site.

Is it possible to erase all data from the FIFO?

Thanks
Gary

I'm using the tools from skpang. They are very good..

I need the diagnostic messages from 0x18DAF100 to 0x18DAF13D. So i have tried to take a filter: can3.setFilterRange(0, 0x18DAF100, 0x18DAF13D, EXT). But there are problems because there are some messages which are not comming through the filter.

Okay so you only need all messages with that ID? This is good, a filter should really work. Works well for me and others.

What exact messages are not getting through, can you post an example? So that we can try to figure out why those aren’t coming through.
 
Today I have examples to read for example the following message:

8030) 17688.012 1 Rx 18DAF112 - 8 10 0C 62 F4 83 02 00 00

In my sight the filter should be open for this message.
 
Hi

I have a small problem and hope there is a solution for my problem.
I'm reading the data from a Scania. The CAN is complete open and there is a lot of traffic.
It seems that the FIFO is overflowing. Is there an option to erase the data from the FIFO. I have more sites on my tool and the idea is to start the FIFO new at every site.

Is it possible to erase all data from the FIFO?

Thanks
Gary

Today I have examples to read for example the following message:

8030) 17688.012 1 Rx 18DAF112 - 8 10 0C 62 F4 83 02 00 00

In my sight the filter should be open for this message.

The filter you use only accepts one ID, I’m unsure if this library can do range. You can try to use ACCEPT_ALL just to make sure the message gets through. But what you need is a filter range.
 
Sorry, i forgot the FIFO.. :)

can3.setFIFOFilterRange(0, 0x18DAF100, 0x18DAF13D, EXT)

In my sight this should be the right filter for more than one message ID
 
Hi

I have a small problem and hope there is a solution for my problem.
I'm reading the data from a Scania. The CAN is complete open and there is a lot of traffic.
It seems that the FIFO is overflowing. Is there an option to erase the data from the FIFO. I have more sites on my tool and the idea is to start the FIFO new at every site.

Is it possible to erase all data from the FIFO?

Thanks
Gary

Sorry, i forgot the FIFO.. :)

can3.setFIFOFilterRange(0, 0x18DAF100, 0x18DAF13D, EXT)

In my sight this should be the right filter for more than one message ID

This should work. How many messages comes through? Is there only a few, or is it working fully in the beginning and then just stops working?
 
The first sites are running well but than there arent messages. So I thought that maybe there is a problem with a overflowing FIFO.
 
Hi

I have a small problem and hope there is a solution for my problem.
I'm reading the data from a Scania. The CAN is complete open and there is a lot of traffic.
It seems that the FIFO is overflowing. Is there an option to erase the data from the FIFO. I have more sites on my tool and the idea is to start the FIFO new at every site.

Is it possible to erase all data from the FIFO?

Thanks
Gary

The first sites are running well but than there arent messages. So I thought that maybe there is a problem with a overflowing FIFO.

Indeed sounds like it’s getting full. That’s the only thing I can think of.

Feel free to send me a PM if you wanna share the code and I can take a look. I usually work with Catepilar CAN BUS. But it’s the same J1939
 
Is it possible that you need a flow control frame for the long responses?
How do you know that messages are being lost and that the fifo is overflowing?
 
I'm sending the flow control for the Iso-TP messages. This isnt the problem. I'm getting all messages but if the system is working longer there are missing messages. So I got the idea that the system ist overflowing. I dont know it. I ask for the messages and they are there. I have read it out with a Pcan Diag FD.
 
Try to empty the FIFO buffer with something like while(can0.available()); then you send the query and wait for a responce.
 
Hi I am using the FlexCAN_T4 library and I wanted to know a specific thing about this one. I wanted to know how can I translate CAN messages for integer/floats variables?
 
you can bitshift the unsigned bytes then cast as needed
for example
RPM:
byte 4 and 5
int value = buf[4] << 8 | buf[5];
 
Evening all

Am using this library with a Teensy 4.1, and am trying to add some code to find the PGNs for an item of interest. Usually, when the code is running, it starts up like this:

Code:
V_Bus.enableFIFO();
V_Bus.setFIFOFilter(REJECT_ALL);
V_Bus.setFIFOFilter(0, 0x0CAC1E13, EXT);
V_Bus.setFIFOFilter(1, 0x18EF1CD2, EXT);
V_Bus.setFIFOFilter(2, 0x1CFFE6D2, EXT);
CANBUS_ModuleID = 0x1E;

But, when I want to flip into this sniffing-mode, I want to remove all filters for a short time, so I had thought it would be as simple as:

Code:
Serial.println("Received signal to disable filters ");
DisableVBUSFilters();
DisableKBUSFilters();

....

void DisableVBUSFilters() {
    Serial.println("Disabled VBUS");
    V_Bus.setFIFOFilter(ACCEPT_ALL);
}
void DisableKBUSFilters() {
    Serial.println("Disabled KBUS");
    K_Bus.setFIFOFilter(ACCEPT_ALL);
}

But in output, all I get is:
Code:
Received signal to disable filters
Disabled VBUS

And then the Teensy hangs, no output continues to my program, and it never moves to the DisableVBUSFilters procedure. Bit new to this, am sure it's something simple, but any help much appreciated!

Thanks
 
Back
Top