Forum Rule: Always post complete source code & details to reproduce any issue!
Page 7 of 7 FirstFirst ... 5 6 7
Results 151 to 161 of 161

Thread: FlexCAN_T4 - FlexCAN for Teensy 4

  1. #151
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,205

    Talking

    The ISR's only job is to queue it.into.the.buffer and exit, if enough frames can fill the queue before you finish pulling them the oldest, excess frames in the queue will be discarded. The background callback is if you want to handle the frame from within the ISR context, and not later via the queue. Running events() as fast as possible is your way to reading all the queues without having it fill to max and start discarding stale frames.

    The fact that the ISR is so fast to clear the mailbox doesn't allow for overflow to next mailbox, is reason why only MB2 is picking up frames, as the first RX MB. You need to process events() as soon as possible to leave room for other frames to drop into the queue from the ISR. If you delay 500ms for events() and 20 frames come in, ISR puts them in queue, and you run events ONCE, theres 19 left to do. Delay again, 20 more frames, your up to 49,events() runs ONCE, your at 48 left. You need to process events as fast as possible, not let it wait on delayed code

    Rezo thats fine, you can definately go faster if you want
    Last edited by tonton81; 02-03-2020 at 07:58 PM.

  2. #152
    Thanks for the confirmation tonton.

    I have another question.

    I some of my calculations of the response, I am placing some of the data into formula's based on my requests (filter based on header ID and the first 3 bytes of the frame).
    In one of my formulas I need to treat the 5th byte as a signed int.

    Here is a cut portion of my code (it has some sensitive data in the code that I don't want to share publicly):
    Code:
     while (waiting < 60) {   //Check for timeout
    
        if(Can0.read(can_MsgRx)) { 
    
    
                        #define a can_MsgRx.buf[4]
                        #define b can_MsgRx.buf[5]
                        #define c can_MsgRx.buf[6]
                        #define d can_MsgRx.buf[7]
    
    
        return ((signed(a) * 256) + b) * 0.01;
        }
     }
    Here is an example of the last 4 bytes:
    FF 90 AA AA

    What I expect to see is 0xFF = -1 and 0x90 = 144. And in the formula: ((-1*256) + 144) * 0.01 = -1.12
    But what I get is 0xFF = 255 and 0x90 = 144. And in the formula ((255*256) + 144) * 0.01 = 654.24


    Now for some reason it's treating can_MsgRx.buf[4] as an unsigned int and not a signed int.

    I looked into the FlexCAN_T4.h file and noticed that the buffer within the CAN_message_t constructor is declared as an unsigned 8 bit integer. Could this be the reason I can't treat it the 4th byte as a signed integer?
    Is there a workaround for this? Or am I talking complete rubbish? (I'm a real noob when it comes to C++)

  3. #153
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,205
    You can just cast it to an int

    (int8_t)can_MsgRx.buf[4]

  4. #154
    Junior Member
    Join Date
    Dec 2019
    Location
    Italy
    Posts
    17
    Can I use this library with my Teensy 4 and MCP2515 board through the SPI interface?
    I need to use the MCP2515 board.

  5. #155
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,205
    No, this is a driver made for the internal controller, which is much faster than the MCP2515 and without the SPI overhead, is there a reason why you want to use a 2515 when you have a much better built in one?

  6. #156
    Junior Member
    Join Date
    Dec 2019
    Location
    Italy
    Posts
    17
    Quote Originally Posted by tonton81 View Post
    No, this is a driver made for the internal controller, which is much faster than the MCP2515 and without the SPI overhead, is there a reason why you want to use a 2515 when you have a much better built in one?
    The reason is that I have to work at 307.2 kbps, and I found that is only possible with certain oscillators, that I can change on mcp2515 board
    Last edited by andrea1984; 02-12-2020 at 08:16 AM.

  7. #157
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,205
    I am not sure the tolerance on T4, T3 ran off a CAN clock of 16MHz and T4 can run up to 60MHz, so the timings might be possible, I don't have the tools to test the theory though.

  8. #158
    Junior Member
    Join Date
    Dec 2019
    Location
    Italy
    Posts
    17
    Quote Originally Posted by tonton81 View Post
    I am not sure the tolerance on T4, T3 ran off a CAN clock of 16MHz and T4 can run up to 60MHz, so the timings might be possible, I don't have the tools to test the theory though.
    I did all the possible combination of internal Teensy clock, unfortunaly there is the need of an oscillator that is a multiple of power of 2, like an 6.144 MHz, so that 307.2kbps is an integer multiple of the input clock

  9. #159
    Junior Member
    Join Date
    Jan 2020
    Posts
    5
    Hi,

    I'm doing a lot of saving and transferring with the data that I'm logging off of CAN and CANFD networks, and I've encountered 2 obstacles:

    1)
    How does the library handle the Cyclic Redundancy Check field of the CAN and CANFD messages? And how can I access them?

    2)
    How can I set listen_only mode (no acknowledge) on the CAN and CANFD transceivers?

  10. #160
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,205
    setBaudRate(500000, LISTEN_ONLY);

    The library doesnt handle the crc frame, the hardware does

  11. #161
    Junior Member
    Join Date
    Nov 2019
    Posts
    8
    I've finally got all my hardware in place so I can start testing - but I've run into an issue.

    I can't seem to receive frames with BRS enabled on my Teensy. As soon as I enable that bit (in CANalyzer 11 Pro's Interactive Generator), the Teensy apparently stops acknowledging the message.

    What works:
    Sending messages Teensy -> Interface (BRS disabled, 8 - 64 bytes)
    Sending messages Teensy -> Interface (BRS enabled, standard, 8 - 64 bytes)
    Receiving messages Interface -> Teensy (BRS disabled, 8 - 64 bytes)

    What does not work:
    Receiving messages Interface -> Teensy (BRS enabled, 8 - 64 bytes)

    I'm using an MCP2558FD, connected to FlexCAN3 on my Teensy 4. The MCP2558FD is split terminated (60-60 Ohm with 4700 pF). From there, wiring to my VN5610A with a 120 Ohm termination adaptor.
    Baud rates are 500k / 2000k

    edit: Hmm, works for now. No idea what I changed though. Anyways - thanks for your awesome library!
    Last edited by towe; Yesterday at 10:05 AM.

Posting Permissions

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