Forum Discussion
Hi. I sorted it out. That was racing issue.
- RRomano0016 years ago
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
- VALLA6 years ago
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.
- RRomano0016 years ago
Contributor
In first process you are sampling cs by a faster clock. This faster clock has nothing to do with SCLK of SPi.
Am I right? So you cannot count bit from clk, you need do instead from SCLK edges.
If process is run from clk the only alternative is to sample slow sclk and derive edges to count bit and shift in/out data. Or add another process where clock is SCLK.
Is this an SPI or just some way of lab with off topic name?
Regards
- VALLA6 years ago
New Contributor
Main clock (clk) which is faster is responsible for this SPI slave's IO ports and internal state actions on rising edge synchronization. Sclk is to fetch data from Serial data in port (din) within 17cycles on falling edge. you can see it as a mosi.