Forum Discussion
9 Replies
- AndyN
Occasional Contributor
You really need to take a look at your process sensitivity list - there is no way that this would be synthesizable (and may be the cause of your simulation issues). From the looks of your code, I'd say the only thing that should be in your sensitivity list is clk. For this kind of interface, you don't really want to use sclk as a true clock, use it as a signal to tell you when to sample/control the rest of the SPI interface.
- RRomano001
Contributor
Hi, also second process has no edge, so it is async, sensitivity list has no sense how is used as noted from AndyN.
Reset if used on async has no sense on clock event:
when INIT=> if cs_n='0' and reset_n ='1' then state <= DF; else state <= INIT; end if;second process has no event so it is Async.
- process(state, sclk, din, cs_n, clk) is
- begin
- case state is
- when INIT =>
- -- new_data <='0';
- counter <= 0;
- t_bus <= "00100000000000000";
- -- regnr<="00";
- -- regwrite_n<='1';
- -- regcontent<=(others=> '0');
try read this book, you can find an example of SPI and how to code in VHDL.
https://www.scribd.com/document/364557756/Beginning-FPGA-Programming-Metal-Your-Brain-on-Hardware
- KhaiChein_Y_Intel
Regular Contributor
Hi,
Can you explain the meaning of the variables used ?
Thanks.
- VALLA
New Contributor
Hi. I sorted it out. That was racing issue.
- RRomano001
Contributor
Hi, clean up code and learn VHDL event.
at second glance, many issue are on your code, don't use elsif with event:
if reset_n ='0' then .. reset actions else if rising_edge(clk) then .. clock event end if; -- clock event end if; -- resetSecond process:
State is a signal assigned from clock on first process, can be ok but if you wish state be an event remove conflicting rising_edge on midst of code.
First process is event driven from rising edge of same clk.
On SPI need use both rising and falling clock event, derive them from an edge detector or code the right way, receiving on one edge transmitting on the other edge.
I assume this is a slave SPI, so your clock is slow (5MHz) and you own a fast clock too.
Sample SPI on a two/three stage shift register on fast clock then check for rising falling sequence 001 110.
Drive all logic from fast clock using edge detector as clock enable.
Second process as case assignment instead of combinatorial when else need have just case in sensitivity list.
try post cleaned code.
Regards
- VALLA
New Contributor
Thank you so much for understanding it very deeply. Actually what you said makes sense prpperly. But, this is my lab task and I got some instructions. So that I couldn't go with edge detection method using faster clock. Thank you.