Forum: FPGA, VHDL & Co. RS232 zum PC mit dem DE1


von Peter B. (funkheld)


Lesenswert?

Hallo, guten Tag.
Vielleicht ist es einfacher eine RS232-Verbindung mit dem DE1 zum PC 
aufzubauen. Ich möchte es mal mit 9600Baud probieren.

Ich habe unten den Code gefunden.
Nun hat der DE1-RS232 nur RX/TX.


Was ist hier der "reset" ?

Welche Ports fallen dann hier bitte weg:
----------------------------------------------------
 port(
    clk       : in std_logic;
    reset     : in std_logic;

    send_data : in  std_logic_vector(7 downto 0);
    write_en  : in  std_logic;
    send_busy : out std_logic;
    send_empty: out std_logic;
    tx        : out std_logic);

-----------------------------------------------------
1
-- TITLE: Uart transmitter
2
-- AUTHOR: Rene Doss
3
-- Company Dossmatik GmbH
4
-- DATE CREATED: 27.6.2011
5
-- FILENAME: UART_TX_8N1.vhd
6
-- PROJECT: MAIS CPU core
7
--
8
-- COPYRIGHT: Creative Commons CC BY-NC 3.0 with exception 
9
-- commercial applicants have to pay a licence fee
10
-- 
11
-- DESCRIPTION:
12
-- Uart transmit timing
13
---------------------------------------------------------------------
14
15
library IEEE;
16
use IEEE.STD_LOGIC_1164.all;
17
18
use ieee.numeric_std.all;
19
20
--Uart transmiter without parity
21
22
entity Uart_8N1_TX is
23
  generic(
24
    clk_freq  : integer;
25
    baudrate  : integer); 
26
  port(
27
    clk       : in std_logic;
28
    reset     : in std_logic;
29
30
    send_data : in  std_logic_vector(7 downto 0);
31
    write_en  : in  std_logic;
32
    send_busy : out std_logic;
33
    send_empty: out std_logic;
34
    tx        : out std_logic);
35
end;
36
37
38
architecture Behavioral of Uart_8N1_TX is
39
--FSM
40
  type   state_type is (idle, start, data0, data1, data2, data3, data4, data5, data6, data7, stop);
41
  signal state, nextstate : state_type := idle;
42
43
  --FIFO
44
  type   RAM is array (0 to 255) of std_logic_vector (7 downto 0);
45
  signal fifo      : RAM;
46
  signal nextwrite : unsigned(7 downto 0);
47
  signal nextread  : unsigned(7 downto 0);
48
49
50
  --output
51
  signal   data_tx      : std_logic_vector (7 downto 0);
52
  signal   tick_counter : unsigned (10 downto 0);
53
  constant tick         : integer := (clk_freq/baudrate);
54
55
56
begin
57
58
  send_busy  <= '1' when (nextwrite+1 = nextread) else '0';
59
  send_empty <= '1' when nextwrite=nextread else '0';
60
61
  process(clk)
62
  begin
63
    if rising_edge(clk) then
64
      if reset = '1' then
65
        nextread <= (others => '0');
66
      elsif state = stop and nextstate = idle then
67
        nextread <= nextread+1;
68
      end if;
69
    end if;
70
  end process;
71
72
  process(clk)
73
  begin
74
    if rising_edge(clk) then
75
      state <= nextstate;
76
    end if;
77
  end process;
78
79
  process(clk)
80
  begin
81
    if rising_edge(clk) then
82
      if reset = '1' then
83
        nextwrite <= (others => '0');
84
      elsif write_en = '1' then
85
        fifo(to_integer(nextwrite)) <= send_data;
86
        nextwrite                   <= nextwrite+1;
87
        
88
      end if;
89
    end if;
90
  end process;
91
92
93
  process(clk)
94
  begin
95
    if rising_edge(clk) then
96
97
      if reset = '1' then
98
        tick_counter <= (others => '0');
99
        tx           <= '1';
100
        nextstate    <= idle;
101
102
103
        --   elsif    tick_counter= unsigned(baudreg)  then
104
      elsif tick_counter = tick then
105
        tick_counter <= (others => '0');
106
107
        case state is
108
          when idle =>
109
            if nextwrite /= nextread then
110
              nextstate    <= start;
111
              data_tx      <= fifo(to_integer(nextread));
112
              tick_counter <= (others => '0');
113
              tx           <= '0';
114
            else
115
              tx <= '1';
116
            end if;
117
          when start =>
118
            nextstate <= data0;
119
            tx        <= data_tx(0);
120
            
121
          when data0 =>
