Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Arduino MCP2515 CAN interface library
[![Build Status](https://travis-ci.org/autowp/arduino-mcp2515.svg?branch=master)](https://travis-ci.org/autowp/arduino-mcp2515)

<br>
CAN-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 gives 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.
CAN-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 gives your Arduino/Seeeduino CAN-BUS capability. 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.

- Implements CAN V2.0B at up to 1 Mb/s
- SPI Interface up to 10 MHz
Expand Down Expand Up @@ -58,9 +58,10 @@ To create connection with MCP2515 provide pin number where SPI CS is connected (

The available modes are listed as follows:
```C++
mcp2515.setNormalMode();
mcp2515.setLoopbackMode();
mcp2515.setListenOnlyMode();
mcp2515.setNormalMode(); // sends and receives data normally, sends acknowledgments to other nodes, when sending data, requires an acknowledgment from another node that the message was received or else, the 2515 will autonomously keep sending the same data
mcp2515.setNormalOneShotMode(); // sends and receives data normally, sends acknoledgements to other nodes that their message was received, when sending data, does not require an acknowledgement from another node that the message was received.
mcp2515.setLoopbackMode(); // data sent is immediately received and is not written to the bus, does not send acknowledgements
mcp2515.setListenOnlyMode(); // does not send data, only receives data, does not send acknowledgements
```
The available baudrates are listed as follows:
```C++
Expand Down Expand Up @@ -183,7 +184,7 @@ MCP2515::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.
You can choise one of two method to receive: interrupt-based and polling
You can choose one of two method to receive: interrupt-based and polling
Example of poll read
Expand Down Expand Up @@ -236,7 +237,7 @@ void loop() {

## Set Receive Mask and Filter

There 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.
There 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.

We provide two functions for you to utilize these mask and filter registers. They are:

Expand Down
6 changes: 3 additions & 3 deletions can.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ typedef __u32 canid_t;
#define CAN_MAX_DLEN 8

struct can_frame {
canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
__u8 can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */
__u8 data[CAN_MAX_DLEN] __attribute__((aligned(8)));
canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
__u8 can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */
alignas(8) __u8 data[CAN_MAX_DLEN];
};

#endif /* CAN_H_ */
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=autowp-mcp2515
version=1.0.3
version=1.3.1
author=autowp <autowp@gmail.com>
maintainer=autowp <autowp@gmail.com>
sentence=Arduino MCP2515 CAN interface library
paragraph=This library with CAN-BUS Shield gives 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.
paragraph=This library with CAN-BUS Shield gives your Arduino/Seeeduino CAN-BUS capability. 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.
category=Communication
url=https://github.com/autowp/arduino-mcp2515
includes=mcp2515.h
Expand Down
7 changes: 6 additions & 1 deletion mcp2515.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,14 @@ MCP2515::ERROR MCP2515::setNormalMode()
return setMode(CANCTRL_REQOP_NORMAL);
}

MCP2515::ERROR MCP2515::setNormalOneShotMode()
{
return setMode(CANCTRL_REQOP_OSM);
}

MCP2515::ERROR MCP2515::setMode(const CANCTRL_REQOP_MODE mode)
{
modifyRegister(MCP_CANCTRL, CANCTRL_REQOP, mode);
modifyRegister(MCP_CANCTRL, CANCTRL_REQOP | CANCTRL_OSM, mode);

unsigned long endTime = millis() + 10;
bool modeMatch = false;
Expand Down
2 changes: 2 additions & 0 deletions mcp2515.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ class MCP2515

enum /*class*/ CANCTRL_REQOP_MODE : uint8_t {
CANCTRL_REQOP_NORMAL = 0x00,
CANCTRL_REQOP_OSM = 0x08,
CANCTRL_REQOP_SLEEP = 0x20,
CANCTRL_REQOP_LOOPBACK = 0x40,
CANCTRL_REQOP_LISTENONLY = 0x60,
Expand Down Expand Up @@ -473,6 +474,7 @@ class MCP2515
ERROR setSleepMode();
ERROR setLoopbackMode();
ERROR setNormalMode();
ERROR setNormalOneShotMode();
ERROR setClkOut(const CAN_CLKOUT divisor);
ERROR setBitrate(const CAN_SPEED canSpeed);
ERROR setBitrate(const CAN_SPEED canSpeed, const CAN_CLOCK canClock);
Expand Down