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
| Signal | Width | Role |
|---|---|---|
question | 8 | input of each check |
Full specification
| System clock edge | What this edge sees | MOSI (data out) | MISO (data in) |
|---|---|---|---|
| 4 | Chip select is seen at 0 | ||
| 6 | Rising serial clock, bit 0 | 1 | 0 |
| 10 | Rising serial clock, bit 1 | 0 | 0 |
| 14 | Rising serial clock, bit 2 | 1 | 0 |
| 18 | Rising serial clock, bit 3 | 0 | 0 |
| 22 | Rising serial clock, bit 4 | 0 | 0 |
| 26 | Rising serial clock, bit 5 | 1 | 0 |
| 30 | Rising serial clock, bit 6 | 1 | 0 |
| 34 | Rising serial clock, bit 7 | 0 | 0 |
| 38 | Rising serial clock, bit 8 | 0 | 0 |
| 42 | Rising serial clock, bit 9 | 0 | 0 |
| 46 | Rising serial clock, bit 10 | 0 | 1 |
| 50 | Rising serial clock, bit 11 | 0 | 1 |
| 54 | Rising serial clock, bit 12 | 0 | 1 |
| 58 | Rising serial clock, bit 13 | 0 | 1 |
| 62 | Rising serial clock, bit 14 | 0 | 0 |
| 66 | Rising serial clock, bit 15 | 0 | 0 |
| 70 | Rising serial clock, bit 16 | 0 | 1 |
| 74 | Rising serial clock, bit 17 | 0 | 0 |
| 78 | Rising serial clock, bit 18 | 0 | 0 |
| 82 | Rising serial clock, bit 19 | 0 | 1 |
| 86 | Rising serial clock, bit 20 | 0 | 0 |
| 90 | Rising serial clock, bit 21 | 0 | 0 |
| 94 | Rising serial clock, bit 22 | 0 | 0 |
| 98 | Rising serial clock, bit 23 | 0 | 1 |
| 102 | Rising serial clock, bit 24 | 0 | 0 |
| 106 | Rising serial clock, bit 25 | 0 | 1 |
| 110 | Rising serial clock, bit 26 | 0 | 0 |
| 114 | Rising serial clock, bit 27 | 0 | 1 |
| 118 | Rising serial clock, bit 28 | 0 | 0 |
| 122 | Rising serial clock, bit 29 | 0 | 1 |
| 126 | Rising serial clock, bit 30 | 0 | 1 |
| 130 | Rising serial clock, bit 31 | 0 | 1 |
| 132 | Chip 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.
| Entry | Your decision |
|---|---|
| SELECT_EDGE | First edge that sees chip select low. |
| FIRST_BIT_EDGE | Edge of the first rising serial clock. |
| SCLK_PERIOD | One period of the serial clock, in system clocks. |
| COMMAND | The command byte that the controller sent. |
| ANSWER_START | Bit number of the first bit of the answer. |
| ANSWER_1 | First byte of the answer. |
| ANSWER_2 | Second byte of the answer. |
| ANSWER_3 | Third byte of the answer. |
| FILLER | Value on MOSI while the sensor answers. |
| SERIAL_CLOCKS | Number of rising edges of the serial clock in the exchange. |
| RELEASE_EDGE | First edge that sees chip select high again. |
| LOW_CLOCKS | Number of system clock edges that see chip select low. |
| LOW_N | For 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