C12 · Problem set 7
Problem set 7: communication
These problems use lessons 28 to 33: the UART, ring buffers and interrupt-driven serial, I²C, SPI, and serial protocols. The clock is 10 MHz; a UART byte is 10 bits on the wire; an I²C byte is 9 clocks; an SPI byte is 8.
Check
A UART runs at 57600 baud and sends 16 bytes back to back.
(a)
How long is one bit?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
(b)
How long do the 16 bytes take?
Check
The board must run its UART at 115200 baud.
(a)
What BAUDDIV?
(b)
How far off is the actual rate, in percent?
Check
Bytes stream in at 115200 baud; the main loop may be away for 3 ms.
(a)
How many bytes arrive meanwhile?
(b)
What's the smallest power-of-two ring buffer that holds them?
Check
A 32-slot ring buffer has head = 260 and tail = 4990.
(a)
How many bytes are waiting?
(b)
Which slot does the next byte go in?
Check
A receive ISR takes 30 cycles per byte at 115200 baud.
(a)
What share of the processor does it use?
(b)
How much time is there between bytes?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
An I²C device answers at address 3C.
(a)
What byte starts a write to it, in hex?
(b)
And a read?
Check
A register read over I²C at 100 kHz sends 3 bytes in all, plus about two clocks for the start, repeated start and stop.
(a)
About 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.
(b)
About how many such reads fit in a second?
Check
A 12-bit sensor reading arrives left-justified as E7, 40, in sixteenths of a degree, two's complement.
(a)
What's the 12-bit pattern, as an unsigned number?
(b)
What's the temperature?
Check
An I²C bus has 80 pF and needs rise times under 300 ns.
(a)
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.
(b)
What current flows through that pull-up when a device holds the line low?
Check
The SPI runs with CLKDIV = 5 (clock ) and sends 2 bytes.
(a)
What's the SPI clock?
Write units the way you normally would: 1.5 MHz, 1500 kHz and 0.0015 GHz are the same answer.
(b)
How long do the bytes take?
Check
3 shift registers are daisy-chained on SPI at 1 MHz.
(a)
How many outputs do they drive?
(b)
How long does a full update take on the wire?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
A frame has 3 header bytes, then the payload 150, 140, 200, then a checksum byte.
(a)
What's the payload's sum, modulo 256?
(b)
What fraction of the frame is payload?
Check
A display of 4 seven-segment digits is multiplexed: each refresh sends 16 bits over SPI at 1 MHz to light one digit, cycling through all digits 200 times a second.
(a)
What share of the SPI bus does refreshing take?
(b)
What fraction of the time is each digit lit?
Check
A command SET LED n plus newline (4 characters in all) is sent at 9600 baud; a line with a bad checksum is resent, and 4 in 100 lines are bad.
(a)
How long does one line take?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
What is the average time per delivered line, counting resends?
Check
A 24-bit ADC on SPI at 2 MHz is read with 8 extra command bits each time, and the CPU spends 16 cycles setting up each transfer.
(a)
How long is each transfer on the wire?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
(b)
What is the most readings a second it can make, back to back?
Have paper and a calculator ready. Work each problem out by hand, then enter the answer. Your first try on each one counts toward your score.
Practice
Keep practicing
15 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.