S7.5.1 Read an SPI Exchange

EasyImplement12 minIcarus Verilog · serverReview the topic

Read one SPI exchange, bit by bit: find chip select, the serial clock, the command byte and the three bytes of the answer.

Hardware context: SPI controller of ap_soc with one target on its four wires, and one open-drain wire as on I2C. Reading an SPI exchange on a logic analyser during bring-up

This capture comes from the SPI controller of lesson S7.5, with another command and another target: a small sensor. Software wrote one command byte to the controller. The controller ran one exchange. The sensor answered after the command.

This worksheet uses named constants. The first three entries show how to record your decisions.

Signals in the Timeline

SignalWidthRole
question8input of each check
Full specification
System clock edgeWhat this edge seesMOSI (data out)MISO (data in)
4Chip select is seen at 0
6Rising serial clock, bit 010
10Rising serial clock, bit 100
14Rising serial clock, bit 210
18Rising serial clock, bit 300
22Rising serial clock, bit 400
26Rising serial clock, bit 510
30Rising serial clock, bit 610
34Rising serial clock, bit 700
38Rising serial clock, bit 800
42Rising serial clock, bit 900
46Rising serial clock, bit 1001
50Rising serial clock, bit 1101
54Rising serial clock, bit 1201
58Rising serial clock, bit 1301
62Rising serial clock, bit 1400
66Rising serial clock, bit 1500
70Rising serial clock, bit 1601
74Rising serial clock, bit 1700
78Rising serial clock, bit 1800
82Rising serial clock, bit 1901
86Rising serial clock, bit 2000
90Rising serial clock, bit 2100
94Rising serial clock, bit 2200
98Rising serial clock, bit 2301
102Rising serial clock, bit 2400
106Rising serial clock, bit 2501
110Rising serial clock, bit 2600
114Rising serial clock, bit 2701
118Rising serial clock, bit 2800
122Rising serial clock, bit 2901
126Rising serial clock, bit 3001
130Rising serial clock, bit 3101
132Chip select is seen at 1

Each row is something that one rising edge of the system clock sees. Edges are numbered from 0. A row with a bit number is the first system clock edge that sees the serial clock high. The highest bit of each byte travels first. Enter edges and counts as plain numbers, and each byte as a decimal number.

EntryYour decision
SELECT_EDGEFirst edge that sees chip select low.
FIRST_BIT_EDGEEdge of the first rising serial clock.
SCLK_PERIODOne period of the serial clock, in system clocks.
COMMANDThe command byte that the controller sent.
ANSWER_STARTBit number of the first bit of the answer.
ANSWER_1First byte of the answer.
ANSWER_2Second byte of the answer.
ANSWER_3Third byte of the answer.
FILLERValue on MOSI while the sensor answers.
SERIAL_CLOCKSNumber of rising edges of the serial clock in the exchange.
RELEASE_EDGEFirst edge that sees chip select high again.
LOW_CLOCKSNumber of system clock edges that see chip select low.
LOW_NFor how many system clock edges would chip select be low in an exchange of one command byte and N answer bytes, at this serial clock?

Examples

Example 1

SELECT EDGE
Input
First edge that sees chip select low.
Output
matches = 1

The row for edge 4 says that chip select is seen at 0.

Example 2

FIRST BIT EDGE
Input
Edge of the first rising serial clock.
Output
matches = 1

Bit 0 is at edge 6, two edges after chip select fell.

Example 3

SCLK PERIOD
Input
One period of the serial clock, in system clocks.
Output
matches = 1

Bit 0 is at edge 6 and bit 1 at edge 10. The rises are 4 edges apart.

Constraints and Contract

  • Keep the parameter and named constants. Use the numeric codes and units on this page.
  • For LOW_N, enter a constant expression using N. Only this entry changes with the parameter. The supported integer range is 0 through 6, inclusive.

Hints

Hint 1

Chip select marks the exchange. Its two rows give the first and the last edge.

Hint 2

Take the edges of two bits next to each other. Their difference is one period of the serial clock.

Hint 3

Group the bits in eights. The first bit of a group is the highest bit of the byte.

What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.

13 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 1 problem on this path

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

SELECT EDGE

Input
First edge that sees chip select low.
Expected output
matches = 1

The row for edge 4 says that chip select is seen at 0.

Run samples executes all 3 public checks. Check all tests runs 13 checks on the server.

Icarus Verilog · server