Skip to content

Commit 99644e8

Browse files
author
Toni Klopfenstein
committedJan 18, 2017
Adding additional demo sketches and updating library version
1 parent ffcd67b commit 99644e8

File tree

5 files changed

+115
-3
lines changed

5 files changed

+115
-3
lines changed
 

Diff for: ‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ SparkFun CAN-Bus Arduino Library
55

66
[*SparkFun CAN-Bus Shield (DEV-13262)*](https://www.sparkfun.com/products/13262)
77

8-
<Basic description of the library.>
8+
Arduino library for using all features of the CAN-Bus Shield.
99

1010
Repository Contents
1111
-------------------

Diff for: ‎examples/CAN_Read_Demo/CAN_Read_Demo.ino

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/****************************************************************************
2+
CAN Read Demo for the SparkFun CAN Bus Shield.
3+
4+
Written by Stephen McCoy.
5+
Original tutorial available here: http://www.instructables.com/id/CAN-Bus-Sniffing-and-Broadcasting-with-Arduino
6+
Used with permission 2016. License CC By SA.
7+
8+
Distributed as-is; no warranty is given.
9+
*************************************************************************/
10+
11+
#include <Canbus.h>
12+
#include <defaults.h>
13+
#include <global.h>
14+
#include <mcp2515.h>
15+
#include <mcp2515_defs.h>
16+
17+
//********************************Setup Loop*********************************//
18+
19+
void setup() {
20+
Serial.begin(9600); // For debug use
21+
Serial.println("CAN Read - Testing receival of CAN Bus message");
22+
delay(1000);
23+
24+
if(Canbus.init(CANSPEED_500)) //Initialise MCP2515 CAN controller at the specified speed
25+
Serial.println("CAN Init ok");
26+
else
27+
Serial.println("Can't init CAN");
28+
29+
delay(1000);
30+
}
31+
32+
//********************************Main Loop*********************************//
33+
34+
void loop(){
35+
36+
tCAN message;
37+
if (mcp2515_check_message())
38+
{
39+
if (mcp2515_get_message(&message))
40+
{
41+
//if(message.id == 0x620 and message.data[2] == 0xFF) //uncomment when you want to filter
42+
//{
43+
44+
Serial.print("ID: ");
45+
Serial.print(message.id,HEX);
46+
Serial.print(", ");
47+
Serial.print("Data: ");
48+
Serial.print(message.header.length,DEC);
49+
for(int i=0;i<message.header.length;i++)
50+
{
51+
Serial.print(message.data[i],HEX);
52+
Serial.print(" ");
53+
}
54+
Serial.println("");
55+
//}
56+
}}
57+
58+
}

Diff for: ‎examples/CAN_Write_Demo/CAN_Write_Demo.ino

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/****************************************************************************
2+
CAN Write Demo for the SparkFun CAN Bus Shield.
3+
4+
Written by Stephen McCoy.
5+
Original tutorial available here: http://www.instructables.com/id/CAN-Bus-Sniffing-and-Broadcasting-with-Arduino
6+
Used with permission 2016. License CC By SA.
7+
8+
Distributed as-is; no warranty is given.
9+
*************************************************************************/
10+
11+
#include <Canbus.h>
12+
#include <defaults.h>
13+
#include <global.h>
14+
#include <mcp2515.h>
15+
#include <mcp2515_defs.h>
16+
17+
//********************************Setup Loop*********************************//
18+
19+
void setup() {
20+
Serial.begin(9600);
21+
Serial.println("CAN Write - Testing transmission of CAN Bus messages");
22+
delay(1000);
23+
24+
if(Canbus.init(CANSPEED_500)) //Initialise MCP2515 CAN controller at the specified speed
25+
Serial.println("CAN Init ok");
26+
else
27+
Serial.println("Can't init CAN");
28+
29+
delay(1000);
30+
}
31+
32+
//********************************Main Loop*********************************//
33+
34+
void loop()
35+
{
36+
tCAN message;
37+
38+
message.id = 0x631; //formatted in HEX
39+
message.header.rtr = 0;
40+
message.header.length = 8; //formatted in DEC
41+
message.data[0] = 0x40;
42+
message.data[1] = 0x05;
43+
message.data[2] = 0x30;
44+
message.data[3] = 0xFF; //formatted in HEX
45+
message.data[4] = 0x00;
46+
message.data[5] = 0x40;
47+
message.data[6] = 0x00;
48+
message.data[7] = 0x00;
49+
50+
mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), 0);
51+
mcp2515_send_message(&message);
52+
53+
delay(1000);
54+
}

Diff for: ‎library.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"type": "git",
2121
"url": "https://github.com/aaronmitti/SparkFun_CAN-Bus_Arduino_Library.git"
2222
},
23-
"version": "5.0.0",
23+
"version": "5.1.0",
2424
"frameworks": "arduino",
2525
"platforms": "*"
2626
}

Diff for: ‎library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun CAN-Bus
2-
version=5.0.0
2+
version=5.1.0
33
author=SparkFun <techsupport@sparkfun.com>, Sukking Pang <http://skpang.co.uk/>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library provies basic functionality of all hardware features on the CAN-Bus Shield.

0 commit comments

Comments
 (0)