Skip to content

Commit e3fceb2

Browse files
committed
Adding sketch for CAN1Read (reading from CAN1).
1 parent a99256b commit e3fceb2

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**************************************************************************************
2+
* INCLUDE
3+
**************************************************************************************/
4+
5+
#include <CAN.h>
6+
7+
/**************************************************************************************
8+
* SETUP/LOOP
9+
**************************************************************************************/
10+
11+
void setup()
12+
{
13+
Serial.begin(115200);
14+
while (!Serial) { }
15+
16+
/* You need to enable the CAN transceiver
17+
* by commenting in below code when using
18+
* a Portenta H33 on a Portenta Max Carrier.
19+
* Note: Only CAN1 is available on the Portenta
20+
* Max Carrier's RJ10 CAN connector.
21+
*/
22+
#if (PIN_CAN1_STBY >= 0)
23+
pinMode(PIN_CAN1_STBY, OUTPUT);
24+
digitalWrite(PIN_CAN1_STBY, LOW);
25+
#endif
26+
27+
if (!CAN1.begin(CanBitRate::BR_250k))
28+
{
29+
Serial.println("CAN.begin(...) failed.");
30+
for (;;) {}
31+
}
32+
}
33+
34+
void loop()
35+
{
36+
if (CAN1.available())
37+
{
38+
CanMsg const msg = CAN1.read();
39+
Serial.println(msg);
40+
}
41+
}

0 commit comments

Comments
 (0)