jakubcabal / spi-fpga

SPI master and SPI slave for FPGA written in VHDL
MIT License
159 stars 38 forks source link

Maximum SCLK frequency on SPI SLAVE module #11

Open federicodesario97 opened 10 months ago

federicodesario97 commented 10 months ago

Hi, firstly your code is very clear and i'm learning a lot from this, so thanks!

Then I was reading in another issue that with a CLK frequency that is at least twice the SCLK frequency the code works fine.

I was trying to use a CLK at 12 MHz and a SCLK at 4 MHz and i found some problem with the MISO of the SPI SLAVE module. Pratically the first 1 sended on the MISO remains too much on it and is sampled two times.

Screenshot 2023-08-09 172400

I'm using a simplified testbench that i can attach here.

SPI_SLAVE_tb.txt

There is something that I can do to fix this problem?

federicodesario97 commented 10 months ago

Another problem that can be seen in the snapshot is that when I send the next code, the MOSI switch correctly but the MISO is sending the previous code. In the shift register infact there is the old code. Am I doing something wrong in the testbench?

SamOrlan commented 1 week ago

From the readme, SCLK must be <= CLK/10: image

With a 12MHz input clock, the maximum SCLK you can safely define is 12MHz/10 = 1.2MHz. If you need the 4MHz SCLK then you'll need a faster input clock

(I literally just found this project and I'm not familiar with the code, just referencing the documentation)