使用SPI协议将数据从FPGA发送到Raspberry Pi

问题描述

我有一个FPGA,我想使用RaspBerry pi和SPI协议(其中从设备是FPGA)捕获FPGA内的工作值(通常为4个字节)。 Rpi输出ar_clk和ar_en(enable)。 FPGA输出ar_dat(data)。我的问题是我有时会想念一下。我的以下VHDL代码应执行以下操作:当使能引脚(ar_en)变为零或ar_clk引脚转换为低电平时,FPGA等待约1024个计数,并将数据位放入ar_dat引脚。然后,它有时间放松,直到ar_clk的上升沿被Rpi读取。 在VHDL代码下面是我的Python代码。 python代码应在ar_clk的上升沿读取ar_dat。 我两者之间的电缆长度约为1m。信号从o镜看起来很干净。我使用来自RJ45电缆的红色,蓝色和橙色线,所有其他5端的Rpi(pin6)接地,并通过定制的有线RJ45连接器接地,我的FPGA板上的5端接地。我有一个Deo Nano Soc板插入PCB板。 请帮助我找到想念我的地方/原因。

 screen_shot : process(CLK)
      begin
            if rising_edge(CLK) then
                if ar_en = '1' then  -- (purple cable orange wire[24]) -- Initializes these 5 when high
                        ss_timer <= (others => '0'); -- 32 bit SLV
                        ss_value <= (others => '0'); -- 32 bit SLV 
                        ss_cntr  <= 1; -- 0 to 1023 integer
                        ss_word  <= 0; -- 0 to 1023 integer
                        ar_dat <= '0'; -- data bit to RaspBerry Pi
                end if;
                            
            if ar_en = '0' then -- (purple cable orange wire[24]) The SDI data enable bit
                ss_timer <= ss_timer + 1; -- 
                
                if ar_clk = '1' then --  10240 Hz from RaspBerry Pi
                    ss_timer <= (others => '0');
                end if;
                
                if ar_clk = '0' then-- (purple cable green wire[23])
                    
                    if ss_timer = 1024 then  -- This is an abitrary time to make sure value is set and settled
                        ar_dat <= ss_value(31- ss_word);  -- Put bit before rising edge (purple cable blue wire[21])
                    end if;
                
                    if ss_timer = 1024 + 5 then
                        ss_word <= ss_word + 1;
                    end if;
                    
                    if ss_word = 32 and ss_timer = 1024 + 10 then
                        ss_cntr <= ss_cntr + 1;
                    end if;
                                
                    if ss_word = 32 and ss_timer = 1024 + 15 then
                        ss_word <= 0;
                    end if;
                end if; -- if ar_clk = '0'
                            
                case ss_cntr is
                    when 1 =>  ss_value <= "10101010101010101010101010101010";
                    when 2 =>  ss_value <= "10101010101010101010101010101010";
                    when 3 =>  ss_value <= "10101010101010101010101010101010";
                    when 4 =>  ss_value <= "10101010101010101010101010101010";
                    when 5 =>  ss_value <= "10101010101010101010101010101010";
                    when others => ss_value <= "11111110101010101010101010101010";
                end case;               
        
            end if; -- if ar_en = '0'
            
        end if; -- Rising Edge
        
  end process;

Python代码

import spidev
import time
spi = spidev.SpiDev()
print("start")
spi.open(0,0)
spi.mode = 0b00
spi.max_speed_hz =10240
#print(val)
for j in range(0,2):
    val = spi.readbytes(20)
    print(val)
spi.close()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)