source: rtos_arduino/trunk/arduino_lib/libraries/NcesCan/README.md@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 5.6 KB
Line 
1CAN BUS Shield
2---------------------------------------------------------
3[![CAN BUS Shield](http://www.seeedstudio.com/depot/images/1130300211.jpg)](http://www.seeedstudio.com/depot/CANBUS-Shield-p-2256.html?cPath=19_88)
4
5
6
7<br>
8CAN-BUS is a common industrial bus because of its long travel distance, medium communication speed and high reliability. It is commonly found on modern machine tools and as an automotive diagnostic bus. This CAN-BUS Shield adopts MCP2515 CAN Bus controller with SPI interface and MCP2551 CAN transceiver to give your Arduino/Seeeduino CAN-BUS capibility. With an OBD-II converter cable added on and the OBD-II library imported, you are ready to build an onboard diagnostic device or data logger.
9
10- Implements CAN V2.0B at up to 1 Mb/s
11- SPI Interface up to 10 MHz
12- Standard (11 bit) and extended (29 bit) data and remote frames
13- Two receive buffers with prioritized message storage
14- Industrial standard 9 pin sub-D connector
15- Two LED indicators
16
17
18
19<br>
20# Usage:
21
22
23
24## 1. Set the BaudRate
25
26This function is used to initialize the baudrate of the CAN Bus system.
27
28The available baudrates are listed as follws:
29
30 #define CAN_5KBPS 1
31 #define CAN_10KBPS 2
32 #define CAN_20KBPS 3
33 #define CAN_31K25BPS 4
34 #define CAN_33KBPS 5
35 #define CAN_40KBPS 6
36 #define CAN_50KBPS 7
37 #define CAN_80KBPS 8
38 #define CAN_83K3BPS 9
39 #define CAN_95KBPS 10
40 #define CAN_100KBPS 11
41 #define CAN_125KBPS 12
42 #define CAN_200KBPS 13
43 #define CAN_250KBPS 14
44 #define CAN_500KBPS 15
45 #define CAN_1000KBPS 16
46
47
48<br>
49
50##2. Set Receive Mask and Filter
51
52There are 2 receive mask registers and 5 filter registers on the controller chip that guarantee you get data from the target device. They are useful especially in a large network consisting of numerous nodes.
53
54We provide two functions for you to utilize these mask and filter registers. They are:
55
56 init_Mask(unsigned char num, unsigned char ext, unsigned char ulData);
57 init_Filt(unsigned char num, unsigned char ext, unsigned char ulData);
58
59**num** represents which register to use. You can fill 0 or 1 for mask and 0 to 5 for filter.
60
61**ext** represents the status of the frame. 0 means it's a mask or filter for a standard frame. 1 means it's for a extended frame.
62
63**ulData** represents the content of the mask of filter.
64
65
66
67<br>
68## 3. Check Receive
69The MCP2515 can operate in either a polled mode, where the software checks for a received frame, or using additional pins to signal that a frame has been received or transmit completed. Use the following function to poll for received frames.
70
71 INT8U MCP_CAN::checkReceive(void);
72
73The function will return 1 if a frame arrives, and 0 if nothing arrives.
74
75
76
77<br>
78## 4. Get CAN ID
79
80When some data arrive, you can use the following function to get the CAN ID of the "send" node.
81
82 INT32U MCP_CAN::getCanId(void);
83
84
85
86<br>
87## 5. Send Data
88
89 CAN.sendMsgBuf(INT8U id, INT8U ext, INT8U len, data_buf);
90
91This is a function to send data onto the bus. In which:
92
93**id** represents where the data come from.
94
95**ext** represents the status of the frame. '0' means standard frame. '1' means extended frame.
96
97**len** represents the length of this frame.
98
99**data_buf** is the content of this message.
100
101For example, In the 'send' example, we have:
102
103<pre>
104unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
105
106CAN.sendMsgBuf(0x00, 0, 8, stmp); //send out the message 'stmp' to the bus and tell other devices this is a standard frame from 0x00.
107</pre>
108
109
110
111<br>
112## 6. Receive Data
113
114The following function is used to receive data on the 'receive' node:
115
116 CAN.readMsgBuf(unsigned char len, unsigned char buf);
117
118In conditions that masks and filters have been set. This function can only get frames that meet the requirements of masks and filters.
119
120**len** represents the data length.
121
122**buf** is where you store the data.
123
124<br>
125## 7. Check additional flags
126
127When frame is received you may check whether it was remote request and whether it was an extended (29bit) frame.
128
129 CAN.isRemoteRequest();
130 CAN.isExtendedFrame();
131
132**return value** is '0' for a negative response and '1' for a positive
133
134
135<br>
136For more information, please refer to [wiki page](http://www.seeedstudio.com/wiki/CAN-BUS_Shield).
137
138
139----
140
141This software is written by loovee ([luweicong@seeed.cc](luweicong@seeed.cc "luweicong@seeed.cc")) for seeed studio<br>
142and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt for more information.<br>
143
144Contributing to this software is warmly welcomed. You can do this basically by<br>
145[forking](https://help.github.com/articles/fork-a-repo), committing modifications and then [pulling requests](https://help.github.com/articles/using-pull-requests) (follow the links above<br>
146for operating guide). Adding change log and your contact into file header is encouraged.<br>
147Thanks for your contribution.
148
149Seeed Studio is an open hardware facilitation company based in Shenzhen, China. <br>
150Benefiting from local manufacture power and convenient global logistic system, <br>
151we integrate resources to serve new era of innovation. Seeed also works with <br>
152global distributors and partners to push open hardware movement.<br>
153
154
155
156
157
158
159[![Analytics](https://ga-beacon.appspot.com/UA-46589105-3/CAN_BUS_Shield)](https://github.com/igrigorik/ga-beacon)
160
161
162<script>
163 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
164 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
165 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
166 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
167
168 ga('create', 'UA-65075738-1', 'auto');
169 ga('send', 'pageview');
170
171</script>
Note: See TracBrowser for help on using the repository browser.