58. Multi-Master interface with I2C 16x2-LCD

The task is to set up I²C communication between two master microcontrollers and a 16x2 LCD (slave) using the PCF8574 I²C module, enabling both masters to display their respective data on a shared LCD screen.

Requirements

  • Master 1: Displays the system uptime (start time) on LCD line 1.
  • Master 2: Reads the potentiometer’s ADC value and displays it on LCD line 2.
  • Implement multi-master I²C communication to ensure both masters can transmit data to the LCD without interference.
  • The LCD should continuously display Uptime and ADC Value from both masters in real-time.

Multi-Master I²C Concept

In a multi-master I²C system, multiple masters share the same SDA (data) and SCL (clock) lines.

Arbitration ensures that only one master controls the bus at a time:

  • Each master checks if the bus is idle (SDA and SCL HIGH).
  • During transmission, it monitors SDA.
  • If a master sends HIGH but reads LOW, it loses arbitration and stops, allowing the winning master to continue.

This process of arbitration is automatically handled by hardware, while synchronisation keeps all devices aligned in timing — enabling reliable communication with shared peripherals like the LCD using minimal wiring.

LCD16x2 with I²C Module (PCF8574)

  • The PCF8574 I²C module makes it easy to connect an LCD16x2 display to a microcontroller using only two pins – SDA and SCL.
  • It reduces GPIO usage from 6 (in 4-bit mode) to just 2 lines.
  • The module also includes a contrast adjustment potentiometer and built-in pull-up resistors for SDA and SCL.
  • It supports both 16x2 and 20x4 LCDs.
  • Simply connect the module to the LCD and link SDA, SCL, VCC, and GND to the microcontroller.

LCD 4-Bit Communication (Working Principle)

In 4-bit mode, the LCD uses only D4–D7 data pins.
Each 8-bit instruction or data byte is sent in two 4-bit parts (high nibble first, then low).

  • RS (Register Select): 0 = Command, 1 = Data
  • RW (Read/Write): 0 = Write (usually fixed LOW)
  • EN (Enable):HIGH→LOW pulse latches each nibble.
  • Command Register: Controls LCD (clear, set cursor, etc.)
  • Data Register: Displays characters on the screen
  • Before use, initialize the LCD with these commands:
     0x33, 0x32, 0x28, 0x0C, 0x06, 0x01
LCD16x2-I2C

Hardware Connection:

  1. Connect 5V and GND from any master to the LCD module.
  2. Connect the SDA and SCL of both masters and the LCD together.
  3. Enable internal or External pull-up resistors for SDA and SCL lines.
  4. Connect the potentiometer to Master 2’s ADC pin.
  5. Ensure a common GND across all devices.

Implementation Platforms:

This task will be implemented on the following microcontrollers:

  1. STM32
  2. ESP32
  3. Arduino UNO

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!