<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 基于FPGA的數(shù)據(jù)并轉(zhuǎn)串SPI發(fā)送模塊的設(shè)計(jì)

          基于FPGA的數(shù)據(jù)并轉(zhuǎn)串SPI發(fā)送模塊的設(shè)計(jì)

          作者: 時(shí)間:2017-06-05 來源:網(wǎng)絡(luò) 收藏

          一、摘要:

          接口應(yīng)用十分廣泛,在很多情況下,人們會用軟件模擬的方法來產(chǎn)生 時(shí)序或是采用帶 功能模塊的MCU。但隨著可編程邏輯技術(shù)的發(fā)展,人們往往需要自己設(shè)計(jì)簡單的SPI 發(fā)送模塊。本文介紹一種基于 的將并行數(shù)據(jù)以SPI 串行方式自動發(fā)送出去的方法。

          二、關(guān)鍵字:

          、、SPI、串行數(shù)據(jù)輸出選擇模塊、移位脈沖產(chǎn)生模塊、SPI 時(shí)鐘采集信號和無相移的SPI 基準(zhǔn)時(shí)鐘產(chǎn)生模塊、SPI 時(shí)鐘輸出選擇模塊、8bit SPI 時(shí)鐘采集生成模塊、16bit SPI 時(shí)鐘采集生成模塊、24bit SPI 時(shí)鐘采集生成模塊、8bit 數(shù)據(jù)移位模塊、16bit 數(shù)據(jù)移位模塊、24bit 數(shù)據(jù)移位模塊。

          三、功能框圖:


          SPI_MODES 為輸入模式選擇端口:
          --01is 8bit 傳輸模式
          --10is 16bit 傳輸模式
          --11is 24bit 傳輸模式

          CLKS 為整個(gè)模塊的基準(zhǔn)時(shí)鐘

          DBINOUTS 為并行數(shù)據(jù)輸入端口:
          --8bit 模式為DBINOUTS(7 downto 0)
          --16bit 模式為DBINOUTS(15 downto 0)
          --24bit 模式為DBINOUTS(23 downto 0)

          SPI_WR 為啟動SPI 傳輸?shù)男盘?br />
          整個(gè)功能模塊可工作在 8bit、16bit、24bit SPI 猝發(fā)傳輸狀態(tài)。對其進(jìn)行軟件操作的步驟相當(dāng)簡單:
          --此模塊軟件操作流程如下
          --1、SPI_MODES=xx 設(shè)定串口操作模式
          --2、DBINOUTS=xxxxxxxxxxxxxxxxxxxxxxxx 輸入要發(fā)射的數(shù)據(jù)
          --3、SPI_WR='0'
          --4、SPI_WR='1'
          --5、SPI_WR='0'
          --8bit 模式延時(shí)2*8*4*CLKS
          --16bit 模式延時(shí)2*16*4*CLKS
          --24bit 模式延時(shí)2*24*4*CLKS
          --6、DBINOUTS=xxxxxxxxxxxxxxxxxxxxxxxx 輸入下一個(gè)要發(fā)射的數(shù)據(jù)

          四、 描述解讀

          --以下描述的是一個(gè)SPI 自動發(fā)射模塊
          --在很多情況下,人們會用軟件模擬的方法來產(chǎn)生SPI 時(shí)序
          --這里采用硬件的方法,即使軟件操作更為簡單,有提高了傳輸?shù)乃俣?br />--------------------------------------------------------------
          --此模塊軟件操作流程如下

          --1、SPI_MODES=xx 設(shè)定串口操作模式
          --2、DBINOUTS=xxxxxxxxxxxxxxxxxxxxxxxx 輸入要發(fā)射的數(shù)據(jù)
          --3、SPI_WR='0'
          --4、SPI_WR='1'
          --5、SPI_WR='0'
          --8bit 模式延時(shí)2*8*4*CLKS
          --16bit 模式延時(shí)2*16*4*CLKS
          --24bit 模式延時(shí)2*24*4*CLKS
          --6、DBINOUTS=xxxxxxxxxxxxxxxxxxxxxxxx 輸入下一個(gè)要發(fā)射的數(shù)據(jù)
          library ieee;
          use ieee.std_logic_1164.all;
          use ieee.std_logic_unsigned.all;
          entity SPI_interface is
          port(CLKS :in std_logic; --基準(zhǔn)時(shí)鐘
          LCD_SCLS :out std_logic;--SPI 發(fā)射時(shí)鐘,上升沿有效
          LCD_SDIS :out std_logic;--SPI 數(shù)據(jù)串行輸出口
          SPI_MODES :in std_logic_vector(1 downto 0);

          --串口操作模式選擇
          --01is 8bit trans mode
          --10is 16bit trans mode
          --11is 24bit trans mode
          SPI_WR :in std_logic; --啟動串口發(fā)送信號
          DBINOUTS :in std_logic_vector(23 downto 0));

          --背發(fā)送數(shù)據(jù)的并行輸入口
          --8bit mode use DBINOUTS(7 downto 0)
          --16bit mode use DBINOUTS(15 downto 0)
          --24bit mode use DBINOUTS(23 downto 0)
          end;
          architecture SPI_interface_behav of SPI_interface is
          signal DB8BIT_reg :std_logic_vector(7 downto 0); --8bit 數(shù)據(jù)移位寄存器
          signal DB16BIT_reg :std_logic_vector(15 downto 0);--16bit 數(shù)據(jù)移位寄存器
          signal DB24BIT_reg :std_logic_vector(23 downto 0);--24bit 數(shù)據(jù)移位寄存器
          signal counter4 :std_logic_vector(3 downto 0); --移位脈沖產(chǎn)生計(jì)數(shù)器
          signal counter4s :std_logic_vector(1 downto 0); --SPI 時(shí)鐘生成計(jì)數(shù)器
          signal counter8 :std_logic_vector(4 downto 0); --8bit SPI 時(shí)鐘控制計(jì)數(shù)器
          signal counter16 :std_logic_vector(5 downto 0); --16bit SPI 時(shí)鐘控制計(jì)數(shù)器
          signal counter24 :std_logic_vector(5 downto 0); --24bit SPI 時(shí)鐘控制計(jì)數(shù)器
          signal shift :std_logic;--移位時(shí)鐘脈沖
          signal LCD_SCLSS :std_logic;--SPI 時(shí)鐘采集信號
          signal LCD_SCLSSS :std_logic;--無相移的SPI 基準(zhǔn)時(shí)鐘
          signal LCD_SCLSS8 :std_logic;--8bit SPI 時(shí)鐘信號
          signal LCD_SCLSS16 :std_logic;--16bit SPI 時(shí)鐘信號
          signal LCD_SCLSS24 :std_logic;--24bit SPI 時(shí)鐘信號
          signal LCD_SDIS_8BIT :std_logic;--8bit SPI 數(shù)據(jù)信號
          signal LCD_SDIS_16BIT :std_logic;--16bit SPI 數(shù)據(jù)信號
          signal LCD_SDIS_24BIT :std_logic;--24bit SPI 數(shù)據(jù)信號
          begin

          --串行數(shù)據(jù)輸出選擇模塊
          u1:process(LCD_SDIS_8BIT,LCD_SDIS_16BIT,LCD_SDIS_24BIT,SPI_MODES)
          begin
          if SPI_MODES=01 then --選擇8bit 串行數(shù)據(jù)輸出
          LCD_SDIS=LCD_SDIS_8BIT;
          elsif SPI_MODES=10 then --選擇16bit 串行數(shù)據(jù)輸出
          LCD_SDIS=LCD_SDIS_16BIT;
          elsif SPI_MODES=11 then --選擇24bit 串行數(shù)據(jù)輸出
          LCD_SDIS=LCD_SDIS_24BIT;
          else LCD_SDIS='1';
          end if;
          end process;

          --移位脈沖產(chǎn)生模塊
          u2:process(CLKS)
          begin
          if CLKS='1' and CLKS'event then
          if counter4=0011 then
          counter4=0000;
          shift ='1';
          else counter4=counter4+1;
          shift ='0';
          end if;
          end if;
          end process;

          --SPI 時(shí)鐘采集信號和無相移的SPI 基準(zhǔn)時(shí)鐘產(chǎn)生模塊
          u3:process(CLKS)
          begin
          if CLKS='1' and CLKS'event then
          if counter4s11 then
          counter4s=counter4s+1;
          else counter4s=00;
          end if;
          end if;
          LCD_SCLSS=counter4s(0); --SPI 時(shí)鐘采集信號
          LCD_SCLSSS=counter4s(1); --無相移的SPI 基準(zhǔn)時(shí)鐘
          end process;

          --SPI 時(shí)鐘輸出選擇模塊
          u4:process(LCD_SCLSS8,LCD_SCLSS16,LCD_SCLSS24,SPI_MODES)
          begin
          if SPI_MODES=01 then
          LCD_SCLS=LCD_SCLSS8; --選擇8bit SPI 時(shí)鐘模式
          elsif SPI_MODES=10 then
          LCD_SCLS=LCD_SCLSS16; --選擇16bit SPI 時(shí)鐘模式
          elsif SPI_MODES=11 then
          LCD_SCLS=LCD_SCLSS24; --選擇24bit SPI 時(shí)鐘模式
          else LCD_SCLS='1';
          end if;
          end process;

          --8bit SPI 時(shí)鐘采集生成模塊

          counter8_u:process(LCD_SCLSS)
          begin
          if SPI_WR='1' then
          counter8=10001;
          elsif LCD_SCLSS='1' and LCD_SCLSS'event then
          if counter8>0 then
          counter8=counter8-1;
          LCD_SCLSS8=LCD_SCLSSS;
          end if;
          end if;
          end process;
          --16bit SPI 時(shí)鐘采集生成模塊
          counter16_u:process(LCD_SCLSS)
          begin
          if SPI_WR='1' then
          counter16=100001;
          elsif LCD_SCLSS='1' and LCD_SCLSS'event then
          if counter16>0 then
          counter16=counter16-1;
          LCD_SCLSS16=LCD_SCLSSS;
          end if;
          end if;
          end process;

          --24bit SPI 時(shí)鐘采集生成模塊
          counter24_u:process(LCD_SCLSS)
          begin
          if SPI_WR='1' then
          counter24=110011;
          elsif LCD_SCLSS='1' and LCD_SCLSS'event then
          if counter24>0 then
          counter24=counter24-1;
          if (counter24=000000)or(counter24=000001)or
          (counter24=110011)or(counter24=000010)then
          LCD_SCLSS24='0';
          else
          LCD_SCLSS24=LCD_SCLSSS;
          end if;
          end if;
          end if;
          end process;

          --8bit 數(shù)據(jù)移位模塊
          DB8BIT_U:process(shift,SPI_WR,DBINOUTS)
          begin
          if SPI_WR='1' then
          DB8BIT_reg=DBINOUTS(7 downto 0);
          else
          if shift='1' and shift'event then
          LCD_SDIS_8BIT=DB8BIT_reg(0);
          DB8BIT_reg(6 downto 0)=DB8BIT_reg(7 downto 1);
          end if;
          end if;
          end process;

          --16bit 數(shù)據(jù)移位模塊
          DB16BIT_U:process(shift,SPI_WR,DBINOUTS)
          begin
          if SPI_WR='1' then
          DB16BIT_reg(15 downto 0)=DBINOUTS(15 downto 0);
          else
          if shift='1' and shift'event then
          LCD_SDIS_16BIT=DB16BIT_reg(0);
          DB16BIT_reg(14 downto 0)=DB16BIT_reg(15 downto 1);
          end if;
          end if;
          end process;

          --24bit 數(shù)據(jù)移位模塊
          DB24BIT_U:process(shift,SPI_WR,DBINOUTS)
          begin
          if SPI_WR='1' then
          DB24BIT_reg(23 downto 0)=DBINOUTS(23 downto 0);
          else
          if shift='1' and shift'event then
          LCD_SDIS_24BIT=DB24BIT_reg(0);
          DB24BIT_reg(22 downto 0)=DB24BIT_reg(23 downto 1);
          end if;
          end if;
          end process;
          end;

          五、仿真波形圖


          六、編譯后資源占用情況


          七、結(jié)束語

          本文旨在給學(xué)習(xí)可編程技術(shù)的人們提供一個(gè)參考,起到拋磚引玉的作用。望閱讀過此文的讀者提供更好的方法,與所有的學(xué)習(xí)者共享,共勉!

          本文引用地址:http://www.ex-cimer.com/article/201706/349058.htm



          關(guān)鍵詞: SPI VHDL FPGA

          評論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();