Cant send CAN messages... Whats wrong?

My code is as follows.. I can send a message with VSPY and it turns on the pump.. However i cant seem to send a message with the arduino and CAN Shield. Any ideas?

I feel like sending a CAN message should be simple... but after several hours im stumped! Ive tried adding a terminating resistor but i dont think this is the problem seeing as i was able to send a message straight over with vspy and activate the pump.

Im trying to send at 500 Kbps CAN ID 201, 8 bytes of data, in the following sequence 0x03, 0xE8, 0x00, 0x00, 0x00, 0x07, 0x68, 0x00.

I cant seem to get any pictures on my PC at the moment, but im using an arduino UNO, attached to a v1.10 CAN bus Shield. I have my PC connected to the arduino and wires attached from the CAN L and CANL ports on the shield to the pumps CAN low and CAN high.

#include <SPI.h>
#define CAN_2515
#if defined(SEEED_WIO_TERMINAL) && defined(CAN_2518FD)
const int SPI_CS_PIN = BCM8;
const int CAN_INT_PIN = BCM25;
#else
const int SPI_CS_PIN = 9;
const int CAN_INT_PIN = 2;
#endif
#ifdef CAN_2518FD
#include "mcp2518fd_can.h"
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
#endif
#ifdef CAN_2515
#include "mcp2515_can.h"
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
#endif
int status = 0;
void setup() {
SERIAL_PORT_MONITOR.begin(115200);
while(!Serial){};

while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k
    SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
    delay(100);
}
SERIAL_PORT_MONITOR.println("CAN init ok!");

}
byte stmp[8] = {0x03, 0xE8, 0x00, 0x00, 0x00, 0x07, 0x68, 0x00};
void loop() {
status = CAN.sendMsgBuf(201, 1, 8, stmp);
delay(100); // send data per 100ms
SERIAL_PORT_MONITOR.println("CAN BUS sendMsgBuf ok!");
SERIAL_PORT_MONITOR.println(status);
}


'1' implies that CAN ID 201 is extended type.

Is you CAN messages extended type or standard? if the latter, you need to change the '1' to a '0' and try again...

Hope that helps...

Thanks! I have tried it set to 0 also with the same result. Not sure if my message type is extended or standard.. I also have tried with the 201 as 0x201. No changes with that either.

Any idea which way i should have either one set?

  • What CAN library are you using?
  • How is the CAN baudrate value set in the library. Your shield seems to have a 16MHz crystal. If the values in the library are for 8MHz crystal your baudrate is too fast (2x).
  • Can you provide a link to the shield you are using?
  • CAN init OK does not mean a lot. I guess it confirms SPI is working and a MCP2515 was found. If the baudrate value is wrong your device will create errors on the bus and then disconnect.
  • What does status 6 mean? Unlikely everything is OK. Check the library source code.

Another test you can do is the following

  • create a CAN bus with only your Arduino and the CAN tool you have
  • initialize the CAN on your Arduino
  • send any message with your CAN tool
  • if the Arduino CAN is not configured correctly (baudrate) the CAN tool should create an error because it needs a CAN node to acknowledge the CAN message on the physical level, the CAN shield will do that when it is correctly configured

If you have an oscilloscope, disconnect everything and send one CAN message from your Arduino. The CAN controller will repeat the CAN message forever because no other node is connected. Use the oscilloscope to measure the bit time.

Check your CAN tool manual whether it supports CAN baudrate scanning. Then connect only the Arduino with the CAN tool, send messages and then run a scan.

In all cases make sure you have a CAN bus with two termination resistors at the end. If your shield has one, enable it. Then you need only on at the other end of the bus.

  • What CAN library are you using? - Seed Arduino CAN.
  • How is the CAN baudrate value set in the library. Your shield seems to have a 16MHz crystal. If the values in the library are for 8MHz crystal your baudrate is too fast (2x).I checked this and its setup to 16MHz in the library.
  • Can you provide a link to the shield you are using? https://www.amazon.com/KOOBOOK-Controller-Expansion-Development-Communication/dp/B07TWDVHWF
  • CAN init OK does not mean a lot. I guess it confirms SPI is working and a MCP2515 was found. If the baudrate value is wrong your device will create errors on the bus and then disconnect.
  • What does status 6 mean? Unlikely everything is OK. Check the library source code. Ill have to check this as well.

Another test you can do is the following

  • create a CAN bus with only your Arduino and the CAN tool you have
  • initialize the CAN on your Arduino
  • send any message with your CAN tool
  • if the Arduino CAN is not configured correctly (baudrate) the CAN tool should create an error because it needs a CAN node to acknowledge the CAN message on the physical level, the CAN shield will do that when it is correctly configured. Ill have to give this a shot.

If you have an oscilloscope, disconnect everything and send one CAN message from your Arduino. The CAN controller will repeat the CAN message forever because no other node is connected. Use the oscilloscope to measure the bit time.

Check your CAN tool manual whether it supports CAN baudrate scanning. Then connect only the Arduino with the CAN tool, send messages and then run a scan.

In all cases make sure you have a CAN bus with two termination resistors at the end. If your shield has one, enable it. Then you need only on at the other end of the bus. I have checked this, there is approximately 120 ohms resistance on the can bus.

It means CAN_GETTXBFTIMEOUT. Can you check whether you get this with sending only one message? I would expect you get another status for this first three times with your current code. Then the TX buffers are full because no message is ever sent and the status changes to 6.

You need a resistor on each end. It is not about DC current. The resistors are for signal termination on the bus. When using a Ohm meter you should see closer to 60Ohm.

Did you read the comments on Amazon about the board? There were some unhappy users. :frowning:

There seem to be quite a few contributors to the library. So, there should be a way to get this working.

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