MCP2515 Can controller : getting error while sending message

Hi all,

Currently I am working with Arduino uno and mcp2515 can controller trying to send message from can controller but getting output as error sending message. please can anyone help?


#include <mcp_can.h>
#include <SPI.h>

MCP_CAN CAN0(10); // Set CS to pin 10

void setup()
{
  Serial.begin(9600);

  // 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_16MHZ) == CAN_OK)
    Serial.println("MCP2515 Initialized Successfully!");
  else
    Serial.println("Error Initializing MCP2515...");

  CAN0.setMode(MCP_NORMAL); // Change to normal mode to allow messages to be transmitted
}

byte data[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};

void loop()
{
  // send data:  ID = 0x100, Standard CAN Frame, Data length = 8 bytes, 'data' = array of data bytes to send
  byte sndStat = CAN0.sendMsgBuf(0x100, 0, 8, data);
  if (sndStat == CAN_OK)
  {
    Serial.println("Message Sent Successfully!");
  }
  else
  {
    Serial.println("Error Sending Message...");
  }
  delay(1000); // send data per 100ms
}

What CAN module are you using? This may need to change to MCP_8MHZ if your module uses an 8MHZ crystal.

if (CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK)

I am using mcp2515 CAN controller.

The solution should be simple, you are violating the CAN protocol. Add another node (1 transmitter and 1 receiver required) to the bus and be sure it is properly terminated. CAN requires an in frame response (IFR) for each message, that is generated by any other unit on the bus. If no Acknowledge is received it is treated as an error and will count the fault. When the number faults reaches a given number it should shut down its transmitter.

I didn't understand can you tell in simple terms

I have already answered it in your other post. Do not double post it burns time that would have helped others and it will make responses to your problems slower as it now becomes a low priority as you did not even bother to read the forum guidelines.

Please read the advice in the topic "How to get the best from this forum". How to get the best out of this forum

Posting an annotated schematic showing exactly how you have wired it helps us help you. By showing all connections, power, ground and power sources you will save a lot of clarifying questions and time for all of us. Be sure to note any logic wires over 10/25 inches/cm in length. Post links to technical information on the hardware items including the motors, shield, and Arduino. This should include all component values or model numbers and details of all power supplies used (which could be USB power for example).
Posting the code following forum guidelines using code tags will also help. With this information we should be able to answer your question accurately. "How to get the best from this forum". How to get the best out of this forum

I have deleted your other cross-post @revajd123.

In the future, please only create one topic for each distinct subject matter. Thanks in advance for your cooperation.

Get a copy of the Arduino Cookbook and read it from cover to cover. It appears you are not familiar with CAN, Its protocol and Arduino hardware. Download and read this, it will explain what is happening.

I have worked with CAN trans receiver with teensy board I never face this type of issue there.

Sometimes we get lucky. I cannot see your project, good luck!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.