Hi Friends I am trying to make a simple spi module with verilog. After I get the Enable signal, I want to send the 8 bit data in series. I've never worked with a verilog before. I wrote a simple code but I do not know how to generate the clock signal. this is my Code;
1 | `include "cypress.v" |
2 | //`#end` -- edit above this line, do not edit this line
|
3 | // Generated on 03/31/2017 at 15:12
|
4 | // Component: ParalelToSerial
|
5 | module ParalelToSerial ( |
6 | output Busy, |
7 | output Clkout, |
8 | output Dout, |
9 | input Clkin, |
10 | input [7:0] Data, |
11 | input En |
12 | );
|
13 | |
14 | //`#start body` -- edit after this line, do not edit this line
|
15 | reg busy; |
16 | reg dout; |
17 | reg clkout; |
18 | reg [3:0]cnt_spi; |
19 | reg clk_count; |
20 | |
21 | assign Busy = busy; |
22 | assign Dout = dout; |
23 | assign Clkout = clkout; |
24 | |
25 | always @ (negedge Clkin) |
26 | begin
|
27 | if(En == 1'b1 && busy == 1'b0) |
28 | begin
|
29 | clkout=1'b0; |
30 | dout=Data[cnt_spi]; |
31 | cnt_spi = cnt_spi + 1; |
32 | end
|
33 | |
34 | if(cnt_spi == 8) |
35 | busy=1'b0; |
36 | begin
|
37 | |
38 | end
|
39 | end
|
40 | |
41 | //`#end` -- edit above this line, do not edit this line
|
42 | endmodule
|
I will be glad if you help me. I'm just looking for a very simple example of spi.