[solved] Arduino CAN Bus

Hello everyone

I am trying to build a CAN interface using
CAN_Bus Tutorial

and having trouble initializing the bus.

I have set up my board using the schematic and the real picture (set it up multiple times, even with different ICs).

The library used is CAN_BUS_Shield.

Even when I just try to initialize the bus I get the status byte 1 (Error-> cant initialize). I do not have anything connected (except the 100Ohm termination resistor) on the CANH, CANL side.

#include <Arduino.h>

#include <mcp_can.h>
#include <SPI.h>          //SPI is used to talk to the CAN Controller

MCP_CAN CAN(10);          //set SPI Chip Select to pin 10

void setup()
{
  Serial.begin(9600);   //to communicate with Serial monitor
  Serial.println("---Setup---");

//tries to initialize, if failed --> it will loop here for ever
START_INIT:

    if(CAN_OK == CAN.begin(CAN_500KBPS))      //setting CAN baud rate to 500Kbps
    {
        Serial.println("CAN BUS Shield init ok!");
    }
    else
    {
        Serial.println("CAN BUS Shield init fail");
        Serial.println("Init CAN BUS Shield again");
        delay(2000);
        goto START_INIT;
    }
}

loop {
  delay(1000);
}

Has anyone experience setting up CAN?

I have enabled 'DEBUG_MODE 1' and followed the methods. The problems seems with the SPI, because I can not read out any register.

INT8U MCP_CAN::mcp2515_setCANCTRL_Mode(const INT8U newmode)
{
    INT8U i;

    mcp2515_modifyRegister(MCP_CANCTRL, MODE_MASK, newmode);

    i = mcp2515_readRegister(MCP_CANCTRL);
    i &= MODE_MASK;

    if ( i == newmode ) 
    {
        return MCP2515_OK;
    }

    return MCP2515_FAIL;

}

I got it running, sort of.
The clock is working and some communication is coming through. I changed the library to
mcp2515/archive/master.zip

it is basically the same, just a little cleaner programmed.

I now have another problem with the protocol, but this is the topic for another thread.

As you probably know CAN is a multi-master serial bus standard for connecting Electronic Control Units [ECUs] (Engine Control Units) also known as nodes. TWO or more nodes are required on the CAN network to communicate. ... All nodes are connected to each other through a two wire bus. Note it is best to also connect the grounds, I have never had much luck unless there are connected. The wires are a twisted pair with a 120 Ω (nominal) characteristic impedance. You need to put termination resistors 120 Ohm at the physically end of the buss only, no more. For can to operate it needs an acknowledge from one or more units. I would recommend you get a logic analyzer it will help a lot, many have a CAN analyzer as part of there software. You can get some cheap ones on eBay for a few dollars.
Good Luck & Have Fun!
Gil

I believe CAN Bus uses two 120 Ohm resisters in parallel at far ends of the network of connected devices. As far as each device sees 60 Ohms