Skip to content

Commit b6328ed

Browse files
Version 2.1.7
1 parent f0b69f5 commit b6328ed

File tree

9 files changed

+295
-152
lines changed

9 files changed

+295
-152
lines changed

examples/LoopBackDemoArduinoUno/LoopBackDemoArduinoUno.ino

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void setup () {
7777
//——————————————————————————————————————————————————————————————————————————————
7878

7979
static uint32_t gSendDate = 0 ;
80+
static uint32_t gReceiveDate = 0 ;
8081
static uint32_t gReceivedFrameCount = 0 ;
8182
static uint32_t gSentFrameCount = 0 ;
8283

@@ -85,21 +86,26 @@ static uint32_t gSentFrameCount = 0 ;
8586
void loop () {
8687
CANFDMessage frame ;
8788
if (gSendDate < millis ()) {
88-
gSendDate += 2000 ;
89+
gSendDate += 1000 ;
8990
const bool ok = can.tryToSend (frame) ;
9091
if (ok) {
9192
gSentFrameCount += 1 ;
9293
Serial.print ("Sent: ") ;
93-
Serial.println (gSentFrameCount) ;
94+
Serial.print (gSentFrameCount) ;
9495
}else{
95-
Serial.println ("Send failure") ;
96+
Serial.print ("Send failure") ;
9697
}
98+
Serial.print (", receive overflows: ") ;
99+
Serial.println (can.hardwareReceiveBufferOverflowCount ()) ;
97100
}
98-
if (can.available ()) {
99-
can.receive (frame) ;
100-
gReceivedFrameCount ++ ;
101-
Serial.print ("Received: ") ;
102-
Serial.println (gReceivedFrameCount) ;
101+
if (gReceiveDate < millis ()) {
102+
gReceiveDate += 4567 ;
103+
while (can.available ()) {
104+
can.receive (frame) ;
105+
gReceivedFrameCount ++ ;
106+
Serial.print ("Received: ") ;
107+
Serial.println (gReceivedFrameCount) ;
108+
}
103109
}
104110
}
105111

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//——————————————————————————————————————————————————————————————————————————————
2+
// ACAN2517FD Demo in loopback mode, for Arduino Uno, without INT pin
3+
//——————————————————————————————————————————————————————————————————————————————
4+
5+
#include <ACAN2517FD.h>
6+
#include <SPI.h>
7+
8+
//——————————————————————————————————————————————————————————————————————————————
9+
// Very very important: put a 10kΩ resistor between CS and VDD of MCP2517FD
10+
11+
static const byte MCP2517_CS = 10 ; // CS input of MCP2517
12+
13+
//——————————————————————————————————————————————————————————————————————————————
14+
// ACAN2517FD Driver object
15+
//——————————————————————————————————————————————————————————————————————————————
16+
17+
ACAN2517FD can (MCP2517_CS, SPI, 255) ; // Last argument is 255 -> no interrupt pin
18+
19+
//——————————————————————————————————————————————————————————————————————————————
20+
// SETUP
21+
//——————————————————————————————————————————————————————————————————————————————
22+
23+
void setup () {
24+
//--- Start serial
25+
Serial.begin (115200) ;
26+
//--- Wait for serial (blink led at 10 Hz during waiting)
27+
while (!Serial) {
28+
delay (50) ;
29+
}
30+
//----------------------------------- Begin SPI
31+
SPI.begin () ;
32+
//--- Configure ACAN2517FD
33+
Serial.print ("sizeof (ACAN2517FDSettings): ") ;
34+
Serial.print (sizeof (ACAN2517FDSettings)) ;
35+
Serial.println (" bytes") ;
36+
Serial.println ("Configure ACAN2517FD") ;
37+
//--- For version >= 2.1.0
38+
ACAN2517FDSettings settings (ACAN2517FDSettings::OSC_4MHz10xPLL, 125UL * 1000UL, DataBitRateFactor::x1) ;
39+
//--- For version < 2.1.0
40+
// ACAN2517FDSettings settings (ACAN2517FDSettings::OSC_4MHz10xPLL, 125UL * 1000UL, ACAN2517FDSettings::DATA_BITRATE_x1) ;
41+
settings.mRequestedMode = ACAN2517FDSettings::InternalLoopBack ; // Select loopback mode
42+
//--- Default values are too high for an Arduino Uno that contains 2048 bytes of RAM: reduce them
43+
settings.mDriverTransmitFIFOSize = 1 ;
44+
settings.mDriverReceiveFIFOSize = 1 ;
45+
//--- RAM Usage
46+
Serial.print ("MCP2517FD RAM Usage: ") ;
47+
Serial.print (settings.ramUsage ()) ;
48+
Serial.println (" bytes") ;
49+
//--- Begin
50+
const uint32_t errorCode = can.begin (settings, NULL) ; // Second argument is NULL -> no interrupt service routine
51+
if (errorCode == 0) {
52+
Serial.print ("Bit Rate prescaler: ") ;
53+
Serial.println (settings.mBitRatePrescaler) ;
54+
Serial.print ("Arbitration Phase segment 1: ") ;
55+
Serial.println (settings.mArbitrationPhaseSegment1) ;
56+
Serial.print ("Arbitration Phase segment 2: ") ;
57+
Serial.println (settings.mArbitrationPhaseSegment2) ;
58+
Serial.print ("Arbitration SJW:") ;
59+
Serial.println (settings.mArbitrationSJW) ;
60+
Serial.print ("Actual Arbitration Bit Rate: ") ;
61+
Serial.print (settings.actualArbitrationBitRate ()) ;
62+
Serial.println (" bit/s") ;
63+
Serial.print ("Exact Arbitration Bit Rate ? ") ;
64+
Serial.println (settings.exactArbitrationBitRate () ? "yes" : "no") ;
65+
Serial.print ("Arbitration Sample point: ") ;
66+
Serial.print (settings.arbitrationSamplePointFromBitStart ()) ;
67+
Serial.println ("%") ;
68+
}else{
69+
Serial.print ("Configuration error 0x") ;
70+
Serial.println (errorCode, HEX) ;
71+
}
72+
}
73+
74+
//——————————————————————————————————————————————————————————————————————————————
75+
// LOOP
76+
//——————————————————————————————————————————————————————————————————————————————
77+
78+
static uint32_t gSendDate = 0 ;
79+
static uint32_t gReceiveDate = 0 ;
80+
static uint32_t gReceivedFrameCount = 0 ;
81+
static uint32_t gSentFrameCount = 0 ;
82+
83+
//——————————————————————————————————————————————————————————————————————————————
84+
85+
void loop () {
86+
can.poll () ; // No interrupt: call can.poll as often as possible
87+
CANFDMessage frame ;
88+
if (gSendDate < millis ()) {
89+
gSendDate += 1000 ;
90+
const bool ok = can.tryToSend (frame) ;
91+
if (ok) {
92+
gSentFrameCount += 1 ;
93+
Serial.print ("Sent: ") ;
94+
Serial.print (gSentFrameCount) ;
95+
}else{
96+
Serial.print ("Send failure") ;
97+
}
98+
Serial.print (", receive overflows: ") ;
99+
Serial.println (can.hardwareReceiveBufferOverflowCount ()) ;
100+
}
101+
if (gReceiveDate < millis ()) {
102+
gReceiveDate += 4567 ;
103+
while (can.available ()) {
104+
can.receive (frame) ;
105+
gReceivedFrameCount ++ ;
106+
Serial.print ("Received: ") ;
107+
Serial.println (gReceivedFrameCount) ;
108+
}
109+
}
110+
}
111+
112+
//——————————————————————————————————————————————————————————————————————————————

examples/LoopBackDemoESP32NoInt/LoopBackDemoESP32NoInt.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static uint32_t gSentFrameCount = 0 ;
105105
//——————————————————————————————————————————————————————————————————————————————
106106

107107
void loop () {
108-
can.poll () ; // Call can.poll as often as possible
108+
can.poll () ; // No interrupt: call can.poll as often as possible
109109
CANFDMessage frame ;
110110
if (gBlinkLedDate < millis ()) {
111111
gBlinkLedDate += 2000 ;

examples/LoopBackDemoTeensy3xNoInt/LoopBackDemoTeensy3xNoInt.ino

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ void setup () {
9999
//----------------------------------------------------------------------------------------------------------------------
100100

101101
static uint32_t gBlinkLedDate = 0 ;
102+
static uint32_t gReceiveDate = 0 ;
102103
static uint32_t gReceivedFrameCount = 0 ;
103104
static uint32_t gSentFrameCount = 0 ;
104105

@@ -108,7 +109,7 @@ void loop() {
108109
can.poll () ; // Call can.poll as often as possible
109110
CANFDMessage frame ;
110111
if (gBlinkLedDate < millis ()) {
111-
gBlinkLedDate += 2000 ;
112+
gBlinkLedDate += 1000 ;
112113
digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
113114
frame.len = 64 ;
114115
for (uint8_t i=0 ; i<frame.len ; i++) {
@@ -123,20 +124,23 @@ void loop() {
123124
Serial.println ("Send failure") ;
124125
}
125126
}
126-
if (can.available ()) {
127-
can.receive (frame) ;
128-
bool ok = frame.len == 64 ;
129-
if (!ok) {
130-
Serial.println ("length error") ;
127+
if (gReceiveDate < millis ()) {
128+
gReceiveDate += 4567 ;
129+
while (can.available ()) {
130+
can.receive (frame) ;
131+
bool ok = frame.len == 64 ;
132+
if (!ok) {
133+
Serial.println ("length error") ;
134+
}
135+
for (uint8_t i=0 ; (i<frame.len) && ok ; i++) {
136+
ok = frame.data [i] == i ;
137+
}
138+
gReceivedFrameCount ++ ;
139+
Serial.print ("Received: ") ;
140+
Serial.print (gReceivedFrameCount) ;
141+
Serial.print (", ") ;
142+
Serial.println (ok ? "ok" : "error") ;
131143
}
132-
for (uint8_t i=0 ; (i<frame.len) && ok ; i++) {
133-
ok = frame.data [i] == i ;
134-
}
135-
gReceivedFrameCount ++ ;
136-
Serial.print ("Received: ") ;
137-
Serial.print (gReceivedFrameCount) ;
138-
Serial.print (", ") ;
139-
Serial.println (ok ? "ok" : "error") ;
140144
}
141145
}
142146

extras/acan2517FD.pdf

17.3 KB
Binary file not shown.

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ACAN2517FD
2-
version=2.1.6
2+
version=2.1.7
33
author=Pierre Molinaro
44
maintainer=Pierre Molinaro <Pierre.Molinaro@pcmolinaro.name>
55
sentence=Driver for MCP2517FD and MCP2518FD CAN Controller (CAN FD mode)

0 commit comments

Comments
 (0)