122
            nextstate <= data1;
123
            tx        <= data_tx(1);
124
          when data1 =>
125
            nextstate <= data2;
126
            tx        <= data_tx(2);
127
          when data2 =>
128
            nextstate <= data3;
129
            tx        <= data_tx(3);
130
          when data3 =>
131
            nextstate <= data4;
132
            tx        <= data_tx(4);
133
          when data4 =>
134
            nextstate <= data5;
135
            tx        <= data_tx(5);
136
          when data5 =>
137
            nextstate <= data6;
138
            tx        <= data_tx(6);
139
          when data6 =>
140
            nextstate <= data7;
141
            tx        <= data_tx(7);
142
          when data7 =>
143
            nextstate <= stop;
144
            tx        <= '1';
145
          when stop =>
146
            nextstate <= idle;
147
            tx        <= '1';
148
        end case;
149
      else
150
        tick_counter <= tick_counter + 1;
151
      end if;
152
    end if;
153
154
  end process;
155
end Behavioral;

Danke.
Gruss

: Bearbeitet durch User
von Bitflüsterer (Gast)


Lesenswert?

Peter Bierbach schrieb:
> Hallo, guten Tag.
> Vielleicht ist es einfacher eine RS232-Verbindung mit dem DE1 zum PC
> aufzubauen. Ich möchte es mal mit 9600Baud probieren.
Einfacher als was?

> Was ist hier der "reset" ?
Was verstehst Du an dem Wort "reset" nicht?

> Welche Ports fallen dann hier bitte weg:
Warum sollten Ports wegfallen?

von Peter B. (funkheld)


Lesenswert?

Wofür ist dieser Reset bitte:
reset     : in std_logic;

Unter Ports verstehe ich immer eine Verdrahtung die an einem PIN vom DE1 
gesetzt wird und nicht irgenwie als Variable oder Ähnlichem?

Danke.
GRuss

von Bitflüsterer (Gast)


Lesenswert?

Peter Bierbach schrieb:
> Wofür ist dieser Reset bitte:
> reset     : in std_logic;

Na schau Dir doch das Design an. Da wird genau beschrieben, wie es auf 
ein Reset-Signal reagiert.

> Unter Ports verstehe ich immer eine Verdrahtung die an einem PIN vom DE1
> gesetzt wird und nicht irgenwie als Variable oder Ähnlichem?
Aha. Nein. Ein Port kann auch mit anderen Instanzen von Entities 
innerhalb des FPGA verbunden sein.
Warum hast Du nach Wochen immer noch ein so eingeschränktes Verständnis 
von einem Port?

Lies mal "VHDL-Synthese" von Rechardt und Schwarz.

von Peter B. (funkheld)


Angehängte Dateien:

Lesenswert?

Ich habe hier das TX-Programm mit clk=50000000 und Baud=9600.

Verdrahtet habe ich TX und CLK beim DE1. Mehr steht mir an der seriellen 
Schnittstelle nicht zur Verfügung. Die anderen PINS die vom Programm 
aufgelistet sind hängen in der Luft. Was mache ich damit?

Wann geht das Senden bitte bei dem Programm eigentlich los. Was ist der 
Auslöser?
1
library IEEE;
2
use IEEE.STD_LOGIC_1164.all;
3
4
use ieee.numeric_std.all;
5
6
--Uart transmiter without parity
7
8
entity Uart_8N1_TX is
9
  generic(
10
    clk_freq  : integer :=50000000;
11
    baudrate  : integer :=9600
12
    );
13
  port(
14
    clk       : in std_logic;
15
    reset     : in std_logic;
16
17
    send_data : in  std_logic_vector(7 downto 0);
18
    write_en  : in  std_logic;
19
    send_busy : out std_logic;
20
    send_empty: out std_logic;
21
    tx        : out std_logic
22
    );
23
end;
24
25
architecture Behavioral of Uart_8N1_TX is
26
--FSM
27
  type   state_type is (idle, start, data0, data1, data2, data3, data4, data5, data6, data7, stop);
28
  signal state, nextstate : state_type := idle;
29
30
  --FIFO
31
  type   RAM is array (0 to 255) of std_logic_vector (7 downto 0);
32
  signal fifo      : RAM;
33
  signal nextwrite : unsigned(7 downto 0);
34
  signal nextread  : unsigned(7 downto 0);
35
  
36
  --output
37
  signal   data_tx      : std_logic_vector (7 downto 0);
38
  signal   tick_counter : unsigned (10 downto 0);
39
  constant tick         : integer := (clk_freq/baudrate);
