登录 免费注册 首页 | 行业黑名单 | 帮助
维库电子市场网
技术交流 | 电路欣赏 | 工控天地 | 数字广电 | 通信技术 | 电源技术 | 测控之家 | EMC技术 | ARM技术 | EDA技术 | PCB技术 | 嵌入式系统
驱动编程 | 集成电路 | 器件替换 | 模拟技术 | 新手园地 | 单 片 机 | DSP技术 | MCU技术 | IC 设计 | IC 产业 | CAN-bus/DeviceNe

请教各位大虾,在设计UART中遇到的问题。

作者:lilysll 栏目:EDA技术
请教各位大虾,在设计UART中遇到的问题。
小弟毕业设计中涉及利用CPLD设计异步串行通信控制器实现两信号采集板之间的数据互传,即两片单片机采集8位开关量,通过并行方式与CPLD相连,利用CPLD实现并串转换,串行发送出去,另一片CPLD接收后,经过串并转换,传给单片机控制相应的发光二极管。
在计算机上仿真并串、串并转换程序波形正确。在板子上试验,单向传输正确。双向互传时就出现错误,已经搞了很久不能解决,故求助各位。
下面把具体程序附上:

发送主程序:
entity txmit is
    PORT ( reset : in std_logic;
           clk : in std_logic;
           wr : in std_logic;
     rege1:in std_logic_vector(7 downto 0);
           txd : out std_logic;
           int1 : out std_logic);
end txmit;

architecture Behavioral of txmit is
signal count:std_logic_vector(3 downto 0);
signal send:std_logic;
signal par: std_logic_vector( 7 downto 0);

begin
  PROCESS(reset,wr,count)  --内部输入控制信号
  begin
   if reset='1'or count="1011"then
    send<='1';
   elsif wr'event and wr='0'then
    send<='0';
   end if;
  end PROCESS;

  PROCESS(clk,reset,send) --发送计数器
  begin
    if send='1'or reset='1'then
     count<="0000";
    elsif clk'event and clk='1'then
      count<=count+"0001";
    end if;
  end PROCESS;

  PROCESS(reset,clk,count,rege1) --发送移位寄存器发送过程
  begin
    if reset='1'then
     txd<='1';
     int1<='0';
    elsif clk'event and clk='1'then
     if count="0001" then
      par<=rege1;
      txd<='0';
      int1<='1';
     elsif count>="0010" and count<="1001" then
      par<=par(6 downto 0)&'0';
      txd<=par(7);
      int1<='1';
     elsif count="1010" then
      int1<='1';   
      txd<='1';
     else
      int1<='0';
      txd<='1';
     end if;
    end if;
  end PROCESS;
          

end Behavioral;

发送地址译码程序:
entity add_in is
    PORT (cs:in std_logic;
            a:in std_logic;
            wr:in std_logic;
            data:in std_Logic_vector(7 downto 0);
            rege1:out std_logic_vector(7 downto 0));
end add_in;

architecture Behavioral of add_in is

begin
PROCESS(cs,a,data,wr)
   begin
     if cs='0'and a='0'then
       if  wr'event and wr='1'then
          rege1<=data;                 
       end if;
     end if;
end PROCESS;
end Behavioral;

接收主程序:
entity rece_search8 is
    PORT (reset:in std_logic;
      clk8:in std_Logic;
     rxd:in std_logic;
     rd:in std_logic;
    int2:out std_logic;
    rege2:out std_logic_vector(7 downto 0));
end rece_search8;

architecture Behavioral of rece_search8 is
signal start:std_logic;
signal int:std_logic;
signal hold:std_logic;
signal data1:std_logic;
signal sink:std_logic;
signal par:std_logic_vector(8 downto 0);
signal mm:std_logic_vector(2 downto 0);

begin
  PROCESS(reset,rxd,sink,start)  --寻找起始位
  begin
    if reset='1'or sink='0'or start='0'then
   hold<='0';
  elsif rxd'event and rxd='0'then
   hold<='1';
  end if;
end PROCESS;

  PROCESS(reset,clk8,hold,sink) --验证起始位
  variable i:integer range 0 to 4:=0;
  variable star:std_logic_vector(3 downto 0);
   begin
  if reset='1'or hold='0'then
    if sink='0'then
        data1<='1';
      else
        data1<='0';
    end if;   
  elsif clk8'event and clk8='1'then
    if i=4 then
          i:=0;
       if star(3 downto 0)="0000"then
               data1<='1';
             else
           data1<='0';
             end if;
      else
          star(i):=rxd;
      i:=i+1;
    end if;
   end if;                 
   end PROCESS;


PROCESS(sink,start)
begin
  if start='1'then
   int2<='1';
  elsif sink='1'then
   int2<='0';
  else
   int2<='1';
    end if;
end PROCESS;
  
PROCESS(reset,clk8,data1) --写入移位寄存器
variable a:integer range 0 to 76:=0;
begin
  if reset='1'or data1='0'then
   par(8 downto 0)<="000000000";
   a:=0;
   int<='0';
  elsif clk8'event and clk8='1'then
       if a=76 then
       a:=0;
      int<='0';
               elsif a=75 then
        sink<='1';
      a:=a+1;
      int<='1';
     else
          a:=a+1;
      int<='1';
    
2楼: >>参与讨论
sunhuaiyi
异步通信可以参考一下现成的程序
你的程序太长了,没仔细看,不过如果是异步通信,首先应该考虑怎样同步接收过来的数据,其次,如果用一个时钟周期去采样,数据出现错误是很正常的,因为两块cpld板子上的时钟不是同步的。
根据奈奎斯特采样定理,在一个周期内至少采样两次才能够得到正确的数据。
一般的,在单片机里面做异步通信,都有一个波特率系数设置,有16和32的,也就是数据的位宽是采样时钟周期的16倍或32倍,才能够保证异步通信数据的可靠性!

参与讨论
昵称:
讨论内容:
 
 
相关帖子
altera stratix 的管脚配置问题
请问如何申请Altera的样片?MAX7000S系列 2500门的芯片多少钱?
altera的MAX系列芯片编程时用晶振吗?用多大的?在线等,谢谢!
求教:体去藕电容(bulk cap)如何连接
【求助】如何在Quartus里对节点进行波形仿真??
免费注册为维库电子开发网会员,参与电子工程师社区讨论,点此进入


Copyright © 1998-2006 www.dzsc.com 浙ICP证030469号