Giter Club home page Giter Club logo

acan's People

Contributors

koryphon avatar pierremolinaro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

acan's Issues

Send message in a timed loop

Hi ,

When trying to send a message in a timed loop I do not know the best phrase for the send message.
I have the "send" function with the yield and is not as good as it should be ?
How can I make it better ?

`// Teensy 3.2 test
// This demo runs on Teensy 3.2
// The CAN0 integrated module exchange data.
// - CAN0TX: pin #3
// - CAN0RX: pin #4

#include <ACAN.h>
#include <elapsedMillis.h>
elapsedMillis Timermillis;

//-----------------------------------------------------------
void setup ()
{
pinMode (LED_BUILTIN, OUTPUT) ;
digitalWrite (LED_BUILTIN, HIGH) ;
//--- Start serial
Serial.begin (38400) ;
//--- Wait for serial (blink led at 10 Hz during waiting)
while (!Serial) {
delay (50) ;
digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
}
ACANSettings settings (500 * 1000) ; // 500 kbit/s
uint32_t errorCode = ACAN::can0.begin (settings) ;
if (0 == errorCode) {
Serial.println ("can0 ok") ;
} else {
Serial.print ("Error can1: 0x") ;
Serial.println (errorCode, HEX) ;
}
Serial.println ("Setup complete") ;
}

byte msg[8] = {0, 0, 0, 0, 0, 0, 0, 0};

//---------------------------------------------------------------
void AD7606 () {

uint32_t timehack = millis();

byte msg[8] = { timehack >> 24, timehack >> 16, timehack >> 8, timehack & 0xF, 55, 66, 77, 28};

Serial.println ("Started loop") ;

CANMessage frame ;
frame.id = 31 ;
frame.ext = true ;
frame.rtr = false ;
frame.idx = 0 ;
frame.len = 8 ;
for (int i = 0 ; i < 8 ; i++) {
frame.data [i] = msg[i] ;
}
Serial.print ("Try to Sent: ") ;
while (!ACAN::can0.tryToSend (frame)) {
yield () ;
}
Serial.print ("Sent: ") ;
}

//---------------------------------------------------------------
void loop()
{
if (Timermillis >= 250)
{
AD7606();
Timermillis = Timermillis - 250;
}
}`

Another question;
is there a nice way to split 16 bytes in 2 CAN messages with each 8 bytes, or 24bytes in 3 messages with 8 bytes ?
The message ID need to get an increasing number for example 0X020 and 0X021 etc.

Sequentiality broken

ACAN 2.0.0 on Teensy 3.2 (Arduino 1.8.12, Teensyduino 1.51), direct attached TJA1050, mTransmitBufferSize 16.
Repeating every 10 seconds to quickly send 41 CAN frames.
After a few packages of 41 CAN frames, sequentiality is broken.
Sender: CanJsonTest.ino.txt
Receiver (ACAN2515 2.0.2 on Arduino Nano with MCP2515/TJA1050 for what its worth):
acantest01.ino.txt
Receiver output: CanTest.Reception.log
On the wire, and at the receivers TJA1050 digital output towards the MCP: CanTest Scope

Note: Increasing mTransmitBuffer to contain all 41 frames avoids the issue, so the problem seems to be some race condition with my application calling can.tryToSend in a very tight loop whilst the transmit buffer is full.

Btw, thanks for the great library. I've built an MQTT CAN hub including a firmware reflasher over CAN for Arduino and Teensy 3/4 on top of it ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.