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);
}