當(dāng)前位置:首頁 > 工業(yè)控制 > 電子設(shè)計(jì)自動(dòng)化
[導(dǎo)讀]一、摘要: SPI 接口應(yīng)用十分廣泛,在很多情況下,人們會(huì)用軟件模擬的方法來產(chǎn)生SPI 時(shí)序或是采用帶SPI 功能模塊的MCU。但隨著可編程邏輯技術(shù)的發(fā)展,人們往往需要自己設(shè)計(jì)簡單的SPI 發(fā)送模塊。本文介紹一種基于FPGA

一、摘要:

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

二、關(guān)鍵字:

VHDL、FPGA、SPI、串行數(shù)據(jù)輸出選擇模塊、移位脈沖產(chǎn)生模塊、SPI 時(shí)鐘采集信號(hào)和無相移的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 為輸入模式選擇端口:

--"01"is 8bit 傳輸模式

--"10"is 16bit 傳輸模式

--"11"is 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 為啟動(dòng)SPI 傳輸?shù)男盘?hào)


整個(gè)功能模塊可工作在 8bit、16bit、24bit SPI 猝發(fā)傳輸狀態(tài)。對(duì)其進(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*1**CLKS

--24bit 模式延時(shí)2*24*4*CLKS

--6、DBINOUTS="xxxxxxxxxxxxxxxxxxxxxxxx" 輸入下一個(gè)要發(fā)射的數(shù)據(jù)

四、VHDL 描述解讀

--以下描述的是一個(gè)SPI 自動(dòng)發(fā)射模塊

--在很多情況下,人們會(huì)用軟件模擬的方法來產(chǎn)生SPI 時(shí)序

--這里采用硬件的方法,即使軟件操作更為簡單,有提高了傳輸?shù)乃俣?/P>

--------------------------------------------------------------

--此模塊軟件操作流程如下

--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*1**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);

--串口操作模式選擇

--"01"is 8bit trans mode

--"10"is 16bit trans mode

--"11"is 24bit trans mode

SPI_WR :in std_logic; --啟動(dòng)串口發(fā)送信號(hào)

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í)鐘采集信號(hào)

signal LCD_SCLSSS :std_logic;--無相移的SPI 基準(zhǔn)時(shí)鐘

signal LCD_SCLSS8 :std_logic;--8bit SPI 時(shí)鐘信號(hào)

signal LCD_SCLSS16 :std_logic;--16bit SPI 時(shí)鐘信號(hào)

signal LCD_SCLSS24 :std_logic;--24bit SPI 時(shí)鐘信號(hào)

signal LCD_SDIS_8BIT :std_logic;--8bit SPI 數(shù)據(jù)信號(hào)

signal LCD_SDIS_16BIT :std_logic;--16bit SPI 數(shù)據(jù)信號(hào)

signal LCD_SDIS_24BIT :std_logic;--24bit SPI 數(shù)據(jù)信號(hào)

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í)鐘采集信號(hào)和無相移的SPI 基準(zhǔn)時(shí)鐘產(chǎn)生模塊

u3:process(CLKS)

begin

if CLKS='1' and CLKS'event then

if counter4s<"11" then

counter4s<=counter4s+1;

else counter4s<="00";

end if;

end if;

LCD_SCLSS<=counter4s(0); --SPI 時(shí)鐘采集信號(hào)

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í)者共享,共勉?。ㄗ髡撸阂η嗳A)



來源:星夢(mèng)居0次

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或?qū)⒋呱龈蟮莫?dú)角獸公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關(guān)鍵字: 阿維塔 塞力斯 華為

倫敦2024年8月29日 /美通社/ -- 英國汽車技術(shù)公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認(rèn)證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時(shí)1.5...

關(guān)鍵字: 汽車 人工智能 智能驅(qū)動(dòng) BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務(wù)能7×24不間斷運(yùn)行,同時(shí)企業(yè)卻面臨越來越多業(yè)務(wù)中斷的風(fēng)險(xiǎn),如企業(yè)系統(tǒng)復(fù)雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務(wù)連續(xù)性,提升韌性,成...

關(guān)鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報(bào)道,騰訊和網(wǎng)易近期正在縮減他們對(duì)日本游戲市場的投資。

關(guān)鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)開幕式在貴陽舉行,華為董事、質(zhì)量流程IT總裁陶景文發(fā)表了演講。

關(guān)鍵字: 華為 12nm EDA 半導(dǎo)體

8月28日消息,在2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)上,華為常務(wù)董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語權(quán)最終是由生態(tài)的繁榮決定的。

關(guān)鍵字: 華為 12nm 手機(jī) 衛(wèi)星通信

要點(diǎn): 有效應(yīng)對(duì)環(huán)境變化,經(jīng)營業(yè)績穩(wěn)中有升 落實(shí)提質(zhì)增效舉措,毛利潤率延續(xù)升勢 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務(wù)引領(lǐng)增長 以科技創(chuàng)新為引領(lǐng),提升企業(yè)核心競爭力 堅(jiān)持高質(zhì)量發(fā)展策略,塑強(qiáng)核心競爭優(yōu)勢...

關(guān)鍵字: 通信 BSP 電信運(yùn)營商 數(shù)字經(jīng)濟(jì)

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺(tái)與中國電影電視技術(shù)學(xué)會(huì)聯(lián)合牽頭組建的NVI技術(shù)創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會(huì)上宣布正式成立。 活動(dòng)現(xiàn)場 NVI技術(shù)創(chuàng)新聯(lián)...

關(guān)鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會(huì)上,軟通動(dòng)力信息技術(shù)(集團(tuán))股份有限公司(以下簡稱"軟通動(dòng)力")與長三角投資(上海)有限...

關(guān)鍵字: BSP 信息技術(shù)
關(guān)閉
關(guān)閉