40
41
begin
42
43
  send_busy  <= '1' when (nextwrite+1 = nextread) else '0';
44
  send_empty <= '1' when nextwrite=nextread else '0';
45
46
  process(clk)
47
  begin
48
    if rising_edge(clk) then
49
      if reset = '1' then
50
        nextread <= (others => '0');
51
      elsif state = stop and nextstate = idle then
52
        nextread <= nextread+1;
53
      end if;
54
    end if;
55
  end process;
56
57
  process(clk)
58
  begin
59
    if rising_edge(clk) then
60
      state <= nextstate;
61
    end if;
62
  end process;
63
64
  process(clk)
65
  begin
66
    if rising_edge(clk) then
67
      if reset = '1' then
68
        nextwrite <= (others => '0');
69
      elsif write_en = '1' then
70
        fifo(to_integer(nextwrite)) <= send_data;
71
        nextwrite                   <= nextwrite+1;
72
        
73
      end if;
74
    end if;
75
  end process;
76
77
  process(clk)
78
  begin
79
    if rising_edge(clk) then
80
81
      if reset = '1' then
82
        tick_counter <= (others => '0');
83
        tx           <= '1';
84
        nextstate    <= idle;
85
86
        --   elsif    tick_counter= unsigned(baudreg)  then
87
      elsif tick_counter = tick then
88
        tick_counter <= (others => '0');
89
90
        case state is
91
          when idle =>
92
            if nextwrite /= nextread then
93
              nextstate    <= start;
94
              data_tx      <= fifo(to_integer(nextread));
95
              tick_counter <= (others => '0');
96
              tx           <= '0';
97
            else
98
              tx <= '1';
99
            end if;
100
          when start =>
101
            nextstate <= data0;
102
            tx        <= data_tx(0);
103
            
104
          when data0 =>
105
            nextstate <= data1;
106
            tx        <= data_tx(1);
107
          when data1 =>
108
            nextstate <= data2;
109
            tx        <= data_tx(2);
110
          when data2 =>
111
            nextstate <= data3;
112
            tx        <= data_tx(3);
113
          when data3 =>
114
            nextstate <= data4;
115
            tx        <= data_tx(4);
116
          when data4 =>
117
            nextstate <= data5;
118
            tx        <= data_tx(5);
119
          when data5 =>
120
            nextstate <= data6;
121
            tx        <= data_tx(6);
122
          when data6 =>
123
            nextstate <= data7;
124
            tx        <= data_tx(7);
125
          when data7 =>
126
            nextstate <= stop;
127
            tx        <= '1';
128
          when stop =>
129
            nextstate <= idle;
130
            tx        <= '1';
131
        end case;
132
      else
133
        tick_counter <= tick_counter + 1;
134
      end if;
135
    end if;
136
137
  end process;
138
end Behavioral;


Gruss

: Bearbeitet durch User
von René D. (Firma: www.dossmatik.de) (dose)


Lesenswert?

>
>     send_data : in  std_logic_vector(7 downto 0);

hier werden die Daten angelegt, die gesendet werden sollen. Das ist ein 
Byte (7 downto 0);

>     write_en  : in  std_logic;
wenn hier ein '1' anliegt wird das Datenbyte bei der CLOCK Flanke 
übernommen.
Das ist eine typisches Paralleles Interface.
D
Das Byte geht erst in einem FIFO. Das ist ein Speichertyp, der es 
schafft mehrer Bytes entgegen zu mehmen. Die asynchrone Datenübertragung 
ist viel langsamer als das parallele Interface, sonst würde das Byte 
überschrieben bevor es gesendet wurde.

von Dieter (Gast)


Lesenswert?

Wäre es nicht sinnvoll ein eigenes Unterforum namens "Peter Bierbach" 
einzurichten?

von Easylife (Gast)


Lesenswert?

Dieter schrieb:
> Wäre es nicht sinnvoll ein eigenes Unterforum namens "Peter
> Bierbach"
> einzurichten?

Besser eine Fernsehsendung "Nachgefragt. Mit Peter Bierbach"

von Uwe (Gast)


Lesenswert?

> Die anderen PINS die vom Programm
> aufgelistet sind hängen in der Luft. Was mache ich damit?
Da machst du deine Steuerlogik ran  am besten ne Statemachine!

> Wann geht das Senden bitte bei dem Programm eigentlich los. Was ist der
> Auslöser?
Das ist kein Programm! Das ist ein Schaltplan und ein Schaltplan geht 
nicht los. Deine Statemachine steuert das Ding. Und deine Statemachine 
ist auch nur nen Schaltplan ...

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.