64 lines
1.1 KiB
Plaintext
64 lines
1.1 KiB
Plaintext
#include <Arduino.h>
|
|
#include "mcp_can.h"
|
|
|
|
#define debug
|
|
#define CAN_CS_PIN 49
|
|
#define CAN_SPEED CAN_500KBPS
|
|
|
|
unsigned char Flag_Recv = 0;
|
|
unsigned char len = 0;
|
|
unsigned char buf[8];
|
|
char str[20];
|
|
|
|
MCP_CAN CAN(CAN_CS_PIN);
|
|
|
|
|
|
void setup()
|
|
{
|
|
#ifdef debug
|
|
Serial.begin(115200);
|
|
Serial.println("CAN Test Project - Sending Unit");
|
|
delay(1000);
|
|
Serial.println("Init MCP2515 CAN Controller...");
|
|
#endif
|
|
|
|
START_INIT:
|
|
|
|
if(CAN_OK == CAN.begin(CAN_SPEED))
|
|
{
|
|
#ifdef debug
|
|
Serial.println("Sucessfully initialized.");
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
#ifdef debug
|
|
Serial.println("Initialization failed, try again.");
|
|
#endif
|
|
delay(100);
|
|
goto START_INIT;
|
|
}
|
|
}
|
|
|
|
void SendIntCAN(int canid, int value)
|
|
{
|
|
byte buf[2];
|
|
buf[0] = value & 0x00FF;
|
|
buf[1] = (value & 0xFF00) >> 8;
|
|
|
|
CAN.sendMsgBuf(canid, 0, 2, buf);
|
|
}
|
|
|
|
int counter = 0, counter2 = 32767;
|
|
|
|
void loop()
|
|
{
|
|
counter++;
|
|
SendIntCAN(1,counter);
|
|
delay(100);
|
|
counter2--;
|
|
SendIntCAN(2,counter2);
|
|
delay(500);
|
|
}
|
|
|