基于FPGA设计与实现UART - search readpudncom.doc

上传人:marr****208 文档编号:134623646 上传时间:2020-06-07 格式:DOC 页数:9 大小:88.50KB
返回 下载 相关 举报
基于FPGA设计与实现UART - search readpudncom.doc_第1页
第1页 / 共9页
基于FPGA设计与实现UART - search readpudncom.doc_第2页
第2页 / 共9页
基于FPGA设计与实现UART - search readpudncom.doc_第3页
第3页 / 共9页
基于FPGA设计与实现UART - search readpudncom.doc_第4页
第4页 / 共9页
基于FPGA设计与实现UART - search readpudncom.doc_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《基于FPGA设计与实现UART - search readpudncom.doc》由会员分享,可在线阅读,更多相关《基于FPGA设计与实现UART - search readpudncom.doc(9页珍藏版)》请在金锄头文库上搜索。

1、基于FPGA设计与实现UARTUART(即Universal Asynchronous Receiver Transmitter 通用异步收发器)是广泛使用的串行数据传输协议。UART允许在串行链路上进行全双工的通信。- 串行外设用到RS-232异步串行接口,本实验室平台用的是MAXIM公司生产的MAX23。MAX232可以将串口设备需要发送的TTL/CMOS逻辑电平转换为RS-232逻辑电平,同时也可以将要接收的RS-232逻辑电平转换为TTL/CMOS逻辑电平。本实验通过编写VHDL语言程序,实现数据在实验平台与PC之间通过串口进行收发,基于FPGA器件设计与实现UART。 一 UART基

2、本知识 UART是通过串行传送数据而实现通信的,它的帧格式如下:-包括线路空闲状态(高电平)、起始位(低电平0)、58位数据位、可选的校验位和停止位(可为1、1.5、2位)。这种格式是由起始位和停止位来实现字符的同步。 另外,UART在国际上有一标准的波特率系列,在本实验中采用的波特率为9600HZ。二 管脚锁定及功能说明1、时钟 clk锁定在4MHZ的频率,是本实验箱的28号管脚的第三个针脚;2、复位键reset锁在105号管脚,用来复位;3、数据输入端口din7.0为117124,实验8位数据输入;4、输入使能口trans_lock为57,按一次输入一位数据;5、接收数据dout7.0显示

3、为8596,显示接收的数据6、接收出错信号frame_erro锁在74,为1则表示接收有误;7、接收完毕frame_end信号为75,为1表示接收完毕为0则表示正在接收,不允许发送;8、发送完毕信号trans_end为76,为1表示发送完毕,为0则表示正在发送,不允许接收。9、串行数据输入口rxd锁在97,串行数据输出口txd锁在98,分别用来数据的输入与输出。 三 UART的设计与实现1、分频计:由于本实验采用的波特率为9600HZ,它每隔16个时钟周期采样一个数据,因此实际输入的频率为9600HZ16153600HZ,实验平台上没有合适的时钟频率,因此在本实验中采用了4MHZ的时钟输入,对

4、它进行了26分频(4000k/153.6k=26.42),接近了实验要求的时钟频率。它的源代码如下:- Generated by Quartus II Version 4.0 (Build Build 190 1/28/2004)- Created on Sun Nov 20 17:09:41 2005-文件名:baud.vhd-功能:将外部输入的4MHz的信号分成频率为153600Hz9600Hz16的信号-26倍分频计library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGI

5、C_UNSIGNED.ALL;entity baud is Port (clkb,resetb:in std_logic; clk_out:out std_logic);end baud;architecture Behavioral of baud isbeginprocess(clkb,resetb)variable div:integer range 0 to 26;begin if resetb=1 then -复位 div:=0; clk_out=0; elsif clkb event and clkb=1 then-设置分频系数 div:=div+1; if div=13 then

6、 -一半的时候置0 clk_out=0; elsif div=26 then -26的时候置1 clk_out=1; div:=0; end if; end if;end process;end Behavioral;2、 UART接收器-串行数据帧和接收时钟是异步的,发送来的数据由逻辑1变为逻辑0可以视为一个数据帧的开始。接收器先要捕捉起始位,确定rxd输入由1到0,逻辑0要8个CLK16时钟周期,才是正常的起始位,然后在每隔16个CLK16时钟周期采样接收数据,移位输入接收移位寄存器rbuf,最后输出数据dout。接收完毕时,数据接收标志信号frame_end置1,标志数据接收完毕,接收过

7、程中为0,防止发送冲突。如果接收的过程中发生错误,则接收出错信号frame_error为1,平时此信号为0。接收器实现的源代码如下:- Generated by Quartus II Version 4.0 (Build Build 190 1/28/2004)- Created on Sun Nov 20 17:09:41 2005-文件名:receive.vhd。-功能:UART接受器。library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;e

8、ntity receive is Port (clkr:in std_logic; -采样时钟 resetr:in std_logic; -复位信号 rxd:in std_logic; -数据串行输入信号 r_lock:in std_logic; -接收锁存信号 frame_end:out std_logic;-一位接收完毕信号 frame_error:out std_logic;-接收出错信号 dout:out std_logic_vector(7 downto 0);-显示接收数据end receive;architecture Behavioral of receive isbeginp

9、ro:process(clkr,resetr,rxd) -接收信号进程variable number:std_logic_vector(3 downto 0); -接收数据的位数计数 variable count:std_logic_vector(3 downto 0); -采样时钟计数variable parity:std_logic:=0; -计算出的奇偶校验位variable receive_parity:std_logic; -接收到的奇偶校验位variable rbuf:std_logic_vector(7 downto 0); -接收缓存begin if resetr=1 then

10、 -复位 number:=0000; count:=0000; frame_end=1; frame_error=0; elsif rising_edge(clkr) then -接收 if number=0000then -识别起始位 if rxd=0 then if count1000then count:=count+1; else dout=00000000; count:=0000; number:=number+1; frame_end=0001 and number=1000then -接收数据 if count1111then count:=count+1; else coun

11、t:=0000; number:=number+1; frame_end=0; rbuf(7 downto 1) := rbuf(6 downto 0) ; rbuf(0):=rxd; parity := parity xor rbuf(0) ; end if; elsif number = 1001 then-接收奇偶校验位 if count1111then count:=count+1; else count:=0000; number:=number+1; frame_end=0; receive_parity:=rxd; end if; elsif number = 1010 then

12、-接收完毕 if count1111then count:=count+1; else count:=0000; dout= rbuf ; -接收移位寄存器数据进入接收缓冲器 rbuf:=00000000; number:=0000; frame_end=1; end if; else count:=0000; number:=0000; rbuf:=00000000; frame_end=1; end if; if parity=receive_parity then -检验接收是否出错 frame_error=0; parity:=0; else frame_error=1; parity:=0; end if; end if;end process;end Beha

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号