CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 06:50:10 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=003887ac1d06b758e345866b1b29584bf71a5dc69fe0f9415b40cf3b50ae51cfa%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22JKXcy6vZ71kRfUWw7NzJdxkNXfqZXQc2%22%3B%7D; HttpOnly; Path=/
cf-ray: 98cc6bf4bc06e084-BLR
spi.v - Pastebin.com
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Format: [R/W bit, addr, msg] **/
- module soft_spi_slave
- #(
- parameter msg_width = 32,
- parameter addr_width = 7,
- localparam rw_bit = 1,
- localparam meta_width = rw_bit + addr_width,
- localparam data_width = msg_width - meta_width,
- localparam counter_width = $clog2(msg_width),
- localparam data_counter_width = $clog2(data_width)
- )
- (
- // General signals
- input rst,
- // SPI MCU connections
- input sck,
- input ncs,
- output reg so,
- input si,
- // SPI Control
- output reg [addr_width-1:0] addr,
- output reg addr_ready,
- output reg rw, // 1 is read 0 is write
- output reg rw_ready,
- output reg [data_width-1:0] data_out,
- output reg data_ready,
- input [data_width-1:0] data_in // Must be ready within 1 serial clock cycle
- );
- // Wires
- wire spi_rst = rst || ncs;
- // Counters
- wire [counter_width-1:0] data_count;
- spi_counter SPI_CNT(
- .clk_i(~sck),
- .clk_en_i(~ncs),
- .aclr_i(spi_rst),
- .q_o(data_count)
- );
- // Data shift reg (needs 1 less bit due to how last bit is handled to reduce output latency and allow consecutive packets)
- reg [data_width-2:0] data_reg;
- // condition flags
- wire rw_ready_c = data_count == 0;
- wire addr_ready_c = data_count == (addr_width + rw_bit) - 1;
- wire data_ready_c = data_count == (msg_width) - 1;
- // Incoming data shift reg
- always @ (posedge sck or posedge spi_rst) begin
- if (spi_rst) begin
- // Reset outputs
- rw <= 0;
- rw_ready <= 0;
- addr_ready <= 0;
- data_ready <= 0;
- // Reset registers
- data_reg <= 0;
- addr <= 0;
- data_out <= 0;
- end else begin
- // Shifting into the data register
- data_reg <= {data_reg[data_width-3:0], si};
- // Check the R/W bit
- if (rw_ready_c) begin
- rw <= si;
- rw_ready <= 1;
- end else if (data_ready_c) begin
- rw <= 0;
- rw_ready <= 0;
- end
- // Check when the address portion is fully received and move it to the output
- if (addr_ready_c) begin
- addr <= {data_reg[addr_width-2:0], si};
- addr_ready <= 1;
- end else if (data_ready_c) begin
- addr <= 0;
- addr_ready <= 0;
- end
- // Check when the entire message is received
- if (data_ready_c) begin
- data_out <= {data_reg[data_width-2:0], si};
- data_ready <= 1;
- end else if (rw_ready_c) begin
- data_out <= 0;
- data_ready <= 0;
- end
- end
- end
- // Data out handling
- always @ (negedge sck or posedge spi_rst) begin
- if (spi_rst) begin
- // Reset outputs
- so <= 0;
- end else begin
- // Counter overflow, prepare for another data packet
- if (addr_ready && (data_count < (msg_width - 1))) begin
- // Shift out the outgoing data
- so <= data_in[msg_width - (data_count + 2)];
- end else begin
- so <= 0;
- end
- end
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐✅ Trading Profit Method ✅ NEVER SEEN BEFORE...
JavaScript | 3 sec ago | 0.24 KB
-
✅⭐ Make huge profits on trading ⭐⭐ 4
JavaScript | 5 sec ago | 0.24 KB
-
⭐ Instant BTC Profit Method ✅ NEVER SEEN BEFO...
JavaScript | 12 sec ago | 0.24 KB
-
⭐✅ MAKE $2500 IN 15 MIN⭐⭐⭐ T
JavaScript | 18 sec ago | 0.24 KB
-
⭐✅ MAKE $2000 INSTANTLY ✅ NEVER SEEN BEFORE ⭐...
JavaScript | 21 sec ago | 0.24 KB
-
⭐✅ Exploit 2500$ in 15 Minutes⭐⭐⭐ V
JavaScript | 30 sec ago | 0.24 KB
-
⭐ Free Crypto Method ✅ NEVER SEEN BEFORE ⭐⭐⭐
JavaScript | 30 sec ago | 0.24 KB
-
Free Crypto Method (NEVER SEEN BEFORE)⭐⭐ D
JavaScript | 42 sec ago | 0.24 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand