Seeed_Arduino_CAN icon indicating copy to clipboard operation
Seeed_Arduino_CAN copied to clipboard

MCP2515 doesnt init

Open zigagazaziga opened this issue 4 years ago • 2 comments

#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.

zigagazaziga avatar Nov 03 '21 12:11 zigagazaziga

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));

RufusVS avatar Sep 24 '22 19:09 RufusVS