mirror of
https://github.com/Seeed-Studio/Seeed_Arduino_CAN.git
synced 2026-09-15 11:03:48 +00:00
Update README.md
This commit is contained in:
@@ -27,22 +27,24 @@ This function is used to initialize the baudrate of the CAN Bus system.
|
||||
|
||||
The available baudrates are listed as follws:
|
||||
|
||||
#define CAN_5KBPS 1
|
||||
#define CAN_10KBPS 2
|
||||
#define CAN_20KBPS 3
|
||||
#define CAN_31K25BPS 4
|
||||
#define CAN_33KBPS 5
|
||||
#define CAN_40KBPS 6
|
||||
#define CAN_50KBPS 7
|
||||
#define CAN_80KBPS 8
|
||||
#define CAN_83K3BPS 9
|
||||
#define CAN_95KBPS 10
|
||||
#define CAN_100KBPS 11
|
||||
#define CAN_125KBPS 12
|
||||
#define CAN_200KBPS 13
|
||||
#define CAN_250KBPS 14
|
||||
#define CAN_500KBPS 15
|
||||
#define CAN_1000KBPS 16
|
||||
enum CAN_SPEED {
|
||||
CAN_5KBPS,
|
||||
CAN_10KBPS,
|
||||
CAN_20KBPS,
|
||||
CAN_31K25BPS,
|
||||
CAN_33KBPS,
|
||||
CAN_40KBPS,
|
||||
CAN_50KBPS,
|
||||
CAN_80KBPS,
|
||||
CAN_83K3BPS,
|
||||
CAN_95KBPS,
|
||||
CAN_100KBPS,
|
||||
CAN_125KBPS,
|
||||
CAN_200KBPS,
|
||||
CAN_250KBPS,
|
||||
CAN_500KBPS,
|
||||
CAN_1000KBPS
|
||||
};
|
||||
|
||||
|
||||
<br>
|
||||
@@ -75,62 +77,52 @@ The function will return 1 if a frame arrives, and 0 if nothing arrives.
|
||||
|
||||
|
||||
<br>
|
||||
## 4. Get CAN ID
|
||||
## 4. Send Data
|
||||
|
||||
When some data arrive, you can use the following function to get the CAN ID of the "send" node.
|
||||
MCP_CAN::ERROR sendMessage(const MCP_CAN::TXBn txbn, const struct can_frame *frame);
|
||||
MCP_CAN::ERROR sendMessage(const struct can_frame *frame);
|
||||
|
||||
INT32U MCP_CAN::getCanId(void);
|
||||
|
||||
|
||||
|
||||
<br>
|
||||
## 5. Send Data
|
||||
|
||||
CAN.sendMsgBuf(INT8U id, INT8U ext, INT8U len, data_buf);
|
||||
|
||||
This is a function to send data onto the bus. In which:
|
||||
|
||||
**id** represents where the data come from.
|
||||
|
||||
**ext** represents the status of the frame. '0' means standard frame. '1' means extended frame.
|
||||
|
||||
**len** represents the length of this frame.
|
||||
|
||||
**data_buf** is the content of this message.
|
||||
This is a function to send data onto the bus.
|
||||
|
||||
For example, In the 'send' example, we have:
|
||||
|
||||
<pre>
|
||||
unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
<pre>
|
||||
struct can_frame frame;
|
||||
frame.can_id = 0x000;
|
||||
frame.can_dlc = 4;
|
||||
frame.data[0] = 0xFF;
|
||||
frame.data[1] = 0xFF;
|
||||
frame.data[2] = 0xFF;
|
||||
frame.data[3] = 0xFF;
|
||||
|
||||
CAN.sendMsgBuf(0x00, 0, 8, stmp); //send out the message 'stmp' to the bus and tell other devices this is a standard frame from 0x00.
|
||||
CAN.sendMessage(&frame); //send out the message to the bus and tell other devices this is a standard frame from 0x00.
|
||||
</pre>
|
||||
|
||||
<pre>
|
||||
struct can_frame frame;
|
||||
frame.can_id = 0x12345678 | CAN_EFF_MASK;
|
||||
frame.can_dlc = 2;
|
||||
frame.data[0] = 0xFF;
|
||||
frame.data[1] = 0xFF;
|
||||
|
||||
CAN.sendMessage(MCP_CAN::TXB1, &frame); // send out the message to the bus using second TX buffer and tell other devices this is a extended frame from 0x12345678.
|
||||
</pre>
|
||||
|
||||
|
||||
|
||||
<br>
|
||||
## 6. Receive Data
|
||||
## 5. Receive Data
|
||||
|
||||
The following function is used to receive data on the 'receive' node:
|
||||
|
||||
CAN.readMsgBuf(unsigned char len, unsigned char buf);
|
||||
MCP_CAN::ERROR readMessage(const MCP_CAN::RXBn rxbn, struct can_frame *frame);
|
||||
MCP_CAN::ERROR readMessage(struct can_frame *frame);
|
||||
|
||||
In conditions that masks and filters have been set. This function can only get frames that meet the requirements of masks and filters.
|
||||
|
||||
**len** represents the data length.
|
||||
|
||||
**buf** is where you store the data.
|
||||
|
||||
<br>
|
||||
## 7. Check additional flags
|
||||
|
||||
When frame is received you may check whether it was remote request and whether it was an extended (29bit) frame.
|
||||
|
||||
CAN.isRemoteRequest();
|
||||
CAN.isExtendedFrame();
|
||||
|
||||
**return value** is '0' for a negative response and '1' for a positive
|
||||
## 6. Examples
|
||||
|
||||
Example implementation of CanHacker (lawicel) protocol based device: [https://github.com/autowp/can-usb](https://github.com/autowp/can-usb)
|
||||
|
||||
<br>
|
||||
For more information, please refer to [wiki page](http://www.seeedstudio.com/wiki/CAN-BUS_Shield).
|
||||
@@ -138,8 +130,9 @@ For more information, please refer to [wiki page](http://www.seeedstudio.com/wik
|
||||
|
||||
----
|
||||
|
||||
This software is written by loovee ([luweicong@seeed.cc](luweicong@seeed.cc "luweicong@seeed.cc")) for seeed studio<br>
|
||||
and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt for more information.<br>
|
||||
This software is written by loovee ([luweicong@seeed.cc](luweicong@seeed.cc "luweicong@seeed.cc")) for seeed studio,<br>
|
||||
Updated by Dmitry ([https://github.com/autowp](https://github.com/autowp "https://github.com/autowp"))<br>
|
||||
and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check [LICENSE.md](LICENSE.md) for more information.<br>
|
||||
|
||||
Contributing to this software is warmly welcomed. You can do this basically by<br>
|
||||
[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>
|
||||
@@ -150,22 +143,3 @@ Seeed Studio is an open hardware facilitation company based in Shenzhen, China.
|
||||
Benefiting from local manufacture power and convenient global logistic system, <br>
|
||||
we integrate resources to serve new era of innovation. Seeed also works with <br>
|
||||
global distributors and partners to push open hardware movement.<br>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[](https://github.com/igrigorik/ga-beacon)
|
||||
|
||||
|
||||
<script>
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||
|
||||
ga('create', 'UA-65075738-1', 'auto');
|
||||
ga('send', 'pageview');
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user