IO6: Buses and drivers: I2C, SPI, UART and reading a datasheet

Lesson 4 of 5 · reading 15–25 minutes; practice and project time is on the module page

Reading a datasheet

🎯You'll be able to

Find the address, registers, bit fields, timing, byte order, signed values and power modes in a datasheet, and turn them into code.

🏠The everyday picture

A recipe lists ingredients, quantities, oven temperature and time. Skip the "rest the dough 30 minutes" line, and the bread fails, even though you followed everything else.

📘What it really is

📝A worked example

Input: the LV-20 datasheet.

Steps:

  1. Address 0x29; WHO_AM_I at 0x0F is 0x5A.
  2. Start with CTRL (0x20) = 0x01; wait 30 ms or until STATUS (0x27) bit 0 is 1.
  3. Read 3 bytes from 0x28: distance = DIST_L + 256 × DIST_H (little-endian, mm); TEMP is a signed byte in 0.5 °C steps.
  4. Standby: CTRL = 0x00, because the sensor draws 1.5 mA if left on.

Expected output: a page of notes that becomes firmware/sensor.py.

🌍Where it's used

📝Case scenario

A learner read the LV-20 straight after starting a measurement and got the previous reading every time. The datasheet's timing section said 30 ms. Waiting for the ready bit fixed it.

🖱️Try it

Find a datasheet for a real I2C temperature sensor online. Write its address, its ID register (if any), its measurement time and its data format. Success: four facts, each with the page or section where you found it.

⚠️Common mistakes

🛠️For your project

Project 1's tests 1, 2 and 4 come straight from the LV-20 datasheet: the ID, the timing and data format, and standby.

✅Quick check

Which datasheet section tells you when data is valid?

Show the answer

The timing section, such as a measurement time or a ready bit.

Why read the errata?

Show the answer

They list known bugs in the chip that the main datasheet may not mention.

← PreviousUART: serial lines to modems and GPS
ProLearners Assist