From a1bd360907eb41fa3d00f18c46e019a4b8e57dec Mon Sep 17 00:00:00 2001 From: Anton N Date: Sun, 15 Jan 2017 22:53:06 +0300 Subject: [PATCH 1/3] Allow to change clock for MCP2515 in order to support mcp2515+TJA1080 shields and modules --- CanHacker.cpp | 6 +++++- CanHacker.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CanHacker.cpp b/CanHacker.cpp index d27bb59..4c1bc75 100644 --- a/CanHacker.cpp +++ b/CanHacker.cpp @@ -54,8 +54,12 @@ Stream *CanHacker::getInterfaceStream() { return _stream; } +void CanHacker::setClock(uint8_t clock){ + canClock = clock; +} + CanHacker::ERROR CanHacker::connectCan() { - MCP2515::ERROR error = mcp2515->setBitrate(bitrate); + MCP2515::ERROR error = mcp2515->setBitrate(bitrate, canClock); if (error != MCP2515::ERROR_OK) { writeDebugStream(F("setBitrate error:\n")); writeDebugStream((int)error); diff --git a/CanHacker.h b/CanHacker.h index cc1cf82..8ddc871 100644 --- a/CanHacker.h +++ b/CanHacker.h @@ -47,6 +47,7 @@ class CanHacker { CanHacker(Stream *stream, Stream *debugStream, uint8_t cs); ~CanHacker(); + void setClock(const uint8_t clock); ERROR receiveCommand(const char *buffer, const int length); ERROR receiveCanFrame(const struct can_frame *frame); ERROR sendFrame(const struct can_frame *); @@ -64,6 +65,7 @@ class CanHacker { static const char BEL = 7; static const uint16_t TIMESTAMP_LIMIT = 0xEA60; + uint8_t canClock = MCP_16MHZ; bool _timestampEnabled = false; bool _listenOnly = false; bool _loopback = false; From fadd3176c81fab48b474ae88ebc68c0eb5f18ccf Mon Sep 17 00:00:00 2001 From: Anton N Date: Mon, 16 Jan 2017 13:48:07 +0300 Subject: [PATCH 2/3] Use enum CAN_CLOCK --- CanHacker.cpp | 2 +- CanHacker.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CanHacker.cpp b/CanHacker.cpp index 4c1bc75..734764a 100644 --- a/CanHacker.cpp +++ b/CanHacker.cpp @@ -54,7 +54,7 @@ Stream *CanHacker::getInterfaceStream() { return _stream; } -void CanHacker::setClock(uint8_t clock){ +void CanHacker::setClock(CAN_CLOCK clock){ canClock = clock; } diff --git a/CanHacker.h b/CanHacker.h index 8ddc871..1e79947 100644 --- a/CanHacker.h +++ b/CanHacker.h @@ -47,7 +47,7 @@ class CanHacker { CanHacker(Stream *stream, Stream *debugStream, uint8_t cs); ~CanHacker(); - void setClock(const uint8_t clock); + void setClock(const CAN_CLOCK clock); ERROR receiveCommand(const char *buffer, const int length); ERROR receiveCanFrame(const struct can_frame *frame); ERROR sendFrame(const struct can_frame *); @@ -65,7 +65,7 @@ class CanHacker { static const char BEL = 7; static const uint16_t TIMESTAMP_LIMIT = 0xEA60; - uint8_t canClock = MCP_16MHZ; + CAN_CLOCK canClock = MCP_16MHZ; bool _timestampEnabled = false; bool _listenOnly = false; bool _loopback = false; From db88896ed5eaa053b534a4d5828b6f63ff0f4a3a Mon Sep 17 00:00:00 2001 From: Anton N Date: Mon, 16 Jan 2017 13:57:40 +0300 Subject: [PATCH 3/3] Update documentation --- README.md | 1 + docs/en/README.md | 1 + docs/ru/README.md | 1 + 3 files changed, 3 insertions(+) diff --git a/README.md b/README.md index 35f131d..f527547 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Implement communication with CAN bus via MCP2515 by CanHacker (lawicel) protocol - supports filter by ID (mask + code) - interface using [Stream](https://www.arduino.cc/en/Reference/Stream): ability to work with Serial, SoftwareSerial, Ethernet and other - supported can baudrates from 10Kbps up to 1Mbps +- supported modules with different oscillators (8, 16, 20 MHZ), 16 MHZ is default, use setClock if your oscillator is not 16MHZ - support [CanHacker](http://www.mictronics.de/projects/usb-can-bus/) (application for Windows) - support [CANreader](https://github.com/autowp/CANreader) (application for Android) diff --git a/docs/en/README.md b/docs/en/README.md index aaf86eb..7015117 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -12,6 +12,7 @@ Implement communication with CAN bus via MCP2515 by CanHacker (lawicel) protocol - supports filter by ID (mask + code) - interface using [Stream](https://www.arduino.cc/en/Reference/Stream): ability to work with Serial, SoftwareSerial, Ethernet and other - supported can baudrates from 10Kbps up to 1Mbps +- supported modules with different oscillators (8, 16, 20 MHZ), 16 MHZ is default, use setClock if your oscillator is not 16MHZ - support [CanHacker](http://www.mictronics.de/projects/usb-can-bus/) (application for Windows) - support [CANreader](https://github.com/autowp/CANreader) (application for Android) diff --git a/docs/ru/README.md b/docs/ru/README.md index fe44357..ca49ba9 100644 --- a/docs/ru/README.md +++ b/docs/ru/README.md @@ -12,6 +12,7 @@ - поддержка фильтра по ID (маска + код) - интерфейс, работающий со [Stream](https://www.arduino.cc/en/Reference/Stream): возможность работы с Serial, SoftwareSerial, Ethernet и другими интерфейсами - поддерживаемые скорости can шины от 10Kbps до 1Mbps +- поддерживаются модули с разными кварцами - 8, 16, 20 МГц. По умолчанию установлена частота 16 МГц, используйте функцию setClock если у вас модуль с другим кварцем. - поддержка [CanHacker](http://www.mictronics.de/projects/usb-can-bus/) (приложение для Windows) - поддержка [CANreader](https://github.com/autowp/CANreader) (приложение для Android)