diff --git a/CanHacker.cpp b/CanHacker.cpp index d27bb59..734764a 100644 --- a/CanHacker.cpp +++ b/CanHacker.cpp @@ -54,8 +54,12 @@ Stream *CanHacker::getInterfaceStream() { return _stream; } +void CanHacker::setClock(CAN_CLOCK 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..1e79947 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 CAN_CLOCK 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; + CAN_CLOCK canClock = MCP_16MHZ; bool _timestampEnabled = false; bool _listenOnly = false; bool _loopback = false; 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)