Forum >CAN-BUS SHIELD V2 (SKU: DFR0370)
CAN-BUS SHIELD V2 (SKU: DFR0370)

hello guys i got a problem with this shield , i already connected can bus shield and arduino mega 2560 at the car with db9 cable , and i get only 1 message that says can bus shield init ok and then not any value at the serial . maybe its someone here who can help me?
2017-09-03 00:41:54 #include <SPI.h>
#include "mcp_can.h"
const int SPI_CS_PIN = 10;
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
#define PID_ENGIN_PRM 0x0C
#define PID_VEHICLE_SPEED 0x0D
#define PID_COOLANT_TEMP 0x05
#define CAN_ID_PID 0x7DF
unsigned char PID_INPUT;
unsigned char getPid = 0;
void set_mask_filt()
{
/*
* set mask 0x3ff
*/
CAN.init_Mask(0, 0, 0x7FC);
CAN.init_Mask(1, 0, 0x7FC);
/*
* set filter, receiver id from 0x04 ~ 0x09
*/
CAN.init_Filt(0, 0, 0x7E8);
CAN.init_Filt(1, 0, 0x7E8);
CAN.init_Filt(2, 0, 0x7E8);
CAN.init_Filt(3, 0, 0x7E8);
CAN.init_Filt(4, 0, 0x7E8);
CAN.init_Filt(5, 0, 0x7E8);
}
void sendPid(unsigned char __pid)
{
unsigned char tmp[8] = {0x02, 0x01, __pid, 0, 0, 0, 0, 0};
Serial.print("SEND PID: 0x");
Serial.println(__pid, HEX);
CAN.sendMsgBuf(CAN_ID_PID, 0, 8, tmp);
}
void setup()
{
Serial.begin(115200);
while (CAN_OK != CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("CAN BUS Shield init fail");
Serial.println(" Init CAN BUS Shield again");
delay(100);
}
Serial.println("CAN BUS Shield init ok!");
set_mask_filt();
}
void loop()
{
taskCanRecv();
taskDbg();
if(getPid) // epistrefei pisw PID
{
getPid = 0;
sendPid(PID_INPUT);
PID_INPUT = 0;
}
}
void taskCanRecv()
{
unsigned char len = 0;
unsigned char buf[8];
if(CAN_MSGAVAIL == CAN.checkReceive()) // check ean dexetai dedomena pisw
{
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
Serial.println("\r\n------------------------------------------------------------------");
Serial.print("Get Data From id: ");
Serial.println(CAN.getCanId(), HEX);
for(int i = 0; i<len; i++) // diatipwsi toy data
{
Serial.print("0x");
Serial.print(buf, HEX);
Serial.print("\t");
}
Serial.println();
}
}
void taskDbg()
{
while(Serial.available())
{
char c = Serial.read();
if(c>='0' && c<='9')
{
PID_INPUT *= 0x10;
PID_INPUT += c-'0';
}
else if(c>='A' && c<='F')
{
PID_INPUT *= 0x10;
PID_INPUT += 10+c-'A';
}
else if(c>='a' && c<='f')
{
PID_INPUT *= 0x10;
PID_INPUT += 10+c-'a';
}
else if(c == '\n') // telos
{
getPid = 1;
}
}
}
karamaltidis5492
#include "mcp_can.h"
const int SPI_CS_PIN = 10;
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
#define PID_ENGIN_PRM 0x0C
#define PID_VEHICLE_SPEED 0x0D
#define PID_COOLANT_TEMP 0x05
#define CAN_ID_PID 0x7DF
unsigned char PID_INPUT;
unsigned char getPid = 0;
void set_mask_filt()
{
/*
* set mask 0x3ff
*/
CAN.init_Mask(0, 0, 0x7FC);
CAN.init_Mask(1, 0, 0x7FC);
/*
* set filter, receiver id from 0x04 ~ 0x09
*/
CAN.init_Filt(0, 0, 0x7E8);
CAN.init_Filt(1, 0, 0x7E8);
CAN.init_Filt(2, 0, 0x7E8);
CAN.init_Filt(3, 0, 0x7E8);
CAN.init_Filt(4, 0, 0x7E8);
CAN.init_Filt(5, 0, 0x7E8);
}
void sendPid(unsigned char __pid)
{
unsigned char tmp[8] = {0x02, 0x01, __pid, 0, 0, 0, 0, 0};
Serial.print("SEND PID: 0x");
Serial.println(__pid, HEX);
CAN.sendMsgBuf(CAN_ID_PID, 0, 8, tmp);
}
void setup()
{
Serial.begin(115200);
while (CAN_OK != CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("CAN BUS Shield init fail");
Serial.println(" Init CAN BUS Shield again");
delay(100);
}
Serial.println("CAN BUS Shield init ok!");
set_mask_filt();
}
void loop()
{
taskCanRecv();
taskDbg();
if(getPid) // epistrefei pisw PID
{
getPid = 0;
sendPid(PID_INPUT);
PID_INPUT = 0;
}
}
void taskCanRecv()
{
unsigned char len = 0;
unsigned char buf[8];
if(CAN_MSGAVAIL == CAN.checkReceive()) // check ean dexetai dedomena pisw
{
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
Serial.println("\r\n------------------------------------------------------------------");
Serial.print("Get Data From id: ");
Serial.println(CAN.getCanId(), HEX);
for(int i = 0; i<len; i++) // diatipwsi toy data
{
Serial.print("0x");
Serial.print(buf, HEX);
Serial.print("\t");
}
Serial.println();
}
}
void taskDbg()
{
while(Serial.available())
{
char c = Serial.read();
if(c>='0' && c<='9')
{
PID_INPUT *= 0x10;
PID_INPUT += c-'0';
}
else if(c>='A' && c<='F')
{
PID_INPUT *= 0x10;
PID_INPUT += 10+c-'A';
}
else if(c>='a' && c<='f')
{
PID_INPUT *= 0x10;
PID_INPUT += 10+c-'a';
}
else if(c == '\n') // telos
{
getPid = 1;
}
}
}

2017-09-02 02:44:54 A general tip - if you want people to help you, you should provide a lot more details.
How is the hardware setup?
What arduino code are you using?
hoerup1981
How is the hardware setup?
What arduino code are you using?
