Working on a project using UNO + NiRen mcp2515 shield.
Its my first CAN experience, so it took some time to make it work, and finally i got data using CoryJFowler library. Good thing i have Canhacker so that helped me alot with checking and searching values im interested in.
Terminal:
Standard ID: 0x608 DLC: 8 Data: 0x7C 0x42 0xFC 0x6D 0x70 0x00 0x00 0x00
Thats the line im interested but main thing is to separate first data bytes (same as a DLC: 1) 0x7C.
Thats a temp value, so need print it to terminal withought all others. Im novice and looks hard to manage program code.
Using Cory's receive example i almost did all i want with lack of knowledge.
It takes first data bytes to terminal once id:608 packed is received and then value stuck even it changes realtime i always see the 1st received value (doesnt update). Another thing my filter not very correct and it loads CPU.
Code im using:
// CAN Receive Example
//
#include <mcp_can.h>
#include <SPI.h>
long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
char msgString[128]; // Array to store serial string
long unsigned int T=0;
#define CAN0_INT 2 // Set INT to pin 2
MCP_CAN CAN0(10); // Set CS to pin 10
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)
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()
{
if(!digitalRead(CAN0_INT)) // If CAN0_INT pin is low, read receive buffer
{
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if(rxId == 0x608){
for(byte i = 0; i<len; i){
// sprintf(msgString, " %.2X", rxBuf[i]);
T=(rxBuf[i]-40);
Serial.println(T);
delay(1000);
}
}
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
Thanks in advance