Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By phenoboy
#53764 I have NodeMCU v1.0 and I'm using this https://github.com/coryjfowler/MCP_CAN_lib library with ESP8266 Arduino and MCP2515 breakout board http://www.ebay.com/itm/MCP2515-CAN-Bus ... SwI-BWPWDt

I'm having problems getting the breakout to work. First I want to get initialization working. MCP_CAN::Begin function returns error.

This breakout board has 8MHZ crystal. I wonder if I have to make some extra setup for 8MHZ SPI to work or what is the default speed for SPI in ESP8266 Arduino ?


I took a look at the library codes:

MCP_CAN::begin function has clock speed in its parameters and it calls function:

Code: Select allINT8U MCP_CAN::mcp2515_init(const INT8U canIDMode, const INT8U canSpeed, const INT8U canClock)


however
Code: Select allcanClock
is not used before this call :

Code: Select all  res = mcp2515_setCANCTRL_Mode(MODE_CONFIG);


.. and call fails and returns the error.

So to me it seems no SPI clock setting is done in the library before SPI.transfer function. Should I set the frequency (how) myself at some point in my sketch ?



Here's my sketch
Code: Select all#include <mcp_can.h>
#include <mcp_can_dfs.h>
#include <SPI.h>

#define CAN0_INT D2 // Set INT to pin D2
/*
  esp8266 SPI CS (CMD) GPIO15 taken from:
  http://www.esp8266.com/wiki/doku.php?id=esp8266_gpio_pin_allocations
*/
MCP_CAN CAN0(15);


void setup()
{
  Serial.begin(115200);
 
  // Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
  if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK)
    Serial.println("MCP2515 Initialized Successfully!");
  else
    Serial.println("Error Initializing MCP2515...");
 
  CAN0.setMode(MCP_NORMAL);                     // Set operation mode to normal so the MCP2515 sends acks to received data.

  pinMode(CAN0_INT, INPUT);                            // Configuring pin for /INT input
 
 

void loop()
{
 yield();
}