CAN Sender
Introduction
This tutorial guides you through using the CAN (Controller Area Network) port on the NEXTuino BASE to send data — both standard and extended CAN messages.
Prerequisites
- Installed Arduino IDE
- NEXTuino BASE board
Example Code
Step-by-Step Guide
Step 1: Initialization
Serial.begin(115200);
SPI1.setRX(PIN_SPI1_MISO);
SPI1.setTX(PIN_SPI1_MOSI);
SPI1.setSCK(PIN_SPI1_SCK);
if (!CAN.begin(500E3)) {
Serial.println("Starting CAN failed!");
while (1);
}
Step 2: Sending Standard CAN Packets
CAN.beginPacket(0x12); // Start packet with 11-bit ID
CAN.write('h');
CAN.write('e');
CAN.write('l');
CAN.write('l');
CAN.write('o');
CAN.endPacket();
Step 3: Sending Extended CAN Packets
CAN.beginExtendedPacket(0xabcdef); // Start packet with 29-bit ID
CAN.write('w');
CAN.write('o');
CAN.write('r');
CAN.write('l');
CAN.write('d');
CAN.endPacket();
Step 4: Loop
The loop() function sends these packets continuously at one-second intervals.
Testing and Validation
- Open the Serial Monitor in the Arduino IDE to view the sending process
- Use a CAN analyzer or another CAN device to verify packet reception
- If issues occur, check connections, baud rate, and CAN IDs
Conclusion
You can now send both standard and extended CAN messages from your NEXTuino BASE, which is essential for automotive and industrial automation applications.