Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

How to Use CAN BUS: Examples, Pinouts, and Specs

Image of CAN BUSDesign with CAN BUS in Cirkit Designer

Introduction

The CAN (Controller Area Network) BUS module is an electronic communication interface used for connecting multiple microcontrollers in applications without a host computer. It is commonly used in automotive and industrial systems for allowing microcontrollers and devices to communicate with each other within a vehicle or machinery without a central computer.

Explore Projects Built with CAN BUS

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of Arduino UNO WiFi CAN Bus Interface with Sensor/Actuator Module: A project utilizing CAN BUS in a practical application
Arduino UNO WiFi CAN Bus Interface with Sensor/Actuator Module

This circuit features two Arduino UNO R4 WiFi microcontrollers interfaced with NS-LS2 light sensors and CAN_SN65HVD230 CAN bus transceivers. The Arduinos are configured to read light intensity data from the NS-LS2 sensors and communicate with each other over a CAN network, likely for a distributed sensing application. Power distribution is managed with 3.3V and 5V connections to the respective components, and the ground connections are shared across the devices to complete the circuit.

Open Project in Cirkit Designer

Common Applications and Use Cases

Technical Specifications

Key Technical Details

Pin Configuration and Descriptions

Pin Number Name Description
1 VCC Power supply (5V)
2 GND Ground connection
3 CANH CAN High
4 CANL CAN Low
5 RX Receive data (optional, for some modules)
6 TX Transmit data (optional, for some modules)

Usage Instructions

How to Use the Component in a Circuit

  1. Power Connections: Connect the VCC pin to a 5V power supply and the GND pin to the ground.
  2. CAN Bus Connections: Connect the CANH and CANL pins to the corresponding CANH and CANL lines of the CAN network.
  3. Microcontroller Interface: If the module has RX and TX pins, connect them to the respective TX and RX pins of the microcontroller.

Important Considerations and Best Practices

Example Code for Arduino UNO

#include <SPI.h>
#include <mcp_can.h>

// Initialize CAN BUS module with CS pin
MCP_CAN CAN(10); 

void setup() {
  Serial.begin(115200);
  
  // Initialize CAN BUS module at 500kbps speed
  if (CAN_OK == CAN.begin(CAN_500KBPS)) {
    Serial.println("CAN BUS Shield init ok!");
  }
  else {
    Serial.println("CAN BUS Shield init fail");
    Serial.println("Init CAN BUS Shield again");
    delay(100);
  }
}

void loop() {
  // Check if data is available to read
  unsigned char len = 0;
  unsigned char buf[8];
  
  if (CAN_MSGAVAIL == CAN.checkReceive()) {
    CAN.readMsgBuf(&len, buf); // Read data,  len: data length, buf: data buffer
    unsigned long canId = CAN.getCanId();
    
    Serial.println("-----------------------------");
    Serial.print("Get data from ID: 0x");
    Serial.println(canId, HEX);
    
    for (int i = 0; i < len; i++) { // Print each byte of the data
      Serial.print(buf[i], HEX);
      Serial.print("\t");
    }
    Serial.println();
  }
}

Troubleshooting and FAQs

Common Issues Users Might Face

Solutions and Tips for Troubleshooting

FAQs

Q: Can I use the CAN BUS module with a 3.3V system? A: Some CAN BUS modules are 3.3V compatible, but you must check the specific module's datasheet.

Q: How many devices can be connected to a CAN BUS? A: The CAN specification allows up to 112 nodes, but practical limits are lower and depend on the total bus length and the transceiver used.

Q: What is the maximum length of a CAN BUS network? A: The maximum length depends on the baud rate; for example, at 1 Mbps, the maximum length is typically around 40 meters.

Q: Do I need to use termination resistors? A: Yes, proper termination is critical for preventing reflections and ensuring signal integrity on the CAN bus.