C12 Embedded systems in MicroPython and C · Practice
I²C: talking to a temperature sensor
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
A device's address is 48. What's the first byte after start to 0? (0 write, 1 read)
Check
A positive reading arrives as 19, 00. What's the temperature?
Check
In 12-bit two's complement at 0.0625 °C per count, what raw value does −10 °C produce?
Check
At 100 kHz, a transaction sends 2 bytes (each 9 clocks) plus about one clock for the start and stop. How long does it take?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
The bus has 50 pF and must rise in 300 ns. What's the largest pull-up?
Write units the way you normally would: 1.5 kΩ, 1500 Ω and 0.0015 MΩ are the same answer.
Check
A temperature sensor sits somewhere on the I²C bus. Scan every address from 0x08 to 0x77 and print the one that acknowledges.
C on the course's RISC-V board (10 MHz, no floating point). #include "board.h" for the registers; print(x) shows a number. Tab indents; press Esc and then Tab to move on.
Check
The sensor at 0x48 is below freezing. Read it and print its temperature in °C, handling negative values.
MicroPython on the course's board: machine (Pin, PWM, ADC, DAC, UART, I2C, SPI, Timer, WDT) and time. Each call into the hardware takes about 40 µs. Tab indents; press Esc and then Tab to move on.
Check
An I²C bus has 50 pF and must rise in 300 ns.
(a)
What is the largest pull-up?
Write units the way you normally would: 1.5 kΩ, 1500 Ω and 0.0015 MΩ are the same answer.
(b)
What current does a device sink pulling it low?
Check
A temperature sensor returns bytes 50 then 128; the reading is the 16-bit value shifted right by 4, in sixteenths of a degree, and positive here.
(a)
What is the 12-bit reading?
(b)
What temperature?
Check
First byte to address 20, direction 0?
Check
Temperature from 0A, 40?
Check
Largest pull-up for 150 pF at 100 kHz?
Write units the way you normally would: 1.5 kΩ, 1500 Ω and 0.0015 MΩ are the same answer.
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in C12