diff --git a/src/mcp2515_can.cpp b/src/mcp2515_can.cpp index 9bfbc46..32522ff 100644 --- a/src/mcp2515_can.cpp +++ b/src/mcp2515_can.cpp @@ -1058,8 +1058,8 @@ byte mcp2515_can::mcp2515_getNextFreeTXBuf(byte* txbuf_n) { // get ** Function name: begin ** Descriptions: init can and set speed *********************************************************************************************************/ -byte mcp2515_can::begin(uint32_t speedset, const byte clockset) { - pSPI->begin(); +byte mcp2515_can::begin(uint32_t speedset, const byte clockset, const bool _initSPI) { + if (_initSPI) pSPI->begin(); byte res = mcp2515_init((byte)speedset, clockset); return ((res == MCP2515_OK) ? CAN_OK : CAN_FAILINIT); diff --git a/src/mcp2515_can.h b/src/mcp2515_can.h index a95dde0..94690d6 100644 --- a/src/mcp2515_can.h +++ b/src/mcp2515_can.h @@ -69,7 +69,7 @@ class mcp2515_can : public MCP_CAN { return MCP_N_TXBUFFERS - 1; // read index of last tx buffer } - virtual byte begin(uint32_t speedset, const byte clockset = MCP_16MHz); // init can + virtual byte begin(uint32_t speedset, const byte clockset = MCP_16MHz, const bool _initSPI = true); // init can virtual byte init_Mask(byte num, byte ext, unsigned long ulData); // init Masks virtual byte init_Filt(byte num, byte ext, unsigned long ulData); // init filters virtual void setSleepWakeup(byte enable); // Enable or disable the wake up interrupt (If disabled the MCP2515 will not be woken up by CAN bus activity, making it send only) diff --git a/src/mcp2518fd_can.cpp b/src/mcp2518fd_can.cpp index f2968c5..29f4159 100644 --- a/src/mcp2518fd_can.cpp +++ b/src/mcp2518fd_can.cpp @@ -55,8 +55,8 @@ uint16_t DRV_CANFDSPI_CalculateCRC16(uint8_t *data, uint16_t size) { ** Function name: begin ** Descriptions: init can and set speed *********************************************************************************************************/ -byte mcp2518fd::begin(uint32_t speedset, const byte clockset) { - SPI.begin(); +byte mcp2518fd::begin(uint32_t speedset, const byte clockset, const bool _initSPI) { + if (_initSPI) pSPI->begin(); /* compatible layer translation */ speedset = bittime_compat_to_mcp2518fd(speedset); diff --git a/src/mcp2518fd_can.h b/src/mcp2518fd_can.h index 181da31..1d1e14e 100644 --- a/src/mcp2518fd_can.h +++ b/src/mcp2518fd_can.h @@ -112,7 +112,8 @@ class mcp2518fd : public MCP_CAN { * or fill by CANFD::BITRATE() */ virtual byte begin(uint32_t speedset, - const byte clockset = MCP2518FD_40MHz); // init can + const byte clockset = MCP2518FD_40MHz, + const bool _initSPI = true); // init can virtual byte init_Mask(byte num, byte ext, unsigned long ulData); virtual byte init_Filt(byte num, byte ext, unsigned long ulData); // init filters diff --git a/src/mcp_can.h b/src/mcp_can.h index c46e8a8..c4d502c 100644 --- a/src/mcp_can.h +++ b/src/mcp_can.h @@ -76,7 +76,7 @@ class MCP_CAN * speedset be in MCP_BITTIME_SETUP * clockset be in MCP_CLOCK_T */ - virtual byte begin(uint32_t speedset, const byte clockset) = 0; // init can + virtual byte begin(uint32_t speedset, const byte clockset, const bool _initSPI = true) = 0; // init can virtual byte init_Mask(byte num, byte ext, unsigned long ulData) = 0; // init Masks virtual byte init_Filt(byte num, byte ext, unsigned long ulData) = 0; // init filters virtual void setSleepWakeup(byte enable) = 0; // Enable or disable the wake up interrupt