Forum Rule: Always post complete source code & details to reproduce any issue!
Page 8 of 8 FirstFirst ... 6 7 8
Results 176 to 181 of 181

Thread: IFCT - Improved Flexcan Teensy Library

  1. #176
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,070
    Please check the simple examples posted with the library, it shows you how to send/receive the 8 bytes.
    You can do your 32 bit conversions before/after if necessary

  2. #177
    Junior Member
    Join Date
    Jun 2019
    Posts
    12
    Code:
    void loop() {
      CAN_message_t msg;
      if ( Can0.read(msg) ) canSniff(msg);
    }
    
    void canSniff(const CAN_message_t &msg) {
      Serial.print("MB "); Serial.print(msg.mb);
      Serial.print("  LEN: "); Serial.print(msg.len);
      Serial.print(" EXT: "); Serial.print(msg.flags.extended);
      Serial.print(" REMOTE: "); Serial.print(msg.rtr);
      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();
    }
    I'm unsure of if FIFO is what im after. Basically what Id want is to do would be to

    Code:
    X = Can0.read(0x234) // read a specific CAN ID and address is to a variable. is this possible? I know my nomenclature is going to be wrong but I hope you get what I'm trying to achieve.
    or do I do a

    Code:
    if(msg.id = 0x234)
    {
      for ( sint8_t i = 0; i < msg.len; i++ ) 
     {
        b =x*10
        a=msg.buf[i]
        x = b+a       // makes it a single string of bits
      }
    
    }

    Sorry I am a total nub at CAN messages.

  3. #178
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,070
    it’s just an array of 8 bytes, by default it will pickup all IDs however you can filter it in callback via software or hardware via filtering.

    your second code is software filtering but yeah that’s acceptable.
    you can just set the variable to X = msg.id; .
    Since that is a standard frame ID it uses 11bits, I would still use 32bit unsigned for peace of mind.

  4. #179
    Junior Member
    Join Date
    Aug 2019
    Posts
    12
    Running in to an issue setting msg.seq - compiler is throwing an error say CAN_message_t is read-only:

    My code:
    Code:
    void relayFrame(const CAN_message_t &frame) {
      // Take incoming frame and send to other bus
      frame.seq = 1;
      if(frame.bus == 0 && can1Enabled) {
        Can1.write(frame);
      } else if(frame.bus == 1 && can0Enabled) {
        Can0.write(frame);
      }
    Error relating to line frame.seq = 1:
    Code:
    /home/david/Arduino/ObjectOrientedCAN/CANalyzer.ino/CANalyzer.ino.ino: In function 'void relayFrame(const CAN_message_t&)':
    CANalyzer.ino:72:13: error: assignment of member 'CAN_message_t::seq' in read-only object
       frame.seq = 1;
                 ^
    exit status 1
    assignment of member 'CAN_message_t::seq' in read-only object
    Any ideas as to what's up? I'm going to switch to Canx.write(MB15, frame) for now as this should have the same effect of forcing FIFO on transmit, right?

    I'm thinking that it has to do with the const keyword in the function definitiion, but if I remove that I get a whole bunch of different errors:

    Code:
    /home/david/Arduino/ObjectOrientedCAN/CANalyzer.ino/CANalyzer.ino.ino: In function 'void setup()':
    CANalyzer.ino:21:28: error: invalid conversion from 'void (*)(CAN_message_t&)' to '_MB_ptr {aka void (*)(const CAN_message_t&)}' [-fpermissive]
       Can0.onReceive(relayFrame);
                                ^
    In file included from /home/david/Arduino/ObjectOrientedCAN/CANalyzer.ino/CANalyzer.ino.ino:1:0:
    /home/david/Arduino/libraries/IFCT-master/IFCT.h:197:10: note:   initializing argument 1 of 'void IFCT::onReceive(_MB_ptr)'
         void onReceive(_MB_ptr handler); /* global callback function */
    
              ^
    CANalyzer.ino:27:28: error: invalid conversion from 'void (*)(CAN_message_t&)' to '_MB_ptr {aka void (*)(const CAN_message_t&)}' [-fpermissive]
       Can1.onReceive(relayFrame);
                                ^
    In file included from /home/david/Arduino/ObjectOrientedCAN/CANalyzer.ino/CANalyzer.ino.ino:1:0:
    /home/david/Arduino/libraries/IFCT-master/IFCT.h:197:10: note:   initializing argument 1 of 'void IFCT::onReceive(_MB_ptr)'
         void onReceive(_MB_ptr handler); /* global callback function */
    
              ^
    exit status 1
    invalid conversion from 'void (*)(CAN_message_t&)' to '_MB_ptr {aka void (*)(const CAN_message_t&)}' [-fpermissive]

  5. #180
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,070
    yes thats read only

    you could copy it to modify it

    CAN_message_t copyFrame = frame;
    copyFrame.seq = 1;

    modify everything in copyFrame.

  6. #181
    Junior Member
    Join Date
    Aug 2019
    Posts
    12
    Quote Originally Posted by tonton81 View Post
    yes thats read only

    you could copy it to modify it

    CAN_message_t copyFrame = frame;
    copyFrame.seq = 1;

    modify everything in copyFrame.
    Perfect! 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
  •