Altera_Forum
Honored Contributor
7 years agoTrying to implement SPI slave in Cyclone IV - why this isn't working?
Hi, i'm trying to implement some practical stuff in Cyclone IV. For a start i need SPI slave which will write data received from master to dual port RAM. I'm struggling with basics in SPI receiver code (not much FPGA and HDL experience).
When receiving a byte from SPI master, i want to send back an anternate bit pattern on MISO, triggering MISO state change on a negative edge of the SPI clock. This is not working as expected, as can be seen on attached oscilloscope screenshot. There is something happening at the negative edge of the clock, but it's not a proper state change, jus some miniscule impulse that is immediately shut down back to 0. Of course master reads this received byte as 0x00. Code is synthesized as on attached image. I/O standard for all of the pins is defined as 3.3V LVCMOS. https://alteraforum.com/forum/attachment.php?attachmentid=15067&stc=1 https://alteraforum.com/forum/attachment.php?attachmentid=15065&stc=1 https://alteraforum.com/forum/attachment.php?attachmentid=15066&stc=1
module spi_recv
(
input sclk, mosi, cs,
output miso,
output reg output_byte,
output reg mem_addr,
output memclk,
output mem_we
);
reg bit_counter;
reg memcell_counter;
always @(negedge sclk)
begin
miso <= ~miso;
end
endmodule
As even this is not working as expected, i have stripped the rest of code suspecting that there is some problem in it (still no change).