Forum Rule: Always post complete source code & details to reproduce any issue!
Page 26 of 27 FirstFirst ... 16 24 25 26 27 LastLast
Results 626 to 650 of 672

Thread: FlexCAN_T4 - FlexCAN for Teensy 4

  1. #626
    If you are using a library like MegaCAN, which will parse the message IDs and data, fifo with interrupt probably makes the most sense.

  2. #627
    Junior Member
    Join Date
    Dec 2020
    Posts
    7
    Hi,

    Is there somewhere I can find more detailed documentation for this library? The git page assumes you understand why mailboxes and FIFO would be useful, and Im looking for more information on these.

    I am also trying to understand how the interrupts for this library work. I know system interrupts should be very lean, and Im not sure if changing code in the canSniff function (argument of onReceive) is a bad idea.

    Long story short, I am trying to implement a double click detection function using this library (if button press can packet detected twice within 400ms, then double click, else, single click). I had this function working perfectly using a different microcontroller and can library but I can not get it working properly with the FIFO setup here.

    Id like to try and sort this out myself, but the lack of documentation is making this difficult.

    Thanks for the help,
    Alex

  3. #628
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    if you don't use events(), message reception is fired directly to callbacks. I too use CAN button counting for OEM keyfob to control windows and sunroof, obviously you need to count them not in the callback scope only, I used a circular buffer to store the count, you could also use a volatile variable, I used a queue because i can look into the buffer to see the last button pressed (not only count) to engage the feature I want

  4. #629
    Senior Member
    Join Date
    Aug 2014
    Posts
    172
    Quote Originally Posted by msadie View Post
    If you are using a library like MegaCAN, which will parse the message IDs and data, fifo with interrupt probably makes the most sense.
    Presume then that then MegaCAN variable should be volatile?

  5. #630
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    volatile without events(), doesn't matter with events()

  6. #631
    Junior Member
    Join Date
    Dec 2020
    Posts
    7
    Quote Originally Posted by tonton81 View Post
    if you don't use events(), message reception is fired directly to callbacks. I too use CAN button counting for OEM keyfob to control windows and sunroof, obviously you need to count them not in the callback scope only, I used a circular buffer to store the count, you could also use a volatile variable, I used a queue because i can look into the buffer to see the last button pressed (not only count) to engage the feature I want
    Thanks, Got it working. I had two issues.

    1) my counter was not volatile (oops, should have known that)
    2) I was not checking for can events while waiting for the next button press.

    This code is a little ugly, but it works!

    Code:
    int volatile clickCounter = 0;
    
    int checkNumClicks(void){
        static unsigned long max_delay = 800;
        int returnVal = 0;
        //Serial.print("before Adding to Counter");
        //Serial.println(clickCounter);
        clickCounter += 1;
        //Serial.print("After Adding to Counter");
        //Serial.println(clickCounter);
    
        lastButtonPress = millis();
    
        while((millis() - lastButtonPress < max_delay) && clickCounter == 1){
           can1.events(); //NEED to CHECK FOR CAN MESSAGES WHILE YOU ARE WAITING FOR COUNTER TO INCREMENT!
    
    
            if (clickCounter == 2){
            Serial.println("Button pressed twice!");
            returnVal = 2;
            clickCounter = 0;
            lastButtonPress = millis();
            break;
            return(returnVal); //I don't think this actually does anything.
            }
        }
        if (clickCounter == 1){
            Serial.println("Button pressed once!");
            clickCounter = 0;
            returnVal = 1;
            lastButtonPress = millis();
            return(returnVal);
        }
    
        return (returnVal);
    }

  7. #632
    Senior Member
    Join Date
    Jun 2014
    Posts
    251
    I 've posted my CAN board on Tindie for anyone interested.



    https://www.tindie.com/products/fusi...-teensy-40-41/

  8. #633
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    Hi,
    please, tell me, what am I doing wrong?
    when the temperature of the external device rises, the power supply R4850 must reduce the output voltage,
    the code works, but when switching the voltage there is a delay of 60-70 seconds, this is a lot!
    how to remove this delay? I will be very grateful for your help!
    Code:
    #include <FlexCAN_T4.h>
    
    FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> can1;
    CAN_message_t msg;
    
    uint8_t Temperature = 0;
    uint8_t temp = 0;
    
    void setup()
    {
      can1.begin();
      can1.setBaudRate(125000);
    }
    
    void loop()
    {
      if (Temperature > 50 && temp == 0)
      {
        msg.mb = 1;
        msg.id = 0x108180fe;
        msg.len = 8;
        msg.buf[0] = 0x01;
        msg.buf[1] = 0x01;
        msg.buf[2] = 0x00;
        msg.buf[3] = 0x00;
        msg.buf[4] = 0x00;
        msg.buf[5] = 0x00;
        msg.buf[6] = 0xa6; // Voltage 41.5
        msg.buf[7] = 0x00;
        can1.write(msg);
        temp = 1;
      } else if (Temperature < 45 && temp == 1)
      {
        msg.mb = 1;
        msg.id = 0x108180fe;
        msg.len = 8;
        msg.buf[0] = 0x01;
        msg.buf[1] = 0x01;
        msg.buf[2] = 0x00;
        msg.buf[3] = 0x00;
        msg.buf[4] = 0x00;
        msg.buf[5] = 0x00;
        msg.buf[6] = 0xd6; // Voltage 53.5
        msg.buf[7] = 0x00;
        can1.write(msg);
        temp = 0;
      }
    }

  9. #634
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    it looks like you are flooding the bus with writes, are you sure the device can process the data that fast? usually on cars we need to space the transmissions to a device at like 10ms, but your loop is constantly flooding the bus so.....

    that is an extended ID, you should be using:
    Code:
    msg.flags.extended = 1;
    Maybe its just the extended flag, I relooked your code and see it's doing only a single transmission on a heat change, but because you are not using the flag, the CANID is truncated to 11bit instead of being 29bit..

  10. #635
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    Quote Originally Posted by tonton81 View Post
    it looks like you are flooding the bus with writes, are you sure the device can process the data that fast? usually on cars we need to space the transmissions to a device at like 10ms, but your loop is constantly flooding the bus so.....

    that is an extended ID, you should be using:
    Code:
    msg.flags.extended = 1;
    Maybe its just the extended flag, I relooked your code and see it's doing only a single transmission on a heat change, but because you are not using the flag, the CANID is truncated to 11bit instead of being 29bit..
    I am very grateful to you for your answer!
    but, I am very bad at programming (((
    can't figure out what i need to do?

  11. #636
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    Code:
    msg.flags.extended = 1;
    this must be set BEFORE writing, or else your extended ID will truncate to a standard ID and it will not be the one you wanted for your device

    also try adding in setup:
    Code:
    can1.setClock(CLK_60MHz);
    the default 24MHz clock didnt work on my civic's BCAN bus at 125000, but 60MHz worked

  12. #637
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    please tell me where to install this code ?
    Code:
    msg.flags.extended = 1;
    I use Teensy 3.2, this code throws an error
    Code:
    can1.setClock(CLK_60MHz);

  13. #638
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    ahh okay sorry Teensy 3.x doesn't use setClock, 4.x only.

    you need to put that msg.flags.extended with your message you wanna send. put it under your msg.id = 0x108180fe;

  14. #639
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    Quote Originally Posted by tonton81 View Post
    ahh okay sorry Teensy 3.x doesn't use setClock, 4.x only.
    you need to put that msg.flags.extended with your message you wanna send. put it under your msg.id = 0x108180fe;
    unfortunately there are no changes, the delay remains the same 60 seconds (((

  15. #640
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    Is your CAN line properly terminated? what happens if you put can1.events() in the loop()?

  16. #641
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    Quote Originally Posted by tonton81 View Post
    Is your CAN line properly terminated? what happens if you put can1.events() in the loop()?
    unfortunately it gives nothing

  17. #642
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    tonton81, can I somehow disable data reception?
    I only need to transfer data,
    maybe then the transmission speed will increase?

    i made simple code, but the effect is the same, the delay when switching is 65 seconds
    Code:
    #include <IFCT.h>
    
    CAN_message_t msg;
    
    void setup() {
      Can0.setBaudRate(125000);
      Can0.enableFIFO();
    
      msg.ext = 1;
      msg.id = 0x108180fe;
      msg.len = 8;
      msg.buf[0] = 0x01;
      msg.buf[1] = 0x01;
      msg.buf[2] = 0x00;
      msg.buf[3] = 0x00;
      msg.buf[4] = 0x00;
      msg.buf[5] = 0x00;
      msg.buf[6] = 0xd6; //Voltage
      msg.buf[7] = 0x00;
    
      Can0.write(msg);
    }
    
    void loop() {
    }

  18. #643
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    if you dont read them they will stay full. reception and transmission have different mailboxes and dont depend on each other. You should try printing mailboxStatus() every couple seconds then, if it shows all TX mailboxes full, it means you have physical connection issues (transceiver not enabled via gpio? CAN termination resistance?)

  19. #644
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    Quote Originally Posted by tonton81 View Post
    if you dont read them they will stay full. reception and transmission have different mailboxes and dont depend on each other. You should try printing mailboxStatus() every couple seconds then, if it shows all TX mailboxes full, it means you have physical connection issues (transceiver not enabled via gpio? CAN termination resistance?)
    unfortunately I don't understand a lot, I have no experience with these devices,
    I use this wiring diagram ..
    Click image for larger version. 

Name:	schematic.png 
Views:	7 
Size:	13.9 KB 
ID:	24512

  20. #645
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    MCP2551 is a 5V transceiver, you need to make sure the communication is done at 3.3V or you risk damaging the pin on teensy. Or look for a 3.3V transceiver

  21. #646
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    Quote Originally Posted by tonton81 View Post
    MCP2551 is a 5V transceiver, you need to make sure the communication is done at 3.3V or you risk damaging the pin on teensy. Or look for a 3.3V transceiver
    2.0-2.5 volts, these levels correspond to Teensy,
    I think it is possible that additional commands are needed for the block R4850...

  22. #647
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    No thats the way it sends, something wrong in your setup. if IFCT and FlexCAN_T4 both don't work it'd definately not the code

  23. #648
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    Quote Originally Posted by tonton81 View Post
    No thats the way it sends, something wrong in your setup. if IFCT and FlexCAN_T4 both don't work it'd definately not the code
    I've been fighting this for two weeks now, I broke my whole head,
    I can't imagine which way to dig ...

    I tried to connect through such a module, there is a delay ..
    Click image for larger version. 

Name:	2021-04-21_223003.png 
Views:	5 
Size:	231.1 KB 
ID:	24514
    there is clearly something wrong with the commands ...

  24. #649
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    have you checked with a can bus analyzer to see if data is going out? or try another can-equipped bus just to see if you can read the bus (using FIFO example). If you can't read the bus don't expect transmissions to work, if you can read the bus, best to check if your frame layout is correct for the device your talking to

  25. #650
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    Quote Originally Posted by tonton81 View Post
    have you checked with a can bus analyzer to see if data is going out? or try another can-equipped bus just to see if you can read the bus (using FIFO example). If you can't read the bus don't expect transmissions to work, if you can read the bus, best to check if your frame layout is correct for the device your talking to
    tonton81, I am very grateful to you for participating in my problem!
    this is the data I accept using IFCTsimpleFIFOPolling.ino
    Click image for larger version. 

Name:	2021-04-22_071311.png 
Views:	6 
Size:	62.6 KB 
ID:	24516
    and wto such with the help IFCTsniffer.ino
    Click image for larger version. 

Name:	2021-04-22_071158.jpg 
Views:	5 
Size:	77.5 KB 
ID:	24517
    but I don't understand what they mean

Posting Permissions

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