pierremolinaro / acan Goto Github PK
View Code? Open in Web Editor NEWCAN Driver for Teensy 3.1 / 3.2, 3.5 and 3.6
License: MIT License
CAN Driver for Teensy 3.1 / 3.2, 3.5 and 3.6
License: MIT License
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.
I just wanted to check if this library works with teensy4.0
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:
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 ...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.