Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: AptoFun CAN-BUS Shield MCP2515 w Teensy 3.2

  1. #1
    Junior Member
    Join Date
    Nov 2021
    Posts
    2

    AptoFun CAN-BUS Shield MCP2515 w Teensy 3.2

    https://www.amazon.it/gp/product/B08...?ie=UTF8&psc=1

    How do i connect these to a teensy 3.2 please?

    Yes newb )

  2. #2
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    465
    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 by BriComp; 11-24-2021 at 08:33 PM.

  3. #3
    Junior Member
    Join Date
    Nov 2021
    Posts
    2
    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/NME...o_NMEA2000.pdf

    I am not clear how to connect the 3 boards

  4. #4
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    697
    Quote Originally Posted by NullNull View Post
    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 by PaulS; 11-25-2021 at 07:06 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •