Seeed-Studio / Seeed_Arduino_CAN

Seeed Arduino CAN-BUS library - MCP2518FD&MCP2515&MCP2551
MIT License
827 stars 441 forks source link

MCP2515 doesnt init #130

Open zigagazaziga opened 2 years ago

zigagazaziga commented 2 years ago
#include <can-serial.h>
#include <mcp2515_can.h>
#include <mcp2515_can_dfs.h>
#include <mcp_can.h>
#include <SPI.h>

#define CAN_2515

const int SPI_CS_PIN = 9;
const int CAN_INT_PIN = 2;

mcp2515_can CAN(SPI_CS_PIN);

void setup() {

   SERIAL_PORT_MONITOR.begin(115200);

    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k
        SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
        delay(100);
    }
    SERIAL_PORT_MONITOR.println("CAN init ok!");
}
void loop() {
//...
}

MCP2515 doesnt complete init and I have no clue why, serial monitor just outputs "CAN init fail, retry...". Using Arduino UNO + CAN-BUS Shield V1.2 10/10/2013 by Elecfreaks. Doesnt work if I change CS to 10 either.

I dont have anything connected to CANH CANL, but it should finish initialisation either way right?

When I do apply a signal to CANH CANL, it is a signal from DEWESOFT's DS CAN2 on address 0x0A5. This doesnt change the result obviously, but the point is, I'd like to read it.

Would appreciate any help, ty.

RufusVS commented 2 years ago

You should do a better job checking the return code from CAN.begin(). It will give you a clue about why can init is failing. For example: SERIAL_PORT_MONITOR.println(CAN.begin(CAN_500KBPS));

Lesords commented 1 week ago

Hello,

I'm very sorry to have kept you waiting so long.

Do you still have this problem now?