ThisCalculator

Everyday

Arduino Uno CAN Bus Monitoring with SH-C30L

Updated · Standard formula, shown below

This guide walks you through connecting an SH-C30L CAN bus module to an Arduino Uno and reading live CAN frames in the Serial Monitor. You will need the MCP2515 library and a CAN bus with a valid 5V logic level (or a level shifter if your bus is 3.3V). By the end, you will see raw CAN IDs and data bytes printed on your computer.

What You’ll Need

  • Arduino Uno (any clone works)
  • SH-C30L CAN bus module (MCP2515 + TJA1050 based)
  • Jumper wires (M-F or F-F)
  • CAN bus with 120Ω termination (e.g., two nodes or a terminator resistor)
  • Arduino IDE (latest stable version)
  • USB cable for the Uno
  • Optional: multimeter for checking continuity and voltages

Step-by-Step

  1. Identify the SH-C30L pins. The module usually has 8 pins: VCC, GND, CS, SO, SI, SCK, INT, and the CAN side has CANH and CANL. Check the silkscreen on your board—some versions label them differently (e.g., “TXD” and “RXD” instead of SI/SO).
  2. Wire the SPI connections. Connect:
    • VCC → 5V on Uno
    • GND → GND on Uno
    • CS → Digital pin 10 (default for MCP2515 library)
    • SO (MISO) → Digital pin 12
    • SI (MOSI) → Digital pin 11
    • SCK → Digital pin 13
    • INT → Digital pin 2 (optional but recommended for interrupt-driven reading)
  3. Connect the CAN bus lines. Attach CANH to the CAN high line and CANL to the CAN low line of your bus. Ensure the bus has 120Ω termination at each end—if you are just testing with one other node, add a 120Ω resistor between CANH and CANL at the far end.
  4. Install the MCP2515 library. Open Arduino IDE, go to Sketch → Include Library → Manage Libraries, search for “MCP2515” by autowp, and install it. This library handles the SPI communication and CAN framing.
  5. Write the monitoring sketch. Use the following code as a starting point:
    #include 
    
    struct can_frame canMsg;
    MCP2515 mcp2515(10); // CS pin
    
    void setup() {
      Serial.begin(115200);
      mcp2515.reset();
      mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ); // adjust to your bus speed
      mcp2515.setNormalMode();
    }
    
    void loop() {
      if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK) {
        Serial.print("ID: 0x");
        Serial.print(canMsg.can_id, HEX);
        Serial.print(" DLC: ");
        Serial.print(canMsg.can_dlc);
        Serial.print(" Data: ");
        for (int i = 0; i < canMsg.can_dlc; i++) {
          Serial.print(canMsg.data[i], HEX);
          Serial.print(" ");
        }
        Serial.println();
      }
    }
        

    Adjust the bitrate to match your CAN bus (e.g., CAN_250KBPS for 250 kbps). The MCP_8MHZ parameter assumes the module’s crystal is 8 MHz—check the silkscreen or datasheet; some use 16 MHz.

  6. Upload the sketch. Connect the Uno via USB, select the correct board and port in Tools, then click Upload. Open the Serial Monitor (Tools → Serial Monitor) and set the baud rate to 115200.
  7. Verify traffic. If your CAN bus has active nodes, you should see frames scrolling in the Serial Monitor. If nothing appears, check wiring and termination.

Common Mistakes

  • Wrong SPI pins. The Uno’s SPI pins are fixed (11, 12, 13). Connecting to other digital pins will not work without bit-banging.
  • Incorrect crystal frequency. The MCP2515 library needs the oscillator speed. If you set 8 MHz but the module has 16 MHz, communication fails silently.
  • Missing termination. A CAN bus without 120Ω at both ends will have reflections and may not transmit reliably.
  • Baud rate mismatch. The module must be set to the same speed as the rest of the bus. A mismatch will cause no messages or garbled data.
  • Power issues. Some modules draw more than the Uno’s 5V regulator can supply. Use an external 5V supply if needed.

Tips

  • Use short jumper wires (under 20 cm) for SPI to reduce noise.
  • Add a decoupling capacitor (100 nF) between VCC and GND on the module if you see random resets.
  • If you only need to monitor (not transmit), you can set the MCP2515 to listen-only mode using mcp2515.setListenOnlyMode() to avoid ACK errors on a bus you are not part of.
  • Print timestamps by calling millis() before reading the message to see frame intervals.
  • For high traffic, consider using the INT pin and an interrupt to avoid missing frames.

Troubleshooting

  • No output at all: Check that the module is powered (LED on). Verify SPI wiring with a multimeter continuity test. Re-upload the sketch after checking the CS pin.
  • Garbage characters in Serial Monitor: Ensure the baud rate matches (115200). Also check that the Uno’s serial is not being used by anything else.
  • Frames appear but with wrong IDs: This usually means a bitrate mismatch or noise. Double-check the bus speed and termination.
  • Module gets hot: Unplug immediately. Check for reversed VCC/GND or a short between CANH and CANL.
  • Only one frame then nothing: The MCP2515 may be entering error state. Add mcp2515.clearInterrupts() after each read, and ensure the bus is properly terminated.

Frequently Asked Questions

Can I use the SH-C30L with a 3.3V CAN bus?

No, the TJA1050 transceiver on the SH-C30L is 5V. Use a level shifter or a different transceiver if your bus is 3.3V.

What is the maximum CAN speed supported?

The MCP2515 supports up to 1 Mbps, but the SH-C30L’s crystal (usually 8 or 16 MHz) limits the achievable bitrates. Check the module’s oscillator frequency.

Do I need a second CAN node to test?

Yes, CAN requires at least two nodes. You can use another Arduino with a CAN shield, or a USB-CAN adapter.

Can I send CAN messages with this setup?

Yes, use mcp2515.sendMessage() in the sketch. Make sure the bus is not overloaded and you have proper termination.

Why do I see only error frames?

Error frames appear when the bus is not terminated, the bitrate is wrong, or there is a short. Check your wiring and the bitrate setting.

How do I know the module’s crystal frequency?

Look for a small metal can labeled “8.000” or “16.000” on the PCB. If unsure, try both settings in the library and see which one works.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.