first can transceiver test

This commit is contained in:
Carsten Schmiemann 2023-12-07 23:53:17 +01:00
parent 76ac314d6e
commit 47cf637810
2 changed files with 24 additions and 11 deletions

View file

@ -13,3 +13,4 @@ platform = atmelavr
board = megaatmega2560
framework = arduino
lib_deps = coryjfowler/mcp_can@^1.5.1
monitor_speed = 115200

View file

@ -1,18 +1,30 @@
#include <Arduino.h>
#include <mcp_can.h>
#include <SPI.h>
// put function declarations here:
int myFunction(int, int);
MCP_CAN CAN0(53); //Interrupt connected to D49 but not used
void setup() {
// put your setup code here, to run once:
int result = myFunction(2, 3);
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) Serial.println("MCP2515 Initialized Successfully!");
else Serial.println("Error Initializing MCP2515...");
CAN0.setMode(MCP_NORMAL); // Change to normal mode to allow messages to be transmitted
}
void loop() {
// put your main code here, to run repeatedly:
}
byte data[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
// put function definitions here:
int myFunction(int x, int y) {
return x + y;
void loop()
{
// send data: ID = 0x100, Standard CAN Frame, Data length = 8 bytes, 'data' = array of data bytes to send
byte sndStat = CAN0.sendMsgBuf(0x100, 0, 8, data);
if(sndStat == CAN_OK){
Serial.println("Message Sent Successfully!");
} else {
Serial.println("Error Sending Message...");
}
delay(100); // send data per 100ms
}