Analyzing I2C signals

Updated on 23 September 2022
dev board Arduino UNO
chip Si7021
tool Saleae Logic Analyser
features I2C logic analyser
This tutorial is more than 1 year old. If the steps below do not work, then please check the latest versions and the documentations of the individual tools used.

Before starting

Dependancies

Ensure the following dependancies are downloaded and available:

Code

Download code logic-analyzer-i2c.ino
#include "Adafruit_Si7021.h"

Adafruit_Si7021 sensor = Adafruit_Si7021();

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
  Serial.println("Start Si7021");

  if (!sensor.begin()) {
    Serial.println("Did not find Si7021 sensor!");
    while (true) {}
  } else {
    Serial.println("Temperature in Celsius:");
  }
}

void loop() {
  Serial.println(sensor.readTemperature());

  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);

  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
}

Makefile

BOARD?=arduino:avr:uno
PORT?=/dev/cu.usbmodem14*

.PHONY: default lint all flash clean

default: lint all flash clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright *.ino

all:
	arduino-cli compile --fqbn $(BOARD) ./

flash:
	arduino-cli upload --fqbn $(BOARD) --port $(PORT)

clean:
	rm -r build

Prototype

A photo of the actual setup.

Analyzing I2C signals prototype

Schematic

Wire up the hardware accordingly

Analyzing I2C signals schematic

Serial console

Serial output from the firmware.

Analyzing I2C signals serial console

Description

View the decoded I2C signal from the graph produced by Saleae to read temperature from an Si7021 breakout board.

Capture the signal in Saleae:

Add asynchronous serial to decode the captured signal:

MS Byte for temperature is 0x6D and LS Byte for temperature is 0xAC which is 0x6DAC in hexadecimal and 28076 in decimal. Using the equation given in the datasheet, the temperature in Celcius is 28076*175.72 / 65536 - 46.85 = 28, 28 C, which is same as what is shown in the serial monitor.

References

Watch