AptoFun CAN-BUS Shield MCP2515 w Teensy 3.2

Status
Not open for further replies.
I searched MCP2515 with Google and found this and this, it should help.

This library seems to have examples for t3.x so should be further help.
 
Last edited:
Thank y ou for the response. I read the first link which is why I signed up here. The second is for an arduino. I dont think that the arduino has a can bus controller does it?

I am trying to understand how to wire these 3 boards. The code I want to run is here:

https://github.com/ttlappalainen/NMEA2000

The readme reccomends a teensy 3.2 for low power consumption

https://github.com/ttlappalainen/NMEA2000/blob/master/Documents/Connecting_hardware_to_NMEA2000.pdf

I am not clear how to connect the 3 boards
 
How do i connect these to a teensy 3.2 please?
Here is the code that worked succesfully for me with that particular CAN board:
Code:
// https://en.wikipedia.org/wiki/CAN_bus
// library needed: https://github.com/autowp/arduino-mcp2515

// Signal     Teensy pins   MCP2515 pins
// Vcc        5V            VCC
// GND        GND           GND
// SPI SS     10            CS
// SPI MOSI   11            SO
// SPI MISO   12            SI 
// SPI SCK    13            SCK
// CANL       -             L
// CANH       -             H

#include <SPI.h>
#include <mcp2515.h>

struct can_frame canMsg1;
struct can_frame canMsg2;
MCP2515 mcp2515(10);


void setup() {
  canMsg1.can_id  = 0x0F6;
  canMsg1.can_dlc = 8;
  canMsg1.data[0] = 0x8E;
  canMsg1.data[1] = 0x87;
  canMsg1.data[2] = 0x32;
  canMsg1.data[3] = 0xFA;
  canMsg1.data[4] = 0x26;
  canMsg1.data[5] = 0x8E;
  canMsg1.data[6] = 0xBE;
  canMsg1.data[7] = 0x86;

  canMsg2.can_id  = 0x036;
  canMsg2.can_dlc = 8;
  canMsg2.data[0] = 0x0E;
  canMsg2.data[1] = 0x00;
  canMsg2.data[2] = 0x00;
  canMsg2.data[3] = 0x08;
  canMsg2.data[4] = 0x01;
  canMsg2.data[5] = 0x00;
  canMsg2.data[6] = 0x00;
  canMsg2.data[7] = 0xA0;
  
  while (!Serial);
  Serial.begin(115200);
  
  mcp2515.reset();
  mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ);
  mcp2515.setNormalMode();
  
  Serial.println("Example: Write to CAN");
}

void loop() {
  mcp2515.sendMessage(&canMsg1);
  mcp2515.sendMessage(&canMsg2);

  Serial.println("Messages sent");
  
  delay(100);
}

Paul

Edit: this works only for T3.2 since the MCP2515 module has to be powered by 5V. T3.2 is 5V tolerant, T4.x is not.
 
Last edited:
Status
Not open for further replies.
Back
Top