0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

概要

micropythonでshrike-lite、やってみた。
spi見つけたので、テストベンチ書いてみた。

参考にしたページ

写真

image.png

テストベンチ

`timescale 1ns / 1ps

module test_tb;
	reg clk;
	reg rst_n;
	reg spi_ss_n;
	reg spi_sck;
	reg spi_mosi;
	reg [7:0] data;
	reg [7:0] rx_data1;
	wire clk_en;
	wire spi_miso;
	integer i,
			j;
	main u(.clk(clk), .clk_en(clk_en), .rst_n(rst_n), .spi_ss_n(spi_ss_n), .spi_sck(spi_sck), .spi_mosi(spi_mosi), .spi_miso(spi_miso), .spi_miso_en(spi_miso_en));
	always
	begin
		wait (spi_ss_n == 0);
		rx_data1 = 8'h55;
		for (j = 7; j >= 0; j = j - 1)
		begin
			@(posedge spi_sck);
			rx_data1[j] = spi_miso;
		end
		$display("【受信完了】     h%h ", rx_data1);
	end
  	initial 
  	begin
    	$dumpfile ("test_tb.vcd");
    	$dumpvars (0, test_tb);
		$monitor(" mosi: %d miso: %d ", spi_mosi, spi_miso);
		clk = 0;
		spi_sck = 0;
		spi_ss_n = 1;
		spi_mosi = 0;
		rst_n = 1;
	#4;
		rst_n = 0;
	#20;
		rst_n = 1;
		spi_ss_n = 0;
		data = 8'h03;
		for (i = 7; i >= 0; i = i - 1)
		begin
			spi_mosi = data[i];
			#20;
		end
		$display("【送信完了 1件目】 h03");
		spi_mosi = 0;
	#20;
		data = 8'h00;
		for (i = 7; i >= 0; i = i - 1)
		begin
			spi_mosi = data[i];
			#20;
		end
		$display("【送信完了 2件目】 h00");
		spi_ss_n = 1;
		spi_mosi = 0;
	#100;
		$finish;
	end
	always
		#1
			clk = ~clk;
	always
		#10
			spi_sck = ~spi_sck;
endmodule




実行結果

8/27/26 7:51 AM > Simulation pipeline iverilog returned an error. Please check the tools log for details.
8/27/26 7:54 AM > Saving the state of the project.
8/27/26 7:54 AM > Launching Simulation
FST info: dumpfile test_tb.vcd opened for output.
 mosi: 0 miso: x 
 mosi: 0 miso: 0 
 mosi: 1 miso: 0 
【受信完了】     h00 
【送信完了 1件目】 h03
 mosi: 0 miso: 0 
 mosi: 0 miso: 1 
 mosi: 0 miso: 0 
【受信完了】     h04 
【送信完了 2件目】 h00
../../sim/test_tb.vt:63: $finish called at 464000 (1ps)

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?