Skip to content
This repository was archived by the owner on Dec 5, 2023. It is now read-only.

Commit 2e94ecb

Browse files
committed
Allow SPI Clock Speed Customization
- Default speed of 10MHz is not compatible with Arduino Uno - Keep default speed (fully backwards compatible), but allow user to inject a different SPI clock speed
1 parent 5d57173 commit 2e94ecb

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

mcp2515.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ const struct MCP2515::RXBn_REGS MCP2515::RXB[N_RXBUFFERS] = {
1212
{MCP_RXB1CTRL, MCP_RXB1SIDH, MCP_RXB1DATA, CANINTF_RX1IF}
1313
};
1414

15-
MCP2515::MCP2515(const uint8_t _CS)
15+
MCP2515::MCP2515(const uint8_t _CS, const uint32_t _SPI_CLOCK)
1616
{
1717
SPI.begin();
1818

1919
SPICS = _CS;
20+
SPI_CLOCK = _SPI_CLOCK;
2021
pinMode(SPICS, OUTPUT);
2122
endSPI();
2223
}

mcp2515.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ class MCP2515
424424
MCP_RXB1DATA = 0x76
425425
};
426426

427-
static const uint32_t SPI_CLOCK = 10000000; // 10MHz
427+
static const uint32_t DEFAULT_SPI_CLOCK = 10000000; // 10MHz
428428

429429
static const int N_TXBUFFERS = 3;
430430
static const int N_RXBUFFERS = 2;
@@ -443,6 +443,7 @@ class MCP2515
443443
} RXB[N_RXBUFFERS];
444444

445445
uint8_t SPICS;
446+
uint32_t SPI_CLOCK;
446447

447448
private:
448449

@@ -460,7 +461,7 @@ class MCP2515
460461
void prepareId(uint8_t *buffer, const bool ext, const uint32_t id);
461462

462463
public:
463-
MCP2515(const uint8_t _CS);
464+
MCP2515(const uint8_t _CS, const uint32_t _SPI_CLOCK = DEFAULT_SPI_CLOCK);
464465
ERROR reset(void);
465466
ERROR setConfigMode();
466467
ERROR setListenOnlyMode();

0 commit comments

Comments
 (0)