Infinite Loop using While

In reply to haykp:

After looking into Waveform, @cgales is correct when cs is low clk is not there.so it obvious it will stuck into while loop.

workaround - you can have one more clock which is one clock advance to spi_clk,use this advance clk so that last posedge of adv.clock will detect the cs==0 condition and it will comeout from loop.

However its just a workaround not the good practice ;)