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

Thread: TeensyCAN

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

    TeensyCAN

    Here it is! CAN2.0/CANFD Implementation early stages. Redesign of CANquitto. This library has the ability not only to work on CAN2.0 and CANFD, but the payload transfers are automatically adjusted to the dlc size of your mailbox and sent out dissambled, and at the other endpoint, they are re-assembled based on the DLC implementation.

    Library supports sending payloads of theoretically 4,063,170 bytes. Considering the RAM on MCU, I doubt you'd reach this
    New feature not introduced in CANquitto ---> broadcasting payloads! All nodes can receive the same identical payload, sort of like UDP, no responses are needed.
    Payloads sent specifically to nodes, will return an ACK 0x06 if the reception and CRC are validated from other endpoint.

    Uses the background functions built into FlexCAN_T4 to receive frame data.
    Examples were posted with the library. To be effective, at least one or more extended mailboxes need to be interrupt enabled in FlexCAN_T4.

    https://github.com/tonton81/TeensyCAN

    On a side note only FD was tested, with mailbox sizes of 8 to 64 bytes in the slave demo, the master demo was set to 64 bytes to demonstrate it can accept all different DLC lengths of the slave transmissions

    Node.sendMsg() sends a broadcast payload to all nodes
    node100.sendMsg() sends a payload specifically to node #100
    Last edited by tonton81; 11-03-2019 at 07:38 AM.

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,134
    Upped to github is a new update to TeensyCAN. USB Serial & UART accesses can be called specifically to a node or globally on the network of nodes!

    Node.Serial.println("Hello World!"); // prints to Serial monitor of all nodes on the network, using a single set of data frames. All nodes will assemble the message and process as needed.
    node100.Serial.println("Hello World!"); // prints specifically on this node, other nodes ignore the call

    The supported functions are write(), write(buf,len), print(), println(), read(), readBytes(), peek(), available().
    Yes! This new update has a 2 way send and receive payloads in a single call, and the commands are not ran from an interrupt!
    Whats more? 2 or more nodes may print to the same port without collision if arrays are used. The accesses are sequential and responded to immediately.

    Note, do not try to print() stuff to other serial ports if you didn't run Serialx.begin() on that node, it will hard lock the mcu.

    Later on when I add GPIO support, it might be a good solution for people who want to keep gpio pins sync'd accross microcontrollers. Example is (not implemented yet):

    Node.pinMode(13, OUTPUT); /* tell all nodes to set their pin 13 as output */
    Node.digitalWrite(13,HIGH); /* tell all nodes to turn their leds on */
    node100.digitalWrite(13,LOW); /* while all other nodes have pin13 HIGH, node100 only is switched LOW */

    On a side note, global commands have no responses. Example:
    Node.Serial.println("Hello World!"); /* dont expect valid return value */
    node100.Serial.println("Hello World!"); /* returns 13 */

  3. #3
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,299
    Nice work Tony.

  4. #4
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,134
    New update for TeensyCAN.

    Node Discovery! The library is able to keep a list of active nodes, their DLC capabilites (receive DLC size max), and their timeout on the network (millis()).
    The timeout depicts how long before the node can resend a keep-alive signal on the bus, and the limit is kept on the sender's active list while it's checked against the local timestamp.
    DLC sizing, the node on the active list has his max DLC capability stored. This prevents 64 byte nodes from writing 64 byte data to 32byte DLC nodes. The sender node now sends at the receivers's size, in this case, 32 bytes. If, however, the receiver accepts a bigger DLC than the sender, the sender sends at his capability instead. So a 32byte node would send a 32byte buffer to a 64byte node. This is all automatic and no user intervention is needed. As far as global sends go, they go out based on the smallest DLC node. Basically, if you have 5 nodes on the network, they will be on the active list.
    Let's say:

    node1 is 32bytes,
    node2 is 16bytes,
    node3 is 64bytes,
    node4 is 16bytes,
    node5 is 8bytes.

    Global sends would go out as 8 bytes traffic. However, if node5 were to drop off the list (offline), global sends would now be sent as 16 byte traffic.

    sendMsg has been upgraded to use the unified assembler/disassembler as the commands. It's features have been retained.
    Last edited by tonton81; 11-10-2019 at 09:39 PM.

  5. #5
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,134
    TeensyCAN has now gone multi-bus mode! Nodes can be talked to on any or all of the 3 CAN busses on Teensy. Responses to nodes will happen to their appropriate busses. Globals now send to all 3 busses unless one is chosen specifically using ::setBus.

    If setBus is set, only one bus is broadcasted to. If unset, all busses will be talked to for global messages. (discoveries or node replies).

    Using 64byte frames, 1024bytes transfers now at 2ms. This requries the FlexCAN_T4::events() update to return the sequential queues left in the buffer needed to send out, before a next TeensyCAN message went out. Previously, this test took 17ms to ensure no payload collisions, to transfer the same 1024 payload accross 64byte message frames.

    Multibus mode retains FD controller TX sizes of external nodes:

    If the sender is 64byte frames supported, and the FD node supports 32 max, The sender will send at 32 frame size. In the global scheme, all CAN2 busses, the sender would send out as 8 byte frames, while, maintaining the size of the FD bus node (32bytes), sending at it's supported size on the FD bus.

Posting Permissions

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