Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: CANBUS not receive all frames

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    5

    CANBUS not receive all frames

    Hi,
    I am trying to receive CAN frames with a teensy 3.2.
    I am using an SN65HVD230D.
    There are the 2 120 ohm terminations.
    there are 3 nodes (an ECU, a digital dashboard, and my teensy3.2)
    the ECU and the dashboard are commercial products (race automotive). They work perfectly with each other.
    For the ECU to send these frames, the dashboard sends a request to the ECU (ID 0x80, frame 0-7 = 0x3).
    I am using a oscilloscope to see the frames. it is able to decode them.
    Frames sent by the ECU start at 0x200. they are well transmitted and appear on the oscilloscope.

    My problem :
    with my Teensy3.2 I can only receive the frame sent by the dashboard 0x80, but cannot receive the frames from the ECU ??

    Click image for larger version. 

Name:	20200930_232226.jpg 
Views:	14 
Size:	116.5 KB 
ID:	21931
    Click image for larger version. 

Name:	Capture.PNG 
Views:	14 
Size:	26.5 KB 
ID:	21934

    Code:
    #include <FlexCAN_T4.h>
    FlexCAN_T4 <CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
    CAN_message_t frame;
    //static uint32_t id;
    
    //*************************************************************
    void setup() {
      Serial.begin(115200);
      Can0.begin();
      Can0.setBaudRate(1000000);
      Can0.enableFIFO();
      Can0.setMaxMB(16); 
      Can0.enableFIFOInterrupt();
      Can0.onReceive(FIFO, canSniff);
      Can0.mailboxStatus();  
    
    }  
    //*************************************************************
    void loop() {
      Can0.events();
      CAN_message_t msg;
      if ( Can0.read(msg) )
      {
       canSniff(msg); // polling    
      }
    }
    
    //*************************************************************
    void canSniff(const CAN_message_t &msg) { // global callback
      Serial.print("MB "); Serial.print(msg.mb);
      Serial.print("  LEN: "); Serial.print(msg.len);
      Serial.print(" EXT: "); Serial.print(msg.flags.extended);
      Serial.print(" TS: "); Serial.print(msg.timestamp);
      Serial.print(" ID: "); Serial.print(msg.id, HEX);
      Serial.print(" Buffer: ");
      for ( uint8_t i = 0; i < 8; i++ ) {
        Serial.print(msg.buf[i], HEX); Serial.print(" ");
      } Serial.println(); 
    }
    //*************************************************************

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,449
    Are you using the latest version on github for testing?

    whats the mailboxStatus() report show?

    I noticed you are polling with interrupts, without RX mailboxes, that won't actually do anything

    also weird you are getting a length of 11bytes...
    make sure your transceiver is asserted (if it has an enable pin) and that you have common ground. Be careful, adding 2x120ohm resistors as some ECUs have them built in, and that could offset the resistance

    Try the latest release with your sketch above, and comment out everything in the loop
    Last edited by tonton81; 09-30-2020 at 10:58 PM.

  3. #3
    Junior Member
    Join Date
    Oct 2019
    Posts
    5
    Quote Originally Posted by tonton81 View Post
    Are you using the latest version on github for testing?

    whats the mailboxStatus() report show?

    I noticed you are polling with interrupts, without RX mailboxes, that won't actually do anything

    also weird you are getting a length of 11bytes...
    make sure your transceiver is asserted (if it has an enable pin) and that you have common ground. Be careful, adding 2x120ohm resistors as some ECUs have them built in, and that could offset the resistance

    Try the latest release with your sketch above, and comment out everything in the loop
    I use the latest FlexCAN_T4 [URL = "https://github.com/tonton81/FlexCAN_T4"] https://github.com/tonton81/FlexCAN_T4 [/ URL]
    when program begin mailboxStatus() = empty, after a short time it receive frame but only 0x80.
    [ATTACH = CONFIG] 21941 [/ ATTACH]
    ground is the same, 2 resistor 120ohms = resitor equivalent = 60ohms.

    what is surprising is that I receive a frame but not the other.

    i tested an other code from your example:
    but i can't use Can0.setMBFilterProcessing, i have an error:

    "sketch_oct01a:28: error: within this context
    Can0.setMBFilterProcessing(MB0,0x00,0x7F);"


    Code:
    #include <circular_buffer.h>
    #include <FlexCAN_T4.h>
    #include <imxrt_flexcan.h>
    #include <kinetis_flexcan.h>
    
    //#include <FlexCAN_T4.h>
    FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
    
    #define NUM_TX_MAILBOXES 2
    #define NUM_RX_MAILBOXES 6
    void setup(void) {
      Serial.begin(115200); delay(400);
      Can0.begin();
      Can0.setBaudRate(1000000);
      Can0.setMaxMB(NUM_TX_MAILBOXES + NUM_RX_MAILBOXES);
      for (int i = 0; i<NUM_RX_MAILBOXES; i++){
        Can0.setMB(i,RX,STD);
      }
      for (int i = NUM_RX_MAILBOXES; i<(NUM_TX_MAILBOXES + NUM_RX_MAILBOXES); i++){
        Can0.setMB(i,TX,STD);
      }
      Can0.setMBFilter(REJECT_ALL);
      Can0.enableMBInterrupts();
      Can0.onReceive(MB0,canSniff);
      Can0.onReceive(MB1,canSniff);
      Can0.onReceive(MB2,canSniff);
      Can0.onReceive(MB3,canSniff);
      Can0.setMBFilter(MB0,0x00,0x7F);
      Can0.setMBFilter(MB1,0x80,0x81);
      Can0.setMBFilter(MB2,0x82,0x1FF);
      Can0.setMBFilter(MB3,0x200,0xFF);
      Can0.mailboxStatus();
    }
    
    void canSniff(const CAN_message_t &msg) {
      Serial.print("MB "); Serial.print(msg.mb);
      Serial.print("  OVERRUN: "); Serial.print(msg.flags.overrun);
      Serial.print("  LEN: "); Serial.print(msg.len);
      Serial.print(" EXT: "); Serial.print(msg.flags.extended);
      Serial.print(" TS: "); Serial.print(msg.timestamp);
      Serial.print(" ID: "); Serial.print(msg.id, HEX);
      Serial.print(" Buffer: ");
      for ( uint8_t i = 0; i < msg.len; i++ ) {
        Serial.print(msg.buf[i], HEX); Serial.print(" ");
      } Serial.println();
    }
    
    void loop() {
      Can0.events();
    }
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Capture2.PNG 
Views:	8 
Size:	29.9 KB 
ID:	21941  

  4. #4
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,449
    first, stop using all the filtering, stop using REJECT_ALL. you say your having issues receiving but your posting a sketch showing me you wanna block all frames and add filtering. you are not receiving frames and you're playing with filters isn't how you fix it. uncomment all your filter stuff, and also setMBFilterProcessing is used by the library not the user. you have no access to it. In fact, use the sketch you posted originally, because this one is definately not helping you at all

    secondly, notice your setting your mailboxes to STD (standard) and none for (EXT) extended? is the ID you are missing extended? it will never receive. You need to use the example and stop modifying mailboxes because you showed me 2 completely different sketches now and it is hard to diagnose it, especially since the 2nd sketch you posted makes things worse to debug

    also setTX has no option (STD) for TX mailbox, it doesn't use it, reception only does. The stock sketch puts even amount of standard and extended mailboxes and a bunch of TX mailboxes. start from there.

    use the "FIFO with Interrupt" example in library then see what it says
    Last edited by tonton81; 10-01-2020 at 11:04 PM.

Posting Permissions

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