diff --git a/README.md b/README.md index 399ae7d..fa4f816 100644 --- a/README.md +++ b/README.md @@ -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)
-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 @@ -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++ @@ -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 @@ -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: diff --git a/can.h b/can.h index 96175b1..4735f81 100644 --- a/can.h +++ b/can.h @@ -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_ */ diff --git a/library.properties b/library.properties index c963a7e..3d61215 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=autowp-mcp2515 -version=1.0.3 +version=1.3.1 author=autowp maintainer=autowp 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 diff --git a/mcp2515.cpp b/mcp2515.cpp index b942b55..57846ad 100644 --- a/mcp2515.cpp +++ b/mcp2515.cpp @@ -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; diff --git a/mcp2515.h b/mcp2515.h index 48e5d57..3d1509f 100644 --- a/mcp2515.h +++ b/mcp2515.h @@ -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, @@ -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);