【发布时间】:2019-05-08 18:19:40
【问题描述】:
我正在尝试用 VHDL 设计一个 rs232 接收器:我使用 python 脚本发送数字,它必须捕获并显示给一些 LED。我希望了解 RS232 的工作原理并着手进行该设计。该设计的行为与我希望的不同,我想知道是否有人可以帮助我找出我的错误。
当然我去看看串行接收器是如何工作的。但作为一个初学者,我经常对提出的解决方案感到不知所措(例如:VHDL RS-232 Receiver" 或更糟糕的是:https://www.nandland.com/vhdl/modules/module-uart-serial-port-rs232.html),我缺乏理解其中发生的事情的词汇和经验。
我在 quartus II 网页版上做了这个设计:
底部的实体只是锁定到通过 rs232 输入的任何数据,以确保 python 脚本确实在做某事。
使用这两个文件: rs232_test
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity rs232_receiver is
port (
clock : in std_logic;
r : in std_logic;
reset : in std_logic;
data : out std_logic_vector (7 downto 0)
);
end rs232_receiver;
architecture rs232_receiver_arch of rs232_receiver is
signal data_buffer : std_logic_vector (12 downto 0);
signal state : integer; -- 1000 => idle;
begin
process
begin
wait until rising_edge (clock);
if (reset = '0') then
if (state = 1000) then
if (r = '0') then
state <= 0; -- startbit as been detected => time to READ !
end if;
elsif (state < 13 and state > -1) then
data_buffer(state) <= r;
state <= state + 1;
else
state <= 1000; -- go back to idle
data <= data_buffer(7 downto 0);
data_buffer <= (others => '0');
end if;
else
data_buffer <= (others => '0');
data <= (others => '0');
state <= 1000;
end if;
end process;
end rs232_receiver_arch;
时钟调整(原始时钟为 24 MHz,我希望我制作这个分频器的方式,输出为 1200 Hz,我相信波特率为 1200)。
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity div1000 is
port (
clock : in std_logic;
clockOut : out std_logic
);
end div1000;
architecture div1000_arch of div1000 is
signal count : integer;
begin
clockOut <= '1' when count < 10000 else '0';
process begin
wait until rising_edge (clock);
if (count > 19999 or count < 0) then
count <= 1;
else
count <= count + 1;
end if;
end process;
end div1000_arch;
我用这个 python 脚本加载数字:
# -*- coding: utf-8 -*-
"""
Created on Thu May 2 14:52:12 2019
@author: nathan hj ragot
"""
import time
import serial
import serial.tools.list_ports
print ("hello world !")
# initialisation des variables
port = "" # port choisit
ports = [] # ports listes
# recherche et choix du port
print ("merci de rentrer le nom d'un port :")
print ("ps : automatiquement, le script a detecte ces ports :")
print ("**************")
ports = serial.tools.list_ports.comports()
for i in range (len(ports)):
print ("-> [" + str(i) + "] : " + str (ports[i]))
print ("**************")
port = input("? votre choix :")
print ("ok cool")
# open serial port
ser = serial.Serial(
port=port,
baudrate=1200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_TWO,
bytesize=serial.EIGHTBITS
)
print(ser.isOpen())
#start writing
ser.write(bytearray([255]))
for i in range(15):
input("press enter to print " + str(i))
ser.write (bytearray([i]))
#stop writing
ser.close()
print(ser.isOpen())
print ("bye")
我期待每次我在键盘上按 Enter 键时,python 脚本都会向我的 fpga 板发送一个字节,并且设计会锁定数字并将其显示给 LED。相反,LED 会闪烁到一些与发送的数字不对应的随机位置,然后立即关闭。
【问题讨论】:
标签: python serial-port vhdl intel-fpga