-->
Page 1 of 2

Problems with MCP2515 breakout board (8MHZ clock)

PostPosted: Thu Aug 25, 2016 2:11 am
by phenoboy
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();
}

Re: Problems with MCP2515 breakout board (8MHZ clock)

PostPosted: Fri Aug 26, 2016 9:33 am
by phenoboy
Here's the picture from Logic analyzer.

This just doesn't make sense. One of the channels is supposed to be CLK but I can't find steady pulse.

ESP8266:
Image


Here's comparison from STM32F103:
Image

Re: Problems with MCP2515 breakout board (8MHZ clock)

PostPosted: Mon Aug 29, 2016 5:28 am
by phenoboy
Does the Esp8266 Arduino SPI code use HSPI or SPI pins ?

It is very confusing since the board has i.e. CLK printed in SPI pin.

Image

Re: Problems with MCP2515 breakout board (8MHZ clock)

PostPosted: Mon Aug 29, 2016 9:21 am
by martinayotte
You should use the HSPI on GPIO12-GPIO15.
(The SPI is dedicated to the Flash)