Test de ma carte:
Ce code utilise deux processus : un pour la transmission UART et un pour la
génération des données à transmettre. La variable tx_data contient les données à
transmettre, sous forme d'un mot binaire 8 bits. Dans l'exemple, on envoie une valeur
fixe de 0x5A.
Le processus de transmission tx_state gère l'envoi des données selon le protocole
UART : un bit de start à '0', les 8 bits de données, puis un bit de stop à '1'. Les bits
sont émis un par un, en utilisant le compteur tx_counter. La sortie uart_tx est
utilisée pour l'émission des bits.
Notez que pour que ce code fonctionne correctement sur la carte cmod S7, vous
devez configurer correctement les broches FPGA pour qu'elles correspondent à
celles utilisées dans le code. Vous devez également connecter la sortie uart_tx à un
adaptateur USB-UART pour pouvoir
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity uart_test is
port (
clk : in STD_LOGIC; -- Horloge
rst : in STD_LOGIC; -- Reset asynchrone
uart_tx : out STD_LOGIC -- Sortie UART TX
);
end uart_test;
architecture Behavioral of uart_test is
MIT School of Engineering, Department of ECE
signal tx_data : std_logic_vector(7 downto 0) := (others => '0'); -- Données à transmettre
signal tx_state : std_logic := '0'; -- État de la transmission
signal tx_counter : integer := 0; -- Compteur de bits
begin
-- Processus de transmission UART
process (clk, rst)
begin
if rst = '1' then
tx_state <= '0';
tx_counter <= 0;
elsif rising_edge(clk) then
case tx_state is
when '0' =>
if tx_data = "00000000" then
tx_state <= '0';
else
tx_state <= '1'; -- Passer à l'état de transmission
tx_counter <= 0;
uart_tx <= '0'; -- Émission d'un bit de start
end if;
when '1' => -- État de transmission
if tx_counter < 8 then
uart_tx <= tx_data(tx_counter); -- Émission d'un bit de données
tx_counter <= tx_counter + 1;
else
uart_tx <= '1'; -- Émission d'un bit de stop
tx_state <= '0'; -- Retour à l'état d'attente
tx_counter <= 0;
tx_data <= (others => '0'); -- Réinitialisation des données à transmettre
end if;
MIT School of Engineering, Department of ECE
end case;
end if;
end process;
-- Processus de génération de données à transmettre
process (clk, rst)
begin
if rst = '1' then
tx_data <= (others => '0');
elsif rising_edge(clk) then
-- Exemple : envoyer une valeur fixe de 0x5A
tx_data <= "01011010";
end if;
end process;
end Behavioral;
[DRC MDRV-1] Multiple Driver Nets: Net tx_data[1] has multiple drivers: tx_data_reg[1]/Q, and
tx_data_reg[1]__0/Q.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use ieee.numeric_std_unsigned.all;
entity send_data is
Port (
clk : in std_logic;
button : in std_logic;
MIT School of Engineering, Department of ECE
uart_tx : out std_logic;
uart_rtsn : out std_logic
);
end send_data;
architecture Behavioral of send_data is
signal tx_data : std_logic_vector(7 downto 0);
signal tx_busy : std_logic;
signal tx_start : std_logic;
signal cnt : integer range 0 to 20000000 := 0;
begin
uart_tx <= '1' when not tx_busy and tx_start = '1' else '0';
uart_rtsn <= '1';
process(clk)
begin
if rising_edge(clk) then
-- Increment counter to debounce button
if button = '0' then
cnt <= cnt + 1;
else
cnt <= 0;
end if;
-- Check for button press and start sending data
if cnt = 10000 then
tx_data <= "10101010"; -- Replace with your 8-bit data
MIT School of Engineering, Department of ECE
tx_busy <= '1';
tx_start <= '1';
end if;
-- Send data over UART
if tx_start = '1' and not tx_busy then
if tx_data /= "" then
uart_rtsn <= '0';
tx_busy <= '1';
cnt <= 0;
else
tx_start <= '0';
end if;
end if;
-- Wait for UART to finish sending data
if tx_busy = '1' then
if cnt < 5000 then
cnt <= cnt + 1;
else
tx_busy <= '0';
tx_data <= "";
end if;
end if;
end if;
end process;
end Behavioral;
MIT School of Engineering, Department of ECE