Skip to content

Commit

Permalink
Merge pull request #78 from RemoraCarbon/74
Browse files Browse the repository at this point in the history
Allow SPI Clock Speed Customization
  • Loading branch information
autowp authored Jan 27, 2022
2 parents 5d57173 + 2e94ecb commit 4d0982e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion mcp2515.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ const struct MCP2515::RXBn_REGS MCP2515::RXB[N_RXBUFFERS] = {
{MCP_RXB1CTRL, MCP_RXB1SIDH, MCP_RXB1DATA, CANINTF_RX1IF}
};

MCP2515::MCP2515(const uint8_t _CS)
MCP2515::MCP2515(const uint8_t _CS, const uint32_t _SPI_CLOCK)
{
SPI.begin();

SPICS = _CS;
SPI_CLOCK = _SPI_CLOCK;
pinMode(SPICS, OUTPUT);
endSPI();
}
Expand Down
5 changes: 3 additions & 2 deletions mcp2515.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ class MCP2515
MCP_RXB1DATA = 0x76
};

static const uint32_t SPI_CLOCK = 10000000; // 10MHz
static const uint32_t DEFAULT_SPI_CLOCK = 10000000; // 10MHz

static const int N_TXBUFFERS = 3;
static const int N_RXBUFFERS = 2;
Expand All @@ -443,6 +443,7 @@ class MCP2515
} RXB[N_RXBUFFERS];

uint8_t SPICS;
uint32_t SPI_CLOCK;

private:

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

public:
MCP2515(const uint8_t _CS);
MCP2515(const uint8_t _CS, const uint32_t _SPI_CLOCK = DEFAULT_SPI_CLOCK);
ERROR reset(void);
ERROR setConfigMode();
ERROR setListenOnlyMode();
Expand Down

0 comments on commit 4d0982e

Please sign in to comment.