Created
February 28, 2024 11:41
-
-
Save twitnic/1f0f6199b7e48818032ef0ab0fbf241c to your computer and use it in GitHub Desktop.
MQB Arduino WakeUp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // CAN Send Example | |
| // | |
| #include <mcp_can.h> | |
| #include <SPI.h> | |
| MCP_CAN CAN0(10); // Set CS to pin 10 | |
| void setup() | |
| { | |
| Serial.begin(500000); | |
| // 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 | |
| } | |
| byte data[4] = {0x00, 0x00, 0x03, 0x00}; | |
| void loop() | |
| { | |
| // send data: ID = 0x100, Standard CAN Frame, Data length = 8 bytes, 'data' = array of data bytes to send | |
| byte sndStat = CAN0.sendMsgBuf(0x3C0, 0, 4, data); | |
| if(sndStat == CAN_OK){ | |
| Serial.println("Message Sent Successfully!"); | |
| } else { | |
| Serial.println("Error Sending Message..."); | |
| } | |
| delay(100); // send data per 100ms | |
| } | |
| /********************************************************************************************************* | |
| END FILE | |
| *********************************************************************************************************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quellen: