<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Lothar Miller - RS232</title>
    <link>http://www.lothar-miller.de/s9y/</link>
    <description>Elektronik und Musik</description>
    <dc:language>de</dc:language>
    <generator>Serendipity 1.3.1 - http://www.s9y.org/</generator>
    <pubDate>Thu, 07 Apr 2011 09:55:22 GMT</pubDate>

    <image>
        <url>http://www.lothar-miller.de/s9y/templates/bulletproof/img/s9y_banner_small.png</url>
        <title>RSS: Lothar Miller - RS232 - Elektronik und Musik</title>
        <link>http://www.lothar-miller.de/s9y/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>RS232</title>
    <link>http://www.lothar-miller.de/s9y/archives/48-RS232.html</link>
            <category>RS232</category>
    
    <comments>http://www.lothar-miller.de/s9y/archives/48-RS232.html#comments</comments>
    <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=48</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.lothar-miller.de/s9y/rss.php?version=2.0&amp;type=comments&amp;cid=48</wfw:commentRss>
    

    <author>nospam@example.com (Lothar Miller)</author>
    <content:encoded>
    
Das ist eine einfache &lt;b&gt;Implementierung einer RS232 Schnittstelle&lt;/b&gt;. &lt;br /&gt;Die Übertragung erfolgt im Format 8 Datenbits, keine Parity, 1 Stop-Bit. Die Baudrate kann generisch angegeben werden, die nötige Zählerbreite und der Zählerwert wird dann aus aus der Taktfrequenz berechnet.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Senden:&lt;/b&gt;&lt;br /&gt;Erst muß abgewartet werden bis das Signal TX_Busy inaktiv (=&#039;0&#039;) ist. Dann können am Port TX_Data 8 Datenbits angelegt und mindestens 1 Takt lang das Signal TX_Start aktiviert werden. Eine Flankenerkennung im Sendeteil erkennt die steigende Flanke von TX_Start und beginnt sofort mit der Übertragung. Während der Übertragung der Daten geht TX_Busy auf &#039;1&#039;.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Empfangen:&lt;/b&gt;&lt;br /&gt;Der (asynchrone) Eingangspin RXD wird über ein 4-Bit-Schieberegister (rxd_sr) einsynchronisiert. Die letzten beiden Bits werden zur Flankenerkennung verwendet rxd_sr(3 downto 2). Eine fallende Flanke wird als Startbit erkannt, danach wird eine halbe Bitzeit gewartet, und dann 9 Bits in das 8 Bit Empfangsdaten-Schieberegister rxsr eingetaktet. Damit wird das Startbit eingelesen, dann aber einfach durchgetaktet und fällt vorne wieder aus dem Schieberegister heraus. Nch dem Erkennen des Start-Bits und während des Empfang der Daten geht das Signal RX_Busy auf &#039;1&#039;. Die fallende Flanke von RX_Busy zeigt also den Empfang eines Zeichens an. &lt;br /&gt;Dieses Zeichen sollte dann gleich abgeholt und weggespeichert werden, denn mit dem Erkennen des nächsten Start-Bits werden die Daten einfach überschrieben.&lt;br /&gt;&lt;br /&gt;&lt;hr width=&quot;100%&quot; size=&quot;2&quot; /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;library&lt;/span&gt; &lt;span&gt;IEEE&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span&gt;IEEE&lt;/span&gt;.&lt;span&gt;STD_LOGIC_1164&lt;/span&gt;.&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;ALL&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span&gt;IEEE&lt;/span&gt;.&lt;span&gt;NUMERIC_STD&lt;/span&gt;.&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;ALL&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;entity&lt;/span&gt; &lt;span&gt;RS232&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;is&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;Generic&lt;/span&gt; ( &lt;span&gt;Quarz_Taktfrequenz&lt;/span&gt; : &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;integer&lt;/span&gt;   := &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;50000000&lt;/span&gt;;  &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- Hertz &lt;/span&gt;&lt;br /&gt;              &lt;span&gt;Baudrate&lt;/span&gt;           : &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;integer&lt;/span&gt;   :=  &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;9600&lt;/span&gt;      &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- Bits/Sec&lt;/span&gt;&lt;br /&gt;             ); &lt;br /&gt;    &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;Port&lt;/span&gt; ( &lt;span&gt;RXD&lt;/span&gt;      : &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;in&lt;/span&gt;   &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;STD_LOGIC&lt;/span&gt;;&lt;br /&gt;           &lt;span&gt;RX_Data&lt;/span&gt;  : &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;out&lt;/span&gt;  &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;STD_LOGIC_VECTOR&lt;/span&gt; (&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;7&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;);&lt;br /&gt;           &lt;span&gt;RX_Busy&lt;/span&gt;  : &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;out&lt;/span&gt;  &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;STD_LOGIC&lt;/span&gt;;&lt;br /&gt;           &lt;span&gt;TXD&lt;/span&gt;      : &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;out&lt;/span&gt;  &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;STD_LOGIC&lt;/span&gt;;&lt;br /&gt;           &lt;span&gt;TX_Data&lt;/span&gt;  : &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;in&lt;/span&gt;   &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;STD_LOGIC_VECTOR&lt;/span&gt; (&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;7&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;);&lt;br /&gt;           &lt;span&gt;TX_Start&lt;/span&gt; : &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;in&lt;/span&gt;   &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;STD_LOGIC&lt;/span&gt;;&lt;br /&gt;           &lt;span&gt;TX_Busy&lt;/span&gt;  : &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;out&lt;/span&gt;  &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;STD_LOGIC&lt;/span&gt;;&lt;br /&gt;           &lt;span&gt;CLK&lt;/span&gt;      : &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;in&lt;/span&gt;   &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;STD_LOGIC&lt;/span&gt;&lt;br /&gt;           );&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span&gt;RS232&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;architecture&lt;/span&gt; &lt;span&gt;Behavioral&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;of&lt;/span&gt; &lt;span&gt;RS232&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;is&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;signal&lt;/span&gt; &lt;span&gt;txstart&lt;/span&gt; : &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; := &lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;0&#039;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;signal&lt;/span&gt; &lt;span&gt;txsr&lt;/span&gt;    : &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;std_logic_vector&lt;/span&gt;  (&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;9&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;) := &lt;span style=&quot;background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);&quot;&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;1111111111&lt;/span&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;;  &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- Startbit, 8 Datenbits, Stopbit&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;signal&lt;/span&gt; &lt;span&gt;txbitcnt&lt;/span&gt; : &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;integer&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;range&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;to&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;10&lt;/span&gt; := &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;10&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;signal&lt;/span&gt; &lt;span&gt;txcnt&lt;/span&gt;    : &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;integer&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;range&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;to&lt;/span&gt; (&lt;span&gt;Quarz_Taktfrequenz&lt;/span&gt;/&lt;span&gt;Baudrate&lt;/span&gt;)-&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;signal&lt;/span&gt; &lt;span&gt;rxd_sr&lt;/span&gt;  : &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;std_logic_vector&lt;/span&gt; (&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;3&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;) := &lt;span style=&quot;background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);&quot;&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;1111&lt;/span&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;;         &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- Flankenerkennung und Eintakten&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;signal&lt;/span&gt; &lt;span&gt;rxsr&lt;/span&gt;    : &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;std_logic_vector&lt;/span&gt; (&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;7&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;) := &lt;span style=&quot;background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);&quot;&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;00000000&lt;/span&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;;     &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- 8 Datenbits&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;signal&lt;/span&gt; &lt;span&gt;rxbitcnt&lt;/span&gt; : &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;integer&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;range&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;to&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;9&lt;/span&gt; := &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;9&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;signal&lt;/span&gt; &lt;span&gt;rxcnt&lt;/span&gt;   : &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;integer&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;range&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;to&lt;/span&gt; (&lt;span&gt;Quarz_Taktfrequenz&lt;/span&gt;/&lt;span&gt;Baudrate&lt;/span&gt;)-&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;; &lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;begin&lt;/span&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- Senden&lt;/span&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;process&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;begin&lt;/span&gt;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;until&lt;/span&gt; &lt;span&gt;rising_edge&lt;/span&gt;(&lt;span&gt;CLK&lt;/span&gt;);&lt;br /&gt;      &lt;span&gt;txstart&lt;/span&gt; &amp;lt;= &lt;span&gt;TX_Start&lt;/span&gt;;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; (&lt;span&gt;TX_Start&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;1&#039;&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;and&lt;/span&gt; &lt;span&gt;txstart&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;0&#039;&lt;/span&gt;) &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;then&lt;/span&gt; &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- steigende Flanke, los gehts&lt;/span&gt;&lt;br /&gt;         &lt;span&gt;txcnt&lt;/span&gt;    &amp;lt;= &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;;                      &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- Zähler initialisieren&lt;/span&gt;&lt;br /&gt;         &lt;span&gt;txbitcnt&lt;/span&gt; &amp;lt;= &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;;                      &lt;br /&gt;         &lt;span&gt;txsr&lt;/span&gt;     &amp;lt;= &lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;1&#039;&lt;/span&gt; &amp;amp; &lt;span&gt;TX_Data&lt;/span&gt; &amp;amp; &lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;0&#039;&lt;/span&gt;;    &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- Stopbit, 8 Datenbits, Startbit, rechts gehts los&lt;/span&gt;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;         &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;(&lt;span&gt;txcnt&lt;/span&gt;&amp;lt;(&lt;span&gt;&lt;/span&gt;&lt;span&gt;Quarz_Taktfrequenz&lt;/span&gt;/&lt;span&gt;Baudrate&lt;/span&gt;)-&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;) &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;then&lt;/span&gt;&lt;br /&gt;            &lt;span&gt;txcnt&lt;/span&gt; &amp;lt;= &lt;span&gt;txcnt&lt;/span&gt;+&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;         &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;else&lt;/span&gt;  &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- nächstes Bit ausgeben  &lt;/span&gt;&lt;br /&gt;            &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; (&lt;span&gt;txbitcnt&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;10&lt;/span&gt;) &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;then&lt;/span&gt;&lt;br /&gt;              &lt;span&gt;txcnt&lt;/span&gt;    &amp;lt;= &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;              &lt;span&gt;txbitcnt&lt;/span&gt; &amp;lt;= &lt;span&gt;txbitcnt&lt;/span&gt;+&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;              &lt;span&gt;txsr&lt;/span&gt;     &amp;lt;= &lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;1&#039;&lt;/span&gt;&lt;span&gt; &amp;amp; txsr&lt;/span&gt;(&lt;span&gt;txsr&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;l&lt;/span&gt;&lt;span&gt;eft&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;)&lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&lt;/span&gt;;&lt;br /&gt;            &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;;&lt;br /&gt;         &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;process&lt;/span&gt;;&lt;br /&gt;   &lt;span&gt;TXD&lt;/span&gt;     &amp;lt;= &lt;span&gt;txsr&lt;/span&gt;(&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;&lt;span&gt;&lt;/span&gt;);  &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- LSB first&lt;/span&gt;&lt;br /&gt;   &lt;span&gt;TX_Busy&lt;/span&gt; &amp;lt;= &lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;1&#039;&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;when&lt;/span&gt; (&lt;span&gt;TX_Start&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;1&#039;&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;or&lt;/span&gt; &lt;span&gt;txbitcnt&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;10&lt;/span&gt;) &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;0&#039;&lt;/span&gt;;&lt;br /&gt;   &lt;br /&gt;   &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- Empfangen&lt;/span&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;process&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;begin&lt;/span&gt;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;until&lt;/span&gt; &lt;span&gt;rising_edge&lt;/span&gt;(&lt;span&gt;CLK&lt;/span&gt;);&lt;br /&gt;      &lt;span&gt;rxd_sr&lt;/span&gt; &amp;lt;= &lt;span&gt;rxd_sr&lt;/span&gt;(&lt;span&gt;rxd_sr&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;l&lt;/span&gt;&lt;span&gt;eft&lt;/span&gt;-&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;) &amp;amp; &lt;span&gt;RXD&lt;/span&gt;;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; (&lt;span&gt;rxbitcnt&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;9&lt;/span&gt;) &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;then&lt;/span&gt;    &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- Empfang läuft&lt;/span&gt;&lt;br /&gt;         &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;(&lt;span&gt;rxcnt&lt;/span&gt;&amp;lt;(&lt;span&gt;&lt;/span&gt;&lt;span&gt;Quarz_Taktfrequenz&lt;/span&gt;/&lt;span&gt;Baudrate&lt;/span&gt;)-&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;) &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;then&lt;/span&gt; &lt;br /&gt;            &lt;span&gt;rxcnt&lt;/span&gt;    &amp;lt;= &lt;span&gt;rxcnt&lt;/span&gt;+&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;         &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;            &lt;span&gt;rxcnt&lt;/span&gt;    &amp;lt;= &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;; &lt;br /&gt;            &lt;span&gt;rxbitcnt&lt;/span&gt; &amp;lt;= &lt;span&gt;rxbitcnt&lt;/span&gt;+&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;            &lt;span&gt;rxsr&lt;/span&gt;     &amp;lt;= &lt;span&gt;rxd_sr&lt;/span&gt;(&lt;span&gt;rxd_sr&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;l&lt;/span&gt;&lt;span&gt;eft&lt;/span&gt;-&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;) &amp;amp; &lt;span&gt;rxsr&lt;/span&gt;(&lt;span&gt;rxsr&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;l&lt;/span&gt;&lt;span&gt;eft&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;)&lt;span&gt;&lt;/span&gt;; &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- rechts schieben, weil LSB first&lt;/span&gt;         &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;;&lt;br /&gt;         &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- warten auf Startbit&lt;/span&gt;&lt;br /&gt;         &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; (&lt;span&gt;rxd_sr&lt;/span&gt;(&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;3&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;2&lt;/span&gt;) = &lt;span style=&quot;background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);&quot;&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;10&lt;/span&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;) &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;then&lt;/span&gt;                 &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- fallende Flanke Startbit&lt;/span&gt;&lt;br /&gt;            &lt;span&gt;rxcnt&lt;/span&gt;    &amp;lt;= (&lt;span&gt;&lt;/span&gt;(&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;Quarz_Taktfrequenz&lt;/span&gt;/&lt;span&gt;Baudrate&lt;/span&gt;)-&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;&lt;span&gt;&lt;/span&gt;)/&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;2&lt;/span&gt;; &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- erst mal nur halbe Bitzeit abwarten&lt;/span&gt;&lt;br /&gt;            &lt;span&gt;rxbitcnt&lt;/span&gt; &amp;lt;= &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;         &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;process&lt;/span&gt;;&lt;br /&gt;   &lt;span&gt;RX_Data&lt;/span&gt; &amp;lt;= &lt;span&gt;rxsr&lt;/span&gt;;&lt;br /&gt;   &lt;span&gt;RX_Busy&lt;/span&gt; &amp;lt;= &lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;1&#039;&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;when&lt;/span&gt; (&lt;span&gt;rxbitcnt&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;9&lt;/span&gt;) &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;0&#039;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span&gt;Behavioral&lt;/span&gt;;&lt;/pre&gt;&lt;hr width=&quot;100%&quot; size=&quot;2&quot; /&gt;&lt;p&gt;In diesem Code ist der Übersichtlichkeit zuliebe keinerlei Fehlerverwaltung eingebaut. Man könnte also mitten im Senden eines Zeichens eine neue Übertragung starten. Genauso wird einfach ein nicht abgeholtes Zeichen überschrieben.&lt;br /&gt;&lt;br /&gt;In der &lt;b&gt;Testbench &lt;/b&gt;werden zwei Zeichen (0xAA und 0xCC) versendet. Parallel dazu werden 2 Zeichen empfangen (0xAA und 0xC3). Hier die Waveform: &lt;/p&gt;&lt;div style=&quot;width: 738px;&quot; class=&quot;serendipity_imageComment_center&quot;&gt;&lt;div class=&quot;serendipity_imageComment_img&quot;&gt;&lt;!-- s9ymdb:115 --&gt;&lt;img width=&quot;738&quot; height=&quot;142&quot; src=&quot;http://www.lothar-miller.de/s9y/uploads/Bilder/RS232_TB.gif&quot; class=&quot;serendipity_image_center&quot; /&gt;&lt;/div&gt;&lt;div class=&quot;serendipity_imageComment_txt&quot;&gt;Testbench: Gleichzeitig Senden und Empfangen&lt;/div&gt;&lt;/div&gt;&lt;p&gt;
&lt;/p&gt;

 
    </content:encoded>

    <pubDate>Wed, 08 Jul 2009 22:06:00 +0200</pubDate>
    <guid isPermaLink="false">http://www.lothar-miller.de/s9y/archives/48-guid.html</guid>
    
</item>

</channel>
</rss>
