Skip to content

Commit

Permalink
Update CAN_receive.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
coryjfowler authored Aug 15, 2016
1 parent e5d5dfc commit 1db096f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions examples/CAN_receive/CAN_receive.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
char msgString[128]; // Array to store serial string

#define CAN0_INT 2 // Set INT to pin 2
MCP_CAN CAN0(10); // Set CS to pin 10


Expand All @@ -16,19 +18,21 @@ void setup()
Serial.begin(115200);

// Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK) Serial.println("MCP2515 Initialized Successfully!");
else Serial.println("Error Initializing MCP2515...");
if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK)
Serial.println("MCP2515 Initialized Successfully!");
else
Serial.println("Error Initializing MCP2515...");

CAN0.setMode(MCP_NORMAL); // Set operation mode to normal so the MCP2515 sends acks to received data.

pinMode(2, INPUT); // Setting pin 2 for /INT input
pinMode(CAN0_INT, INPUT); // Configuring pin for /INT input

Serial.println("MCP2515 Library Receive Example...");
}

void loop()
{
if(!digitalRead(2)) // If pin 2 is low, read receive buffer
if(!digitalRead(CAN0_INT)) // If CAN0_INT pin is low, read receive buffer
{
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)

Expand Down

0 comments on commit 1db096f

Please sign in to comment.