Forum Rule: Always post complete source code & details to reproduce any issue!
Page 27 of 27 FirstFirst ... 17 25 26 27
Results 651 to 671 of 671

Thread: FlexCAN_T4 - FlexCAN for Teensy 4

  1. #651
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    thats a different id and doesnt correlate to your sends, is the device sending you that? what is the device?

  2. #652
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    Quote Originally Posted by tonton81 View Post
    thats a different id and doesnt correlate to your sends, is the device sending you that? what is the device?
    Power Supply Huawei R4850
    Click image for larger version. 

Name:	2021-04-22_074425.png 
Views:	2 
Size:	226.6 KB 
ID:	24518

  3. #653
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    well you need the manual for it then, i tried googling and came up with this:
    https://github.com/craigpeacock/Huaw.../Protocol.xlsx

    the IDs dont match what your sending or receiving, but since your receiving something it means your sending the wrong/right data to the wrong canid thats why it's not responding

  4. #654
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    Quote Originally Posted by tonton81 View Post
    well you need the manual for it then, i tried googling and came up with this:
    https://github.com/craigpeacock/Huaw.../Protocol.xlsx

    the IDs dont match what your sending or receiving, but since your receiving something it means your sending the wrong/right data to the wrong canid thats why it's not responding
    yes, this is the document I use,
    but it turns out that nothing works, I am sure that I am doing something wrong,
    but I can't understand what am I doing wrong? if the error is in the team, how should it be correct?

    maybe I'm not forming the team correctly ?

  5. #655
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    wow .... found a bug !!!

    I had it like that:
    msg.buf[0] = 0x01;
    msg.buf[1] = 0x01;

    did so:
    msg.buf[0] = 0x01;
    msg.buf[1] = 0x00;

    now the voltage switches very quickly,
    but another problem appeared, this voltage changes for 1 minute,
    then reverts to the previous value!
    now you need to figure out how to remember it ?

    it looks like now I need to send two commands in a row,
    switch and remember, do I understand correctly ?

  6. #656
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    did you read last line of the xlsx?




    The rectifier can operate in two states:
    Off-line is when there is no CAN communication (i.e. standalone operation). This occurs on power-up or if CAN communication has timed-out (Orange LED slowly blinking).
    On-line values are only valid when CAN communication is present (Orange LED not blinking). These values are volatile and reset to default on loss of CAN comms.
    CAN communication time-out is approximately 60 seconds. i.e. if you stop sending valid CAN messages to the rectifier, the rectifier will switch to Off-line/Default values in approximately 60 seconds.






    You basically need to keep transmitting whatever within 60 seconds for it to remain active, if you stop transmitting for 60 seconds thats it. so send every 30 seconds if you want

  7. #657
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    Quote Originally Posted by tonton81 View Post
    did you read last line of the xlsx?
    You basically need to keep transmitting whatever within 60 seconds for it to remain active, if you stop transmitting for 60 seconds thats it. so send every 30 seconds if you want
    yes, now thanks to you, I understood everything
    I am very grateful to you for your help!
    and if, can you tell me how to write the code correctly, for these purposes ?
    I will be your debtor!

  8. #658
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    1 then 0 workes because on the chart, Online in green is for CAN, because you were sending 1 then 1, you actually disabled canbus so the normal voltage would be output, Offline meant no canbus traffic allowed

  9. #659
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    try using the FIFO with interrupts example so you can see what the responses are, then try to send the message with byte0 as 1 and byte 1 as 0 and repeat send in loop with delay(5), see what it responds?

    everytime its sending every 5 seconds, the powersupply 60 second counter resets, so it shouldnt timeout since your hitting it every 5 seconds, thats more of a powersupply safety, if no data is communicating it'll most likely shut down and wait

  10. #660
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    Quote Originally Posted by tonton81 View Post
    try using the FIFO with interrupts example so you can see what the responses are, then try to send the message with byte0 as 1 and byte 1 as 0 and repeat send in loop with delay(5), see what it responds?

    everytime its sending every 5 seconds, the powersupply 60 second counter resets, so it shouldnt timeout since your hitting it every 5 seconds, thats more of a powersupply safety, if no data is communicating it'll most likely shut down and wait
    Thank you for your reply!
    but for me it is difficult, I cannot do that, I lack knowledge
    I plan to send two commands sequentially,
    first online, then offline, probably this is not correct, but otherwise I have no idea how to do it

  11. #661
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    this?

    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] = 0x00;
      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() {
    
    
    Can0.write(msg);
    delay(5000);
    
    }

  12. #662
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    Quote Originally Posted by tonton81 View Post
    this?

    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] = 0x00;
      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() {
    
    
    Can0.write(msg);
    delay(5000);
    
    }
    Yes fine! Thank you!

  13. #663
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    tonton81, maybe you will have a free minute,
    can you show me how to receive data from a block please?
    with not a lot of sample code?

  14. #664
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    you need to use the "FIFO with interrupts" example and use the same loop() with delay you added earlier, then you'll see the responses every 5 seconds you transmit, according to the xlsx, you'll get a frame reply ACK after the send

  15. #665
    Junior Member
    Join Date
    Apr 2021
    Posts
    19
    Quote Originally Posted by tonton81 View Post
    you need to use the "FIFO with interrupts" example and use the same loop() with delay you added earlier, then you'll see the responses every 5 seconds you transmit, according to the xlsx, you'll get a frame reply ACK after the send
    ok, I understand you, I will try to figure it out.
    thank you again for your time!

  16. #666
    Great work here. I am try to find out more of an understanding of the best way to set up for receiving specific messages. But, I do not know the messages at compile time so I need to set the filters in a loop. I am reading in a DBC file and I only want to receive messages in the DBC file.

    Is this possible?

    Also, what happens if I need to receive more than 128 messages? Can you set filter masking?

    Is is 128 filters per channels or for all 3 channels?

    Thoughts on the best way to set up MB/FIFO (either/or/both) when you do not know what the messages are in advance of compile time?

    Any hints where to find more information on filtering/masking?

    Thanks

    Bruce

  17. #667
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    I don't see a need to filter excessively each id. FIFO has 128 filters however only the first 32 are independant, the rest work off a global filter that doesn't sense to use. There are also 64 mailboxes on T4 and 16 on T3. each mailbox (or channel as you call it?) is ONE filter, but the functions allow mixing one or more IDs on ONE filter. You can use mailboxes, or FIFO, or both. Most people use FIFO for ordered receptions and you can use additional mailboxes for interrupt (or if not using interrupts the mailboxes guarentee the latest stored ID frame remains in that mailbox until read, so other frames won't jump in, good for polling). Most people will just use FIFO with interrupts, no need for mailboxes, you can apply filters to FIFO via setFIFOFilter(0, 0x123, STD);
    FILTER #0, CANID 0x123, STANDARD FRAME
    by default, FIFO consumes 8 mailboxes leaving the rest as transmit, and 8 filters (0-7).

    Teensy is fast enough to not drop frames, you can just filter your ID in the callback:

    if ( msg.id == 0x123 ) { doSomething(); }

  18. #668
    Thanks for the quick response.

    The #'s you are quoting above are they for each can instance (can1,2 and 3) or for all 3?

    Is there a way to set the automatic filtering in a loop or an array?

    MB filter

    bool setMBFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t id2, uint32_t id3, uint32_t id4, uint32_t id5); /* input 5 ID's to be filtered */

    for example the above can set 5 id's....is there a way to set and array of ID's?

    Also for the FIFO filters

    Also I am trying to understand the following a little more:

    What is the difference functionality between the following:

    bool setFIFOUserFilter(uint8_t filter, uint32_t id1, uint32_t id2, uint32_t id3, uint32_t id4, uint32_t mask, const FLEXCAN_IDE &ide, const FLEXCAN_IDE &remote = NONE);

    and

    bool setFIFOFilter(uint8_t filter, uint32_t id1, uint32_t id2, const FLEXCAN_IDE &ide, const FLEXCAN_IDE &remote = NONE); /* 2 ID's per filter */

    and

    bool setFIFOFilter(uint8_t filter, uint32_t id1, const FLEXCAN_IDE &ide1, const FLEXCAN_IDE &remote1, uint32_t id2, const FLEXCAN_IDE &ide2, const FLEXCAN_IDE &remote2); /* TableB 2 ID / filter */
    bool setFIFOFilter(uint8_t filter, uint32_t id1, uint32_t id2, const FLEXCAN_IDE &ide1, const FLEXCAN_IDE &remote1, uint32_t id3, uint32_t id4, const FLEXCAN_IDE &ide2, const FLEXCAN_IDE &remote2); /* TableB 4 minimum ID / filter */

    also the difference between:

    bool setFIFOFilterRange(uint8_t filter, uint32_t id1, uint32_t id2, const FLEXCAN_IDE &ide, const FLEXCAN_IDE &remote = NONE); /* ID range per filter */

    and

    bool setFIFOFilterRange(uint8_t filter, uint32_t id1, uint32_t id2, const FLEXCAN_IDE &ide1, const FLEXCAN_IDE &remote1, uint32_t id3, uint32_t id4, const FLEXCAN_IDE &ide2, const FLEXCAN_IDE &remote2); /* TableB dual range based IDs */

    Sorry for all the questions but as you said the filtering is complicated and I could be flaying for weeks and getting no where.

    Thanks

    Bruce

  19. #669
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700
    Thats alot to explain, but what it comes all down to is just giving it an ID to match to and the hardware will filter that from the rest of the frames. Each instance of can1/2/3 is a completely different controller, they have their own 64 mailboxes and filters.

    CanID filters and masks are a bit challenging to understand, thats why the masks are automatically generated in my code for you, so you only need to assign an ID to the function and the mailbox filter is written to the hardware register.

    With the library normally you'd write 1 ID filter to a mailbox, however by using id1, id2, etc you can write up to 5 IDs that you want the hardware filter to pass. Keep in mind if there are any IDs that overlap the multiple ID filter mask, they will bleed through, this is normal expected behavior. The range function allows you to get IDs between A to B. So if you wanted IDs from 0x50 to 0x64 then it calculates the mask for all those IDs in range and writes the register, so the hardware will pass those frames in the same mailbox. The userfilter is if you want to set your own custom filter, that was added because a user wanted to mask the last 16 bits to accept multiple IDs with the last matching bits matching the acceptance. That is a little more complex for you in this case since you are just starting with filters the library generates it for you automatically. If you want to learn how to make a mask on your own there are sites out there to research on but it's not easy to explain, thats why I wrote the code to generate it for you, makes it easier to use

  20. #670
    How would you handle J1939?

    For example, how would you filter to ignore source and/or destination in the message ID?

    Thanks

    Bruce

  21. #671
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,700

Posting Permissions

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