Skip to content

Commit e771551

Browse files
committed
Merge remote-tracking branch 'upstream/master' into readme-pr
2 parents 4eb5fdd + 43521de commit e771551

File tree

5 files changed

+414
-5
lines changed

5 files changed

+414
-5
lines changed

examples/gpioRead/gpioRead.ino

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
*********************************************************************************************************/

examples/gpioWrite/gpioWrite.ino

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
*********************************************************************************************************/

0 commit comments

Comments
 (0)