Skip to content

Commit 0b0cadd

Browse files
authored
Merge pull request #6 from orenergy/MCP_8MHZ
Allow to set oscillator clock for 8/20MHZ modules
2 parents efd7398 + db88896 commit 0b0cadd

File tree

5 files changed

+10
-1
lines changed

5 files changed

+10
-1
lines changed

CanHacker.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ Stream *CanHacker::getInterfaceStream() {
5454
return _stream;
5555
}
5656

57+
void CanHacker::setClock(CAN_CLOCK clock){
58+
canClock = clock;
59+
}
60+
5761
CanHacker::ERROR CanHacker::connectCan() {
58-
MCP2515::ERROR error = mcp2515->setBitrate(bitrate);
62+
MCP2515::ERROR error = mcp2515->setBitrate(bitrate, canClock);
5963
if (error != MCP2515::ERROR_OK) {
6064
writeDebugStream(F("setBitrate error:\n"));
6165
writeDebugStream((int)error);

CanHacker.h

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class CanHacker {
4747

4848
CanHacker(Stream *stream, Stream *debugStream, uint8_t cs);
4949
~CanHacker();
50+
void setClock(const CAN_CLOCK clock);
5051
ERROR receiveCommand(const char *buffer, const int length);
5152
ERROR receiveCanFrame(const struct can_frame *frame);
5253
ERROR sendFrame(const struct can_frame *);
@@ -64,6 +65,7 @@ class CanHacker {
6465
static const char BEL = 7;
6566
static const uint16_t TIMESTAMP_LIMIT = 0xEA60;
6667

68+
CAN_CLOCK canClock = MCP_16MHZ;
6769
bool _timestampEnabled = false;
6870
bool _listenOnly = false;
6971
bool _loopback = false;

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Implement communication with CAN bus via MCP2515 by CanHacker (lawicel) protocol
1212
- supports filter by ID (mask + code)
1313
- interface using [Stream](https://www.arduino.cc/en/Reference/Stream): ability to work with Serial, SoftwareSerial, Ethernet and other
1414
- supported can baudrates from 10Kbps up to 1Mbps
15+
- supported modules with different oscillators (8, 16, 20 MHZ), 16 MHZ is default, use setClock if your oscillator is not 16MHZ
1516
- support [CanHacker](http://www.mictronics.de/projects/usb-can-bus/) (application for Windows)
1617
- support [CANreader](https://github.com/autowp/CANreader) (application for Android)
1718

docs/en/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Implement communication with CAN bus via MCP2515 by CanHacker (lawicel) protocol
1212
- supports filter by ID (mask + code)
1313
- interface using [Stream](https://www.arduino.cc/en/Reference/Stream): ability to work with Serial, SoftwareSerial, Ethernet and other
1414
- supported can baudrates from 10Kbps up to 1Mbps
15+
- supported modules with different oscillators (8, 16, 20 MHZ), 16 MHZ is default, use setClock if your oscillator is not 16MHZ
1516
- support [CanHacker](http://www.mictronics.de/projects/usb-can-bus/) (application for Windows)
1617
- support [CANreader](https://github.com/autowp/CANreader) (application for Android)
1718

docs/ru/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- поддержка фильтра по ID (маска + код)
1313
- интерфейс, работающий со [Stream](https://www.arduino.cc/en/Reference/Stream): возможность работы с Serial, SoftwareSerial, Ethernet и другими интерфейсами
1414
- поддерживаемые скорости can шины от 10Kbps до 1Mbps
15+
- поддерживаются модули с разными кварцами - 8, 16, 20 МГц. По умолчанию установлена частота 16 МГц, используйте функцию setClock если у вас модуль с другим кварцем.
1516
- поддержка [CanHacker](http://www.mictronics.de/projects/usb-can-bus/) (приложение для Windows)
1617
- поддержка [CANreader](https://github.com/autowp/CANreader) (приложение для Android)
1718

0 commit comments

Comments
 (0)