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

Thread: CANquitto

  1. #1
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,711

    CANquitto

    Greetings all. Pushing out a library in development for a teensy to teensy communication over CANbus. It may probably contain bugs that will hinder it's operation, but looking into ressolving them over time...

    The library is capable of transferring up to 8000 byte payload over canbus in sequential ordering with ACK responses and callback firing. It uses one of the raw outputs of IFCT including background events() operation.
    The library supports multiple nodes and is multi-master design

    Two demos have been uploaded as a simple demo, and a few videos of it in action:

    https://www.youtube.com/watch?v=XGUBXl2psck

    https://www.youtube.com/watch?v=UP4KQlDcsoc

    https://www.youtube.com/watch?v=YpxmuLBO8to

    https://www.youtube.com/watch?v=tXqmFIKOsGc

    Github repo: https://github.com/tonton81/CANquitto

    Tony

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,711
    The event handling for CANquitto was redesigned to allow the ISR to be the only consumer/producer for both buffers while not processing, and while processing only the primary buffer was handled by the ISR. Next while not busy, the ISR was in charge of unloading the primary buffer to the secondary one. There is no more buffer shuffling in events, the specific frames are now searched and appended to the local array and the node is purged on completion. Alot of code has been reduced this way. An attempt of a 3 node communication was established during current tests:

    https://m.youtube.com/watch?v=hD-NOlcDQCI

    The Teensy 3.6 (far right) is blinking fast due to it’s sending a 77 byte char array to the 3.2 and 3.5, so it’s getting a double ACK, 1 from each node causing the led to blink on and off rapidly. All 3 consoles are displaying the node transfers including the 3.2 which shows 2 callbacks firing (lower window in video).

    Still looking to improove the code as sometimes a frame could not be completed successfully, although it recovers, it’s still looking to be ressolved

  3. #3
    Junior Member
    Join Date
    Jun 2018
    Location
    Seoul in South Korea
    Posts
    4
    Hello.
    I have one Teensy 3.6 Board... so I try connect between CAN0 and CAN1...

    but not work.....I think only work Fixed CAN0 and node....
    ( so I try modify code....but not easy )

    If you can, I hope support to the next versions.


    I Try test example code....


    #ifndef __MK66FX1M0__
    #error "Teensy 3.6 with dual CAN bus is required to run this example"
    #else
    #include <IFCT.h>//modify code
    #include <CANquitto.h>
    #endif

    #include <Serial_Printf.h>

    CANquitto Node0( FLEXCAN0_BASE ), Node1( FLEXCAN1_BASE );//test

    void setup()
    {
    pinMode( 13, OUTPUT ); // enable led pin

    Serial.begin( 2000000 );
    while( !Serial && ( millis() < 100 ) ); // wait for Arduino Serial Monitor
    Serialprint0( "Setup Start 0\r\n" );

    Can0.setBaudRate( 1000000 );
    Can0.enableFIFO();
    Can0.enableFIFOInterrupt();
    Node0.onReceive( myCallback_0 );
    Node0.begin( 112 );
    Can0.intervalTimer(); // enable queue system and run callback in background.

    Can1.setBaudRate( 1000000 );
    Can1.enableFIFO();
    Can1.enableFIFOInterrupt();
    Node1.onReceive( myCallback_1 );
    Node1.begin( 123 );
    Can1.intervalTimer(); // enable queue system and run callback in background.

    Serialprint0( "Setup End 0\r\n\r\n" );
    }

    void loop()
    {
    static elapsedMillis time_NodeSend = millis(), time_NodeSend_Info = millis();
    uint8_t nNode0_Send = 0, nNode1_Send = 0;
    // put your main code here, to run repeatedly:
    uint8_t buf_node0[ 200 ];
    char buf_node1[] = "Hello World! Hello Teensy! Hello IFCT!";

    if( time_NodeSend >= 200 )
    {
    for( uint32_t i = 0; i < sizeof( buf_node0 ); i++ )
    {
    //buf[ i ] = random( 0, 255 ); // i + 1;
    buf_node0[ i ] = i + 1;
    }

    if( Node0.write( buf_node0, sizeof( buf_node0 ), 123, 2000, 3000 ) == 0x06 )
    {
    digitalWrite( 13, !digitalRead( 13 ) );
    nNode0_Send++;
    }

    if( Node1.write( (const uint8_t*)buf_node1, sizeof( buf_node1 ), 112, 11, 2000, 3000 ) == 0x06 )
    {
    digitalWrite( 13, !digitalRead( 13 ) );
    nNode1_Send++;
    }
    }
    //delay( 100 );

    if( time_NodeSend_Info >= 1000 )
    {
    time_NodeSend_Info = 0;
    Serialprint0( "NodeSend_Info %lu, %lu \r\n", nNode0_Send, nNode1_Send );
    }
    }

    void myCallback_0( const uint8_t* buffer, uint16_t length, AsyncCQ info )
    {
    Serial.print( "node0 PAYLOAD!!: " );
    for( uint32_t i = 0; i < length; i++ )
    {
    Serial.print( buffer[ i ] ); Serial.print( " " );
    } Serial.println();
    Serial.print( "From Node: " );
    Serial.println( info.node );

    Serial.print( "Length: " );
    Serial.println( length );

    Serial.print( "Millis(): " );
    Serial.println( millis() );
    }

    void myCallback_1( const uint8_t* buffer, uint16_t length, AsyncCQ info )
    {
    Serial.print( "node1 PAYLOAD!!: " );
    for( uint32_t i = 0; i < length; i++ )
    {
    Serial.print( buffer[ i ] ); Serial.print( " " );
    } Serial.println();
    Serial.print( "From Node: " );
    Serial.println( info.node );

    Serial.print( "Length: " );
    Serial.println( length );

    Serial.print( "Millis(): " );
    Serial.println( millis() );
    }

    Thank you very much. Tony(tonton81)

  4. #4
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,711
    Yes can0 only supported for now until stability is better, then will add Can1

    the problem is sharing the buffer, we need it stable first on one bus before combining both busses into same buffer for sorting
    Last edited by tonton81; 09-17-2018 at 09:47 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
  •