is shown in Table 4.
We can’t very well talk about decoding a
command without first discussing our
command format. The I/O control module will
accept an eight-bit byte in the format as in
As you can see, the upper nibble is the
command and the lower nibble is the ROM
read address. The module will respond to only
one command — 0x1 — which sets the ROM
read address as discussed earlier.
So, how do we decode a command? First,
the module checks if a command has been
received (cmd_rdy). If it has, we verify that the
upper nibble is equal to 0x1. If it is,
we transfer the address stored in the
lower nibble of the received
command to the ROM read address
register in the module. Pretty easy,
right? However, there is one catch.
How do we respond to
subsequent read operations? If a command is not ready
and the SPI slave module is requesting more data
(data_req_edge), then we will increment the ROM read
address register by one. The logic diagram is shown in
With everything glued together, it’s time to verify
operation of the SPI serial ROM. I wrote a test bench
(spi_rom_tb.v) which essentially “bit bangs” the SPI
protocol at a 1 MHz SPI clock rate to test our module.
Two operations we need to test are the command
decoding logic and the incrementing of the ROM read
address for subsequent reads. The test sequence is as
1. Initialize the SPI bus to an idle
2. Send a command to the SPI serial
ROM to set the ROM read address to
3. Read two bytes from the SPI serial
Let’s take a look at Screenshot 1 to
verify our SPI serial ROM operation. Our
module first receives the command 0x14
which sets the ROM read address to 0x4.
At the same time, the SPI serial ROM is
sending the ROM data from address 0x0
(the initial reset value for the ROM read
address) to the SPI master. This data is the
letter ‘H,’ or ASCII code 0x48.
The next two read operations output data from
addresses 0x4 and 0x5, which are ‘o' and ‘,' (ASCII comes
0x6F and 0x2C). Everything works as advertised!
Let’s get this loaded on the Mojo V3 and test it with
our Microstick II.
July 2016 51
CONNECTION MOJO V3 PIN MICROSTICK II PIN
SCK 93 18
MOSI 142 17
MISO 143 16
SS 144 3
Ground GND 27
SCREENSHOT 1. SPI serial ROM test bench.
SCREENSHOT 2. SPI serial ROM test.