I2C / UART / SPI / CAN 통신 프로토콜 비교

2025. 2. 22. 04:02Embedded Development

I2C, UART, SPI, CAN 통신 프로토콜 비교

임베디드 시스템에서는 다양한 주변 장치와 통신하기 위해 여러 가지 통신 프로토콜이 사용됩니다. 그중 가장 일반적인 프로토콜은 I2C, UART, SPI, CAN입니다. 아래는 이 프로토콜들의 특징과 차이점을 정리한 비교표입니다.


1. 통신 프로토콜 개요

프로토콜 유형 속도 사용되는 배선 수 통신 방식 주된 용도
I2C (Inter-Integrated Circuit) 직렬, 멀티마스터 최대 3.4 Mbps 2 (SDA, SCL) 동기식 저속 센서, EEPROM, RTC
UART (Universal Asynchronous Receiver-Transmitter) 직렬, 포인트투포인트 최대 1 Mbps 2 (TX, RX) 비동기식 디버깅, 저속 주변 장치
SPI (Serial Peripheral Interface) 직렬, 마스터-슬레이브 최대 50 Mbps 3+ (MOSI, MISO, SCK, SS) 동기식 고속 데이터 전송, 플래시 메모리, 디스플레이
CAN (Controller Area Network) 직렬, 멀티마스터 1 Mbps (클래식) / 5 Mbps (CAN FD) 2 (CAN_H, CAN_L) 동기식 자동차, 산업 자동화

2. I2C, UART, SPI, CAN 상세 비교

📌 I2C (Inter-Integrated Circuit)

  • 유형: 멀티마스터, 멀티슬레이브 프로토콜
  • 배선: 2개 (SDA – 데이터, SCL – 클럭)
  • 속도: 일반 모드 (100 kbps), 고속 모드 (400 kbps), 초고속 모드 (3.4 Mbps)
  • 데이터 전송: 7비트 또는 10비트 주소 지정을 사용하여 여러 슬레이브 장치와 통신
  • 장점:
    • 두 개의 배선만으로 여러 장치 연결 가능
    • 간단한 구현 가능
  • 단점:
    • SPI보다 속도가 느림
    • 클럭 스트레칭(clock stretching)으로 인해 속도 지연 발생 가능
  • 사용 사례: EEPROM, RTC(실시간 클럭), 온도 센서 등 저속 주변 장치

📌 UART (Universal Asynchronous Receiver-Transmitter)

  • 유형: 비동기식, 풀 듀플렉스 통신
  • 배선: 2개 (TX – 송신, RX – 수신)
  • 속도: 일반적으로 9600 ~ 115200 bps, 최대 1 Mbps
  • 데이터 전송: 시작/정지 비트와 설정 가능한 보드레이트 사용
  • 장점:
    • 하드웨어 및 소프트웨어 구현이 간단함
    • I2C 및 SPI보다 장거리 통신이 가능
  • 단점:
    • 포인트투포인트 통신만 지원 (멀티슬레이브 불가능)
    • SPI보다 속도가 낮음
  • 사용 사례: 디버깅, GPS 모듈, 블루투스 및 Wi-Fi 모듈 등

📌 SPI (Serial Peripheral Interface)

  • 유형: 동기식, 풀 듀플렉스 통신
  • 배선: 최소 3개 (MOSI – 마스터 출력 슬레이브 입력, MISO – 마스터 입력 슬레이브 출력, SCK – 클럭) + SS(슬레이브 선택)
  • 속도: 최대 50 Mbps 이상 가능
  • 데이터 전송: 시프트 레지스터(Shift Register)를 사용하여 동시에 송수신
  • 장점:
    • UART 및 I2C보다 매우 빠름
    • 간단한 하드웨어 구조 (I2C처럼 주소 지정 필요 없음)
  • 단점:
    • 각 슬레이브마다 추가적인 SS(칩 선택) 라인 필요
    • 장거리 통신에는 부적합
  • 사용 사례: 디스플레이 모듈, SD 카드, 플래시 메모리, 고속 ADC 등

📌 CAN (Controller Area Network)

  • 유형: 멀티마스터, 우선순위 기반 중재 프로토콜
  • 배선: 2개 (CAN_H, CAN_L)를 사용하는 차동 신호(differential signaling)
  • 속도: 1 Mbps (클래식 CAN), 5 Mbps (CAN FD)
  • 데이터 전송: 메시지 우선순위 및 오류 감지 기능 지원
  • 장점:
    • 노이즈 환경에 강함 (차량 및 산업 자동화에 최적)
    • 마스터-슬레이브 개념이 없음, 메시지 ID를 통해 직접 통신
    • 강력한 오류 감지 및 복구 기능 제공
  • 단점:
    • 별도의 하드웨어 컨트롤러가 필요함
    • SPI보다 데이터 전송 속도가 느림
  • 사용 사례: 자동차 ECU, 산업 자동화, 의료 기기 등

3. 어떤 프로토콜을 선택해야 할까?

사용 시나리오 추천 프로토콜
여러 개의 저속 센서를 연결해야 하는 경우 I2C
디버깅 및 간단한 직렬 통신이 필요한 경우 UART
MCU와 주변 장치 간 고속 데이터 전송이 필요한 경우 SPI
노이즈가 많은 환경에서 신뢰성 높은 통신이 필요한 경우 (자동차/산업용) CAN

4. 결론

각 통신 프로토콜은 특정한 목적을 위해 설계되었습니다.

  • I2C → 저속 장치를 여러 개 연결하는 경우 적합
  • UART → 간단한 디버깅 및 장거리 통신에 유용
  • SPI → 고속 데이터 전송이 필요한 경우 적합
  • CAN → 노이즈가 많은 환경에서 신뢰성 있는 통신을 제공

각 프로토콜의 차이를 이해하고, 시스템 요구사항에 맞는 적절한 프로토콜을 선택하는 것이 중요합니다. 🚀


Comparison of Communication Protocols: I2C, UART, SPI, CAN

In embedded systems, various communication protocols are used to interface different peripherals. The four most common protocols are I2C, UART, SPI, and CAN. Below is a detailed comparison of these protocols based on their characteristics and applications.


1. Overview of Communication Protocols

Protocol Type Speed Number of Wires Communication Type Best For
I2C (Inter-Integrated Circuit) Serial, Multi-Master Up to 3.4 Mbps 2 (SDA, SCL) Synchronous Low-speed sensors, EEPROM, RTC
UART (Universal Asynchronous Receiver-Transmitter) Serial, Point-to-Point Up to 1 Mbps 2 (TX, RX) Asynchronous Debugging, Low-speed peripherals
SPI (Serial Peripheral Interface) Serial, Master-Slave Up to 50 Mbps 3+ (MOSI, MISO, SCK, SS) Synchronous High-speed data transfer, Flash memory, Display
CAN (Controller Area Network) Serial, Multi-Master 1 Mbps (Classical) / 5 Mbps (CAN FD) 2 (CAN_H, CAN_L) Synchronous Automotive, Industrial automation

2. Detailed Comparison of I2C, UART, SPI, and CAN

📌 I2C (Inter-Integrated Circuit)

  • Type: Multi-master, multi-slave protocol.
  • Wires: Requires only 2 wires (SDA – Data, SCL – Clock).
  • Speed: Standard mode (100 kbps), Fast mode (400 kbps), High-Speed mode (3.4 Mbps).
  • Data Transmission: Uses 7-bit or 10-bit addressing for multiple slave devices.
  • Advantages:
    • Simple two-wire implementation.
    • Supports multiple devices with unique addresses.
  • Disadvantages:
    • Slower compared to SPI.
    • Susceptible to clock stretching delays by slower slave devices.
  • Common Use Cases: EEPROM, RTC (Real-Time Clock), temperature sensors, and low-speed peripherals.

📌 UART (Universal Asynchronous Receiver-Transmitter)

  • Type: Asynchronous, full-duplex communication.
  • Wires: Requires 2 wires (TX – Transmit, RX – Receive).
  • Speed: Typically 9600 to 115200 bps, but can go up to 1 Mbps.
  • Data Transmission: Uses Start/Stop bits and a configurable baud rate.
  • Advantages:
    • Simple hardware and software implementation.
    • Works over longer distances than I2C and SPI.
  • Disadvantages:
    • Only supports point-to-point communication (no multiple slaves).
    • Speed is limited compared to SPI.
  • Common Use Cases: Debugging, GPS modules, wireless modules (e.g., Bluetooth, Wi-Fi).

📌 SPI (Serial Peripheral Interface)

  • Type: Synchronous, full-duplex communication.
  • Wires: At least 3 lines (MOSI – Master Out Slave In, MISO – Master In Slave Out, SCK – Clock) + Slave Select (SS) for each device.
  • Speed: Can reach 50 Mbps or higher.
  • Data Transmission: Uses shift registers to transmit and receive simultaneously.
  • Advantages:
    • Very fast compared to UART and I2C.
    • Simple hardware (no need for addressing like I2C).
  • Disadvantages:
    • Requires an additional SS (Chip Select) line for each slave device.
    • Not ideal for long-distance communication.
  • Common Use Cases: Display modules, SD cards, flash memory, high-speed ADCs.

📌 CAN (Controller Area Network)

  • Type: Multi-master, priority-based arbitration protocol.
  • Wires: Uses 2 wires (CAN_H, CAN_L) with differential signaling.
  • Speed: 1 Mbps (Classical CAN), 5 Mbps (CAN FD).
  • Data Transmission: Supports message prioritization and error detection.
  • Advantages:
    • Very robust, designed for noisy environments.
    • No master-slave restriction; devices communicate using message IDs.
    • High fault tolerance with error handling.
  • Disadvantages:
    • More complex protocol requiring dedicated hardware controllers.
    • Slower than SPI in data transfer rate.
  • Common Use Cases: Automotive ECUs, industrial automation, medical devices.

3. Protocol Selection Guide

Scenario Recommended Protocol
Need to connect multiple low-speed sensors? I2C
Debugging and simple serial communication? UART
High-speed data transfer between MCU and peripheral? SPI
Reliable communication in a noisy environment (automotive/industrial)? CAN

4. Conclusion

Each communication protocol serves a unique purpose in embedded systems:

  • I2C is ideal for multiple low-speed devices with simple wiring.
  • UART is best for debugging and long-distance point-to-point communication.
  • SPI offers high-speed data transfer for peripherals like memory and displays.
  • CAN is highly reliable for applications requiring real-time communication in noisy environments.

By understanding their differences, you can choose the best protocol based on your embedded system requirements. 🚀