File tree Expand file tree Collapse file tree 5 files changed +414
-5
lines changed
Expand file tree Collapse file tree 5 files changed +414
-5
lines changed Original file line number Diff line number Diff line change 1+ // demo: Use TX2RTS as digital input
2+ // adlerweb, 2017-06-24
3+ #include < SPI.h>
4+ #include " mcp_can.h"
5+
6+ #define SPI_CS_PIN 10
7+
8+ MCP_CAN CAN (SPI_CS_PIN); // Set CS pin
9+
10+
11+ void setup ()
12+ {
13+ Serial.begin (115200 );
14+
15+ while (CAN_OK != CAN.begin (CAN_500KBPS)) // init can bus : baudrate = 500k
16+ {
17+ Serial.println (" CAN init failed, retry" );
18+ delay (100 );
19+ }
20+ Serial.println (" CAN init ok" );
21+
22+ if (CAN.pinMode (MCP_TX2RTS, MCP_PIN_IN))
23+ {
24+ Serial.println (" TX2RTS is now an input" );
25+ }
26+ else
27+ {
28+ Serial.println (" Could not switch TX2RTS" );
29+ }
30+ }
31+
32+ void loop ()
33+ {
34+ Serial.print (" TX2RTS is currently " );
35+ Serial.println (CAN.digitalRead (MCP_TX2RTS));
36+ delay (500 );
37+ }
38+
39+ /* ********************************************************************************************************
40+ END FILE
41+ *********************************************************************************************************/
Original file line number Diff line number Diff line change 1+ // demo: Use RX0BF and RX1BF as digital outputs
2+ // adlerweb, 2017-06-24
3+ #include < SPI.h>
4+ #include " mcp_can.h"
5+
6+ #define SPI_CS_PIN 10
7+
8+ MCP_CAN CAN (SPI_CS_PIN); // Set CS pin
9+
10+
11+ void setup ()
12+ {
13+ Serial.begin (115200 );
14+
15+ while (CAN_OK != CAN.begin (CAN_500KBPS)) // init can bus : baudrate = 500k
16+ {
17+ Serial.println (" CAN init failed, retry" );
18+ delay (100 );
19+ }
20+ Serial.println (" CAN init ok" );
21+
22+ if (CAN.pinMode (MCP_RX0BF, MCP_PIN_OUT))
23+ {
24+ Serial.println (" RX0BF is now an output" );
25+ }
26+ else
27+ {
28+ Serial.println (" Could not switch RX0BF" );
29+ }
30+
31+ if (CAN.pinMode (MCP_RX1BF, MCP_PIN_OUT))
32+ {
33+ Serial.println (" RX1BF is now an output" );
34+ }
35+ else
36+ {
37+ Serial.println (" Could not switch RX1BF" );
38+ }
39+ }
40+
41+ void loop ()
42+ {
43+ Serial.println (" 10" );
44+ CAN.digitalWrite (MCP_RX0BF, HIGH);
45+ CAN.digitalWrite (MCP_RX1BF, LOW);
46+ delay (500 );
47+ Serial.println (" 01" );
48+ CAN.digitalWrite (MCP_RX0BF, LOW);
49+ CAN.digitalWrite (MCP_RX1BF, HIGH);
50+ delay (500 );
51+ }
52+
53+ /* ********************************************************************************************************
54+ END FILE
55+ *********************************************************************************************************/
You can’t perform that action at this time.
0 commit comments