在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 1885|回复: 2

[求助] 关于写uart接收的问题

[复制链接]
发表于 2012-8-6 23:26:55 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
本帖最后由 孫悟 于 2012-8-6 23:31 编辑

想要请问个uart接收的问题



  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_unsigned.all;

  4. entity uart is
  5. port(

  6. clk_in_325hz : in std_logic;--153600hz由50MHZ分頻

  7. rxd_in: in std_logic;

  8. rxd_out:out std_logic_vector(7 downto 0)
  9. );
  10. end uart;

  11. architecture a of uart is
  12. type state is(idle,check,rec);
  13. signal check_ck,rec_ck,rec_re,rec_cc,ok:std_logic;
  14. signal check_re: std_logic_vector(1 downto 0):="00";
  15. signal recv,recv_sig : std_logic_vector(8 downto 0):="000000000";
  16. signal rxd_ck,rxd_ck_sig : std_logic_vector(3 downto 0):="0000";
  17. signal sta : state;
  18. begin

  19. process(sta,rxd_in,check_re,rec_re)
  20. begin

  21. case sta is

  22. when idle=>--等待初始位元

  23. recv_sig<="000000000";

  24. if rxd_in='0' then

  25. sta<=check;

  26. else

  27. sta<=idle;

  28. end if;

  29. when check=>--確認初始位元是不是雜訊

  30. check_ck<='1';

  31. case check_re is

  32. when "01"=>

  33. check_ck<='0';

  34. sta<=rec;

  35. when "10"=>

  36. check_ck<='0';

  37. sta<=idle;

  38. when others=> null;

  39. end case;

  40. when rec=>--接收資料

  41. rec_ck<='1';

  42. if rec_re='1' then

  43. sta<=idle;

  44. rec_ck<='0';

  45. elsif ok='1' then

  46. rxd_out<=recv(7 downto 0);

  47. sta<=idle;

  48. rec_ck<='0';

  49. end if;

  50. end case;
  51. end process;

  52. process(clk_in_325hz,check_ck,rec_ck)
  53. variable rxd_ck_st : integer range 0 to 4:=0;
  54. variable rec_st : integer range 0 to 8:=0;
  55. variable rec_ck_st: integer range 0 to 9:=0;
  56. begin

  57. if check_ck='1' then--確認初始位元是不是雜訊

  58. if clk_in_325hz'event and clk_in_325hz='1' then--1153600的上延

  59. if rxd_ck_st/=4 then--讓他記數4次,採樣4次確認是不是起始位元

  60. rxd_ck_st:=rxd_ck_st+1;

  61. rxd_ck<=rxd_in & rxd_ck_sig(3 downto 1);

  62. else

  63. if rxd_ck="0000" then--4次之後判斷回傳結果

  64. check_re<="01";

  65. rxd_ck_st:=0;

  66. else

  67. check_re<="10";

  68. rxd_ck_st:=0;


  69. end if;

  70. end if;

  71. end if;

  72. end if;

  73. if rec_ck='1' then

  74. if clk_in_325hz'event and clk_in_325hz='1' then

  75. rec_st:=rec_st+1;

  76. if rec_st=8 then --讓他記數8次,第8次的時候剛好再中間,共取9次,8個資料1個停止

  77. recv<=rxd_in & recv_sig(8 downto 1);

  78. rec_st:=0;

  79. rec_ck_st:=rec_ck_st+1;

  80. elsif rec_ck_st=9 then--取完第9個判斷第9個是不是停止位元,之後回傳

  81. if recv(8)='1' then

  82. ok<='1';

  83. rec_ck_st:=0;

  84. else

  85. rec_re<='1';

  86. rec_ck_st:=0;

  87. end if;

  88. end if;

  89. end if;

  90. end if;
  91. end process;
  92. end a;


复制代码
这样写烧进实验板没有反应,这我的写法有错吗(?),9600bps的,先谢谢
发表于 2012-8-7 11:30:53 | 显示全部楼层
不能用signal tap一点点调试吗?

先查下输入输出有没有。

另外,代码最好是先仿真再上板子调,这是一个好习惯。仿真查问题比上板要容易多了。
发表于 2012-8-7 12:57:43 | 显示全部楼层
你为什么不仿真呢?而是直接上板子呢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-17 18:50 , Processed in 0.023537 second(s), 12 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表