Skip to content

Instantly share code, notes, and snippets.

@maxpromer
Created February 17, 2024 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxpromer/0bff40601e999a6f4db6840063c809d0 to your computer and use it in GitHub Desktop.
Save maxpromer/0bff40601e999a6f4db6840063c809d0 to your computer and use it in GitHub Desktop.
#include <SPI.h>
#include <mcp2515.h>
MCP2515 mcp2515(10);
void setup() {
Serial.begin(115200);
mcp2515.reset();
mcp2515.setBitrate(CAN_125KBPS, MCP_8MHZ);
mcp2515.setNormalMode();
}
void loop() {
uint16_t adc = analogRead(A0);
struct can_frame frame;
frame.can_id = 0x7FF;
frame.can_dlc = 2;
frame.data[0] = adc >> 8;
frame.data[1] = adc & 0xFF;
if (mcp2515.sendMessage(&frame) == mcp2515.ERROR_OK) {
Serial.println("Send analog value OK");
} else {
Serial.println("Send FAIL");
}
delay(50);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment