• <li id="00i08"><input id="00i08"></input></li>
  • <sup id="00i08"><tbody id="00i08"></tbody></sup>
    <abbr id="00i08"></abbr>
  • 新聞中心

    EEPW首頁 > 嵌入式系統 > 設計應用 > 基于FPGA和單片機的串行通信接口設計

    基于FPGA和單片機的串行通信接口設計

    作者: 時間:2012-03-25 來源:網絡 收藏

    摘要:本文針對由構成的高速數據采集系統數據處理能力弱的問題,提出實現數據的解決方案。在過程中完全遵守RS232協議,具有較強的通用性和推廣價值。

    本文引用地址:http://www.czjhyjcfj.com/article/149348.htm

    1 前言
    現場可編程邏輯器件()在高速采集系統中的應用越來越廣,由于FPGA對采集到的數據的處理能力比較差,故需要將其采集到的數據送到其他CPU系統來實現數據的處理功能,這就使FPGA系統與其他CPU系統之間的數據提到日程上,得到人們的急切關注。本文介紹利用VHDL語言實現 FPGA與的串口異步通信電路。
    整個采用模塊化的思想,可分為四個模塊:FPGA數據發送模塊,FPGA波特率發生控制模塊,FPGA總體模塊以及數據接收模塊。本文著重對FPGA數據發送模塊實現進行說明。

    2 FPGA數據發送模塊的
    根據RS232 異步通信來的幀格式,在FPGA發送模塊中采用的每一幀格式為:1位開始位+8位數據位+1位奇校驗位+1位停止位,波特率為2400。本系統設計的是將一個16位的數據封裝成高位幀和低位幀兩個幀進行發送,先發送低位幀,再發送高位幀,在傳輸數據時,加上文件頭和數據長度,文件頭用555555來表示,只有單片機收到555555時,才將下面傳輸的數據長度和數據位進行接收,并進行奇校驗位的檢驗,正確就對收到的數據進行存儲處理功能,數據長度可以根據需要任意改變。由設置的波特率可以算出分頻系數,具體算法為分頻系數X=CLK/(BOUND*2)。可由此式算出所需的任意波特率。下面是實現上述功能的VHDL源程序。
    Library ieee;
    use ieee.std_logic_1164.all;
    use ieee.std_logic_arith.all;
    use ieee.std_logic_unsigned.all;
    entity atel2_bin is
    port( txclk: in std_logic; --2400Hz的波特率時鐘
    reset: in std_logic; --復位信號
    din: in std_logic_vector(15 downto 0); --發送的數據
    start: in std_logic; --允許傳輸信號
    sout: out std_logic --輸出端口
    );
    end atel2_bin;
    architecture behav of atel2_bin is
    signal thr,len: std_logic_vector(15 downto 0);
    signal txcnt_r: std_logic_vector(2 downto 0);
    signal sout1: std_logic;
    signal cou: integer:=0;
    signal oddb:std_logic;
    type s is(start1,start2,shift1,shift2,odd1,odd2,stop1,stop2);
    signal state:s:=start1;
    begin
    process(txclk)
    begin
    if rising_edge(txclk) then
    if cou3 then thr=0000000001010101; --發送的文件頭
    elsif cou=3 then
    thr=0000000000000010; --發送的文件長度
    elsif (cou>3 and state=stop2) then thr=din;--發送的數據
    end if;
    end if;
    end process;
    process(reset,txclk)
    variable tsr,tsr1,oddb1,oddb2: std_logic_vector(7 downto 0);
    begin
    if reset='1' then
    txcnt_r=(others=>'0');
    sout1='1';
    state=start1;
    cou=0;
    elsif txclk'event and txclk='1' then
    case state is
    when start1=>
    if start='1' then
    if cou=3 then
    len=thr;
    end if;
    tsr:=thr(7 downto 0);
    oddb1:=thr(7 downto 0);
    sout1='0'; --起始位
    txcnt_r=(others=>'0');
    state=shift1;
    else
    state=start1;
    end if;
    when shift1=>
    oddb=oddb1(7) xor oddb1(6) xor oddb1(5) xor oddb1(4) xor oddb1(3) xor oddb1(2) xor oddb1(1) xor oddb1(0);
    sout1=tsr(0); --數據位
    tsr(6 downto 0):=tsr(7 downto 1);
    tsr(7):='0';
    txcnt_r=txcnt_r+1;
    if (txcnt_r=7) then
    state=odd1;cou=cou+1;
    end if;
    when odd1=> --奇校驗位
    if oddb='1' then
    sout1='0';state=stop1;
    else
    sout1='1';state=stop1;
    end if;
    when stop1=>
    sout1='1'; --停止位
    if cou4 then
    state=start1;
    else
    state=start2;
    end if;
    when start2=>
    tsr1:=thr(15 downto 8);
    oddb2:=thr(15 downto 8);
    sout1='0'; --起始位
    txcnt_r=(others=>'0');
    state=shift2;
    when shift2=>
    oddb=oddb2(7) xor oddb2(6) xor oddb2(5) xor oddb2(4) xor oddb2(3) xor oddb2(2) xor oddb2(1) xor oddb2(0);
    sout1=tsr1(0);--數據位
    tsr1(6 downto 0):=tsr1(7 downto 1);
    tsr1(7):='0';
    txcnt_r=txcnt_r+1;
    if (txcnt_r=7) then
    state=odd2;
    end if;
    when odd2=> --奇校驗位


    上一頁 1 2 下一頁

    評論


    相關推薦

    技術專區

    關閉
    主站蜘蛛池模板: 通州区| 香格里拉县| 盘山县| 崇阳县| 沾化县| 左云县| 资阳市| 鄯善县| 斗六市| 高平市| 扬州市| 临颍县| 荥经县| 麻城市| 临高县| 凌海市| 遂昌县| 略阳县| 邻水| 商水县| 札达县| 九寨沟县| 莫力| 吉木萨尔县| 江孜县| 博乐市| 大宁县| 张家川| 德昌县| 额敏县| 文水县| 上思县| 舟曲县| 西平县| 许昌县| 卢龙县| 永顺县| 镇康县| 开原市| 永清县| 克拉玛依市|