Skip to content
RED SAGSkills
mediumEmbedded Systems Engineer interview question

How would you write a driver for a new I2C temperature sensor?

What the interviewer wants to hear

  • Read the datasheet: address, registers, timing, conversion time
  • Layered design: sensor driver over an I2C bus abstraction
  • Clear API: init, read, configure, with error codes
  • Handle timeouts, NACKs and retries
  • Test with a logic analyser and unit tests with a mocked bus

Model answer

I start with the datasheet: the I2C address, register map, power-on timing, conversion time, data format and any CRC. Then I design layers. The sensor driver does not call the MCU's HAL directly; it uses a small I2C interface, like function pointers for write and read, passed in at init. This makes it portable across MCUs and easy to unit test with a fake bus. The API is simple: sensor_init, sensor_read_celsius, sensor_set_mode, each returning an error code instead of failing silently. Inside, I check the chip ID at init, respect conversion delays, convert raw values with the datasheet formula using fixed point if there is no FPU, and handle NACKs and timeouts with a limited number of retries, plus bus recovery if SDA gets stuck low. I verify the real traffic with a logic analyser, compare readings with a reference thermometer, and write unit tests for the conversion and error paths.

Can you answer it under time pressure?

Take a timed medium round and get scored on every answer.

Start mock interview

More medium Embedded Systems Engineer questions