I am trying to brute force a CANBUS with ID's and values but my loop doesn't seem to change the ID.
I am expecting the following when changing ID's
0x100 FF FF FF FF FF FF FF FF
0x101 00 00 00 00 00 00 00 00
But I get
0x100 FF FF FF FF FF FF FF FF
0x100 00 00 00 00 00 00 00 00
I am not sure where I am going wrong
#include <SPI.h>
#include "mcp_can.h"
// Define the chip select pin for the MCP2515
#define CAN_CS 5
MCP_CAN CAN(CAN_CS); // Initialize MCP2515 with the CS pin
void setup() {
Serial.begin(115200);
// Initialize MCP2515
if (CAN.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK) {
Serial.println("MCP2515 Initialized Successfully!");
} else {
Serial.println("Error Initializing MCP2515...");
while (1);
}
CAN.setMode(MCP_NORMAL);
}
void loop() {
for (uint16_t id = 0x100; id <= 0x500; id++) { // Increment ID
for (uint8_t byteValue = 0x00; byteValue <= 0xFF; byteValue++) { // Increment data bytes from 0x00 to 0xFF
uint8_t data[8] = {byteValue, byteValue, byteValue, byteValue, byteValue, byteValue, byteValue, byteValue}; // Set all bytes to the current value
// Send CAN message
byte sendStatus = CAN.sendMsgBuf(id, 0, 8, data);
// Keep the if condition unchanged
if (sendStatus == CAN_OK) {
Serial.print("Sent message with ID: 0x");
Serial.print(id, HEX);
Serial.print(" Data: ");
for (int k = 0; k < 8; k++) {
Serial.print(data[k], HEX);
Serial.print(" ");
}
Serial.println();
} else {
Serial.print("Error sending message with ID: 0x");
Serial.println(id, HEX);
}
delay(10); // Small delay between messages
}
// Print a separator after finishing all data bytes for the current ID
Serial.println("----------------------------------------");
}
Serial.println("Finished all IDs from 0x100 to 0x500 with data bytes from 0x00 to 0xFF.");
while (1); // Stop after completion
}