Forum Rule: Always post complete source code & details to reproduce any issue!
Page 47 of 48 FirstFirst ... 37 45 46 47 48 LastLast
Results 1,151 to 1,175 of 1193

Thread: FlexCAN_T4 - FlexCAN for Teensy 4

  1. #1151
    Junior Member
    Join Date
    Feb 2023
    Posts
    11

    Angry Having troubel sending messages

    Quote Originally Posted by profor View Post
    @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[i]);
    }
    Serial.print('\n');
    }

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

  2. #1152
    Senior Member skpang's Avatar
    Join Date
    Jan 2015
    Location
    UK
    Posts
    242
    You are using extended IDs.

    You need to add this :

    msg.flags.extended = 1;

  3. #1153
    Junior Member
    Join Date
    Feb 2023
    Posts
    11
    AAAA Thank you! Didn't notice that, thanks a lot!

  4. #1154
    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

  5. #1155
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    4,095
    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

  6. #1156
    I'm using

    can3.enableFIFO();
    can3.enableFIFOInterrupt();

    Thanks for your help

    Gary

  7. #1157
    Senior Member
    Join Date
    Feb 2021
    Posts
    120
    Quote Originally Posted by Gary View Post
    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.

  8. #1158
    Senior Member
    Join Date
    Feb 2021
    Posts
    120
    Quote Originally Posted by Gary View Post
    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
    Quote Originally Posted by Gary View Post
    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?

  9. #1159
    Senior Member
    Join Date
    Oct 2019
    Posts
    451
    Quote Originally Posted by Gary View Post
    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?)

  10. #1160
    Senior Member
    Join Date
    Feb 2021
    Posts
    120
    Quote Originally Posted by Gary View Post
    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?

  11. #1161
    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.

  12. #1162
    Senior Member
    Join Date
    Feb 2021
    Posts
    120
    Quote Originally Posted by Gary View Post
    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
    Quote Originally Posted by Gary View Post
    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.

  13. #1163
    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.

  14. #1164
    Senior Member
    Join Date
    Feb 2021
    Posts
    120
    Quote Originally Posted by Gary View Post
    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
    Quote Originally Posted by Gary View Post
    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.

  15. #1165
    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

  16. #1166
    Senior Member
    Join Date
    Feb 2021
    Posts
    120
    Quote Originally Posted by Gary View Post
    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
    Quote Originally Posted by Gary View Post
    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?

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

  18. #1168
    Senior Member
    Join Date
    Feb 2021
    Posts
    120
    Quote Originally Posted by Gary View Post
    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
    Quote Originally Posted by Gary View Post
    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

  19. #1169
    Thanks for your help. Maybe someone else has an idea...

  20. #1170
    Senior Member
    Join Date
    Oct 2019
    Posts
    451
    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?

  21. #1171
    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.

  22. #1172
    Junior Member
    Join Date
    Apr 2020
    Posts
    19
    Try to empty the FIFO buffer with something like while(can0.available()); then you send the query and wait for a responce.

  23. #1173
    Junior Member
    Join Date
    Feb 2023
    Posts
    11
    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?

  24. #1174
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    4,095
    you can bitshift the unsigned bytes then cast as needed
    for example
    RPM:
    byte 4 and 5
    int value = buf[4] << 8 | buf[5];

  25. #1175
    Junior Member
    Join Date
    May 2023
    Posts
    6
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •