From 705f3be317014ba538a2cf31b7ee5483fe5eb86b Mon Sep 17 00:00:00 2001 From: woodward1 Date: Fri, 28 Feb 2014 15:57:16 -0800 Subject: [PATCH] Set SPICS pin to output in begin() It took me a while to figure this out, but the SPICS pin is not necessarily initialized to output when the arduino starts. Explicitly making it an output in the begin() method saves the library user from having to set the pin as output in their code (which they may not know they need to do, since it is not in the example code). --- mcp_can.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mcp_can.cpp b/mcp_can.cpp index 26970e2..2c32d2a 100644 --- a/mcp_can.cpp +++ b/mcp_can.cpp @@ -576,6 +576,9 @@ INT8U MCP_CAN::begin(INT8U speedset) { INT8U res; + MCP2515_UNSELECT(); /* disable chip select to begin with */ + pinMode(SPICS, OUTPUT); /* make chip select pin an output */ + SPI.begin(); res = mcp2515_init(speedset); if (res == MCP2515_OK) return CAN_OK;