搜索
bottom↓
回复: 6

FPGA串口发送程序,上位机接收错误,请教

[复制链接]

出0入55汤圆

发表于 2011-5-26 16:27:57 | 显示全部楼层 |阅读模式
一下是FPGA串口发送程序,上位机接收的数据位发送的2倍,也就是说发送的数据向高位移了1位。我看了硬件应该没问题,请问这程序哪里出了错?

时钟:50MHZ

顶层文件 transfer.vhd

library ieee;
use ieee.std_logic_1164.all;

entity transfer is
    port(clk,reset,start : in std_logic;
         txd,txddone     : out std_logic);
end transfer;

architecture behave of transfer is
component baud
    port(clk,resetb : in std_logic;
         bclk       : out std_logic);
end component;
component txmit
    port(bclkt,resett,xmit_cmd_p : in std_logic;
         txd,txd_done            : out std_logic);
end component;
signal bclk:std_logic;
begin
  U1:baud  port map ( clk , reset , bclk );
  U2:txmit port map ( bclk, reset , start , txd, txddone );
end behave;



波特率发生器

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity baud is
    Port (clk,resetb:in std_logic;
      bclk:out std_logic);
end baud;
architecture Behavioral of baud is
begin
process(clk,resetb)
variable cnt:integer;   
begin
  if resetb='0' then cnt:=0; bclk<='0';                           --复位
  elsif rising_edge(clk) then
     if cnt>=325 then cnt:=0; bclk<='1';                        --设置分频系数
  else cnt:=cnt+1; bclk<='0';
  end if;
  end if;
end process;
end Behavioral;



有限状态机实现发送逻辑

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity txmit is
    generic(framlent:integer:=8);
    Port (bclkt,resett,xmit_cmd_p:in std_logic;                  --定义输入输出信号
      txdbuf:in std_logic_vector(7 downto 0):="10011011";
   txd:out std_logic;
   txd_done:out std_logic);
end txmit;

architecture Behavioral of txmit is
type states is (x_idle,x_start,x_wait,x_shift,x_stop);                --定义个子状态
signal state:states:=x_idle;
signal tcnt:integer:=0;
begin
process(bclkt,resett,xmit_cmd_p,txdbuf)                         --主控时序、组合进程
variable xcnt16:std_logic_vector(4 downto 0):="00000";            --定义中间变量
variable xbitcnt:integer:=0;
variable txds:std_logic;
begin  
  if resett='0' then state<=x_idle; txd_done<='0'; txds:='1';           --复位
  elsif rising_edge(bclkt) then
     case state is
    when x_idle=>                                --状态1,等待数据帧发送命令
            if xmit_cmd_p='0' then state<=x_start; txd_done<='0';
   else state<=x_idle;               
   end if;
       when x_start=>                                --状态2,发送信号至起始位
            if xcnt16>="01111" then state<=x_wait; xcnt16:="00000";
            else xcnt16:=xcnt16+1; txds:='0'; state<=x_start;
            end if;                          
       when x_wait=>                                  --状态3,等待状态
            if xcnt16>="01110" then
         if xbitcnt=framlent then state<=x_stop; xbitcnt:=0;
      else state<=x_shift;
      end if;
      xcnt16:="00000";
       else xcnt16:=xcnt16+1; state<=x_wait;
    end if;                    
       when x_shift=>txds:=txdbuf(xbitcnt); xbitcnt:=xbitcnt+1; state<=x_wait;                                            --状态4,将待发数据进行并串转换
when x_stop=>                         --状态5,停止位发送状态
if xcnt16>="01111" then
      if xmit_cmd_p='1' then state<=x_idle; xcnt16:="00000";
      else xcnt16:=xcnt16; state<=x_stop;
      end if; txd_done<='1';
   else xcnt16:=xcnt16+1; txds:='1'; state<=x_stop;
      end if;                     
    when others=>state<=x_idle;
     end case;  
  end if;
  txd<=txds;
end process;
end Behavioral;

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入55汤圆

 楼主| 发表于 2011-5-26 16:32:19 | 显示全部楼层
也就是说:发送0x01是,上位机显示的是0x02。最高位怎么弄都没反应。丢失了

出0入0汤圆

发表于 2011-5-26 16:41:06 | 显示全部楼层
http://china.xilinx.com/support/documentation/application_notes/xapp341.pdf
供参照

出0入0汤圆

发表于 2011-6-4 16:05:45 | 显示全部楼层
回复【1楼】jssd 龙
-----------------------------------------------------------------------

我现在的情况已是这个样子的,找了好久都没有把问题解决。我的QQ:284543604,到时加我,一起讨论。

出0入0汤圆

发表于 2011-6-18 15:25:49 | 显示全部楼层
最直观的解决方法是你把查看下 START位  ,如果设置时间长一些,肯定就可以解决 。

出0入0汤圆

发表于 2011-6-18 21:52:45 | 显示全部楼层
很多时候都是因为采样问题

出0入0汤圆

发表于 2011-6-18 22:43:45 | 显示全部楼层
http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=4405292&bbs_page_no=1&search_mode=3&search_text=888888888888&bbs_id=9999
看我的串口 VHDL的
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-24 13:27

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表