I am using an Arduino UNO along with a Cooking Hacks CAN Bus Module and Multiprotocol Radio Shield. The CAN module is connected to the radio shield which is plugged into the Arduino. I got this radio shield keeping future applications in mind where I can combine multiple protocols, for eg. CAN and Bluetooth.

I connected them through an OBD2-DB9 cable to the car's OBD port but noticed that I was not really getting any messages. Well I am getting messages but just:

   -- Constructor Can(uint16_t speed) --
   SPI configured
   The MCP2515 has been successfully reset, configuration mode activated
   -- End Constructor Can(uint16_t speed) --

   Data in buffer 0
   id: 7FF  rtr: FFFFFFFF => Data in buffer 0
   id: 7FF  rtr: FFFFFFFF => Data in buffer 0
   id: 7FF  rtr: FFFFFFFF => Data in buffer 0 

After analysing the connections, I realised that the hardware is probably fine since the continuity between the pins of the cables is fine and the CAN module(MCP2515 + MCP2551) is receiving power and I also checked the voltages at the pins and think they're mostly fine apart from a few pins which I'm not sure about. Which brings me to the software issue. I can see that the SPI is not getting configured properly and the MCP2515 controller doesn't enter configuration mode which means the bit times defined are not being used and hence the controller is not initialising like it should. I even tried manually changing to configuration mode by changing the values of the REQOP bits of the CANCTRL register as opposed to doing a software reset which was how I was doing it initially. Even then, no luck. To verify the SPI connection, I chose a random read/write control register like BFPCTRL and wrote a value to it and then read it back to verify that it matched the values I wrote. However, the value read back is not the same as the value I wrote. Also, the controller only has trouble going into configuration mode. It seems to change to normal and listen only mode without problem since the CANSTAT register displays the correct values for the REQOP bits. I don't understand why the controller has problem entering configuration mode but no problem changing to the other modes. Can anybody help me?

SPI Code:

    bool CAN::begin(uint16_t speed)
    #if (DEBUGMODE ==1 )
    Serial.println("-- Constructor Can(uint16_t speed) --");

    //Initialization SPI
    // both mode 0 & 3 should work

    //Set the SPI frequency

    #if (DEBUGMODE==1)
    Serial.println("SPI configured");

    //Configure MCP2515 pins

    writeRegister(BFPCTRL, (1<<B0BFM) | (1<<B1BFM));
    int dat = readRegister(BFPCTRL<<2);

    //Software resets MCP2515
    //After the reset, controller enters configuration mode 

When I read back the values of B0BFM and B1BFM bits, they should be 1 but the display says that their values are 0.

   void CAN::writeRegister( char direction, char data )
   //CS low to select the MCP2515 


  //CS line again to release 

  char CAN::readRegister(char direction)
  char data;
  //CS low to select the MCP2515 

  //Read data SPI
  data = SPI.transfer(0xff); 

  //CS line again to release 
  return data;
  • Please fix the format and remove extra characters "myCAN.begin(500); ]" Feb 11 '16 at 12:36

In SPI protocol you'll need to read the SPI buffer twice because the data you wrote will be read by the IC and the IC will respond to it in the next communication and that's when you know.

Also, by looking at the message, I see that your IC is working fine, but is your CAN bus initialised properly? I'm a FSAE team member and I've faced this issue with the CAN Bus termination resistances and the ODB-II configuration on the Sparkfun CAN Bus shield.

Also, have you tried any other libraries for the CAN Shield? For me the seeedstudio library of their CAN shield worked very well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.