Skip to content

Commit

Permalink
Merge pull request #6 from orenergy/MCP_8MHZ
Browse files Browse the repository at this point in the history
Allow to set oscillator clock for 8/20MHZ modules
  • Loading branch information
autowp committed Jan 16, 2017
2 parents efd7398 + db88896 commit 0b0cadd
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CanHacker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions CanHacker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions docs/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions docs/ru/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 0b0cadd

Please sign in to comment.