vtl / volvo-cem-cracker

Volvo central electronic module pin cracker via OBD for P1, P2 and P3 platforms
GNU General Public License v3.0
106 stars 46 forks source link

Hoping you could add support for Teensy LC #21

Open KennethMcNutt opened 6 months ago

KennethMcNutt commented 6 months ago

To use the MCP2551 transceiver with a Teensy LC microcontroller, you can follow these steps:

Step 1: Wiring Connect the MCP2551 to your Teensy LC as follows:

Step 2: Install Libraries In your Arduino IDE, install the "MCP_CAN_lib" by visiting "Sketch -> Include Library -> Manage Libraries", then search for and install the library.

Step 3: Initialize MCP2515 You'll require code similar to this in your setup function:

#include https://github.com/Longan-Labs/Arduino_CAN_BUS_MCP2515
#include Adafruit MCP2515](https://reference.arduino.cc/reference/en/libraries/adafruit-mcp2515/
#include https://github.com/autowp/arduino-mcp2515

MCP2515 mcp2515(10); // Assuming CS pin is connected to digital pin 10

void setup() {
    Serial.begin(115200);
    SPI.begin();
    mcp2515.reset();
Step 4: Setting Bitrate
To set the CAN bit rate to 500 kbps, you can use the `setBitrate` function. For example:
```cpp
    mcp2515.setBitrate(CAN_500KBPS);

Step 5: Sending CAN Message Here's an example of how you can send a CAN message using MCP2515 from your loop or main function:

void loop() {
    // Prepare message
    uint8_t data[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
    CAN_message_t msg;

    msg.id = /* Set the ID of your message */;
    msg.len = sizeof(data);
    memcpy(msg.buf, data, sizeof(data));

    // Send the prepared message using MCP2515
    mcp2515.sendMessage(&msg);

    delay(100); // Add a delay if necessary

}

In summary:

vtl commented 6 months ago

Teensy's built-in CAN is better and cheaper.