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

struct can_frame frame;

MCP2515 mcp2515(10);
/*
Software matching Hardware of meycan v8.1
*/
void setup() {
  SPI.begin();
  Serial.begin(9600);



  pinMode(PD3, OUTPUT);
  digitalWrite(PD3, HIGH);
  delay(1000);
  digitalWrite(PD3, LOW);
  delay(2000);

  mcp2515.reset();
  mcp2515.setBitrate(CAN_1000KBPS, MCP_8MHZ);
  mcp2515.setNormalMode();
}


void loop() {
  if (mcp2515.readMessage(&frame) == MCP2515::ERROR_OK) {
    // frame contains received message

    Serial.print(" Id: ");
    Serial.print(frame.can_id, HEX);
    Serial.print(" [");

    for (int i = 0; i < 8; i++) {
      Serial.print(frame.data[i], HEX);
      Serial.print(" ");
    }
    Serial.println("]");

    digitalWrite(PD3, HIGH);
    delay(50);
    digitalWrite(PD3, LOW);
    delay(50);

    mcp2515.sendMessage(&frame);
    mcp2515.sendMessage(&frame);
    mcp2515.sendMessage(&frame);
    mcp2515.sendMessage(&frame);
  }
}