The Adafruit Feather M4 Express CAN is a versatile and powerful development board that harnesses the capabilities of the ATSAMD51 microcontroller. This board is part of the Feather ecosystem, known for its compact size, portability, and extensive I/O options. The inclusion of CAN-Bus connectivity makes it ideal for automotive applications, industrial automation, and any project where robust serial communication is required. The ARM Cortex-M4 core with a floating-point unit runs at 120 MHz, providing high computational performance for complex tasks.
Pin Number | Function | Description |
---|---|---|
1 | GND | Ground |
2 | 3V | 3.3V power supply output |
3 | AREF | Analog reference voltage for ADC |
4-9 | A0-A5 | Analog input pins |
10-15 | D5-D10 | Digital I/O pins, PWM capable |
16-17 | SCK, MISO, MOSI | SPI communication pins |
18-19 | SDA, SCL | I2C communication pins |
20 | RX | UART receive pin |
21 | TX | UART transmit pin |
22 | CAN_RX | CAN-Bus receive pin |
23 | CAN_TX | CAN-Bus transmit pin |
#include <SPI.h>
#include <mcp_can.h>
// Initialize MCP_CAN instance with SPI CS Pin 10
MCP_CAN CAN0(10);
void setup() {
Serial.begin(115200);
// Initialize CAN0 at 500 kbps
if (CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK) {
Serial.println("CAN Bus Module Initialized Successfully!");
} else {
Serial.println("CAN Bus Module Initialization Failed!");
}
}
void loop() {
// Check if data is available to read
if (CAN0.checkReceive() == CAN_MSGAVAIL) {
unsigned char len = 0;
unsigned char buf[8];
// Read data: len = data length, buf = data byte(s)
CAN0.readMsgBuf(&len, buf);
// Print received data
for (int i = 0; i < len; i++) {
Serial.print(buf[i], HEX);
Serial.print(" ");
}
Serial.println();
}
}
Note: This example demonstrates basic CAN-Bus communication using the MCP_CAN library. Ensure that the library is installed in your Arduino IDE before compiling the sketch. Adjust the CS pin number and CAN bus speed according to your specific setup.