Created
November 30, 2012 19:29
-
-
Save rechargecar/4177971 to your computer and use it in GitHub Desktop.
MCP2515 basic setup with Macchina
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> // Arduino SPI Library | |
#include <MCP2515.h> | |
// Pin definitions specific to how the MCP2515 is wired up. | |
#define CS_PIN 85 | |
#define RESET_PIN 7 | |
#define INT_PIN 84 | |
// Create CAN object with pins as defined | |
MCP2515 CAN(CS_PIN, RESET_PIN, INT_PIN); | |
void setup() { | |
Serial.begin(115200); | |
Serial.println("Initializing ..."); | |
// Set up SPI Communication | |
// dataMode can be SPI_MODE0 or SPI_MODE3 only for MCP2515 | |
SPI.setClockDivider(SPI_CLOCK_DIV2); | |
SPI.setDataMode(SPI_MODE0); | |
SPI.setBitOrder(MSBFIRST); | |
SPI.begin(); | |
// Initialise MCP2515 CAN controller at the specified speed and clock frequency | |
// In this case 125kbps with a 16MHz oscillator | |
// (Note: This is the oscillator attached to the MCP2515, not the Arduino oscillaltor) | |
if(CAN.Init(250,16)) | |
{ | |
Serial.println("MCP2515 Init OK ..."); | |
} else { | |
Serial.println("MCP2515 Init Failed ..."); | |
} | |
Serial.println("Ready ..."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment