<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=8&amp;t=19649&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2017-11-19T09:48:31+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=8&amp;t=19649&amp;mode</id>
<entry>
<author><name><![CDATA[micky]]></name></author>
<updated>2017-11-19T07:36:17+01:00</updated>
<published>2017-11-19T07:36:17+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=19649&amp;p=199231#p199231</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=19649&amp;p=199231#p199231"/>
<title type="html"><![CDATA[Re: ATmega162 + ST485CN (RS485)]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=19649&amp;p=199231#p199231"><![CDATA[
Zdjęcia wstawiamy na forum a nie na serwerach zewnętrznych.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1546">micky</a> — 19 lis 2017, o 07:36</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[gotik]]></name></author>
<updated>2017-11-19T09:48:31+01:00</updated>
<published>2017-11-18T22:06:32+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=19649&amp;p=199220#p199220</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=19649&amp;p=199220#p199220"/>
<title type="html"><![CDATA[ATmega162 + ST485CN (RS485)]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=19649&amp;p=199220#p199220"><![CDATA[
Witam Wszystkim forumowiczów.<br />Każdy nowy prosi o poradę i ja również  <img src="https://forum.atnel.pl/images/smilies/icon_e_biggrin.gif" alt=":D" title="Bardzo szczęśliwy" /> <br />Wiem, wątków jest wiele na ten temat, ale nie znalazłem rozwiązania mojego problemu.<br />Chcę wysłać coś przez RS485 i niestety zamiast '0' wysyła 0x06, zamiast '1' wysyła 0x67 (i dalej odpowiednio 0x33, 0x66, 0x19, 0x65, 0x32, 0x64, 0x0c).<br />Póki co interesuje mnie proste wysłanie 1 bajtu, może więcej, bez tworzenia jakiegoś protokołu.<br />Proszę sprawdźcie i podpowiedzcie gdzie jest problem.<br />Przy wykorzystaniu RS232 wszystko jest prawidłowo.<br />Dwa terminale w Windzie i dwa konwertery USB-RS232 (ATC-810) oraz USB-RS485 (ATC-820).<br />Poniżej chyba wszystkie potrzebne dane. Wiem schemat nieciekawy, ale przejrzysty <img src="https://forum.atnel.pl/images/smilies/icon_e_wink.gif" alt=";)" title="Puszcza oko" /><br /><br />Pozdrawiam<br />Grzesiek<br /><br />poprawione <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" /><br /><br />Link do ustawienia fuzebitów:<br /><a href="https://obrazkiforum.atnel.pl/18248/8608f00fe55abf5ad492b0c7bf29bb7e.gif"  class="postlink"><img src="https://obrazkiforum.atnel.pl/thumb/18248/8608f00fe55abf5ad492b0c7bf29bb7e.gif" alt="Obrazek" /></a><br /><br />Link do schematu:<br /><a href="https://obrazkiforum.atnel.pl/18248/e295137792d61c16bcbbebbd70b67bf8.gif"  class="postlink"><img src="https://obrazkiforum.atnel.pl/thumb/18248/e295137792d61c16bcbbebbd70b67bf8.gif" alt="Obrazek" /></a><br /><br />Link do zdjęcia płytki:<br /><a href="https://obrazkiforum.atnel.pl/18248/dda3a963c98eab964dd2da6465d6058e.gif"  class="postlink"><img src="https://obrazkiforum.atnel.pl/thumb/18248/dda3a963c98eab964dd2da6465d6058e.gif" alt="Obrazek" /></a><br /><br />Kod programu:<br />/[syntax=c]*<br /> * Testy_RS485.cpp<br /> *<br /> * Created: 15.11.2017 18:59:01<br /> * Author :<br /> */ <br />#define F_CPU11059200<br />#include &lt;avr/io.h&gt;<br />#include &lt;util/delay.h&gt;<br />// port 0<br />#define BAUD4859600<br />// port 1<br />#define BAUD2329600<br /><br />#define BRC485((F_CPU/16/BAUD485) -1)<br />#define BRC232((F_CPU/16/BAUD232) -1)<br /><br />// dioda zielona sygnalizacja pracy;<br />#define LED1 (1 &lt;&lt; PA0);<br />#define LED1_ON     PORTA &amp;= ~LED1; // dioda pod VCC to gaszenie bitu zapala diodę<br />#define LED1_OFF    PORTA |=  LED1; // dioda pod VCC to zapalenie bitu gasi diodę<br />#define LED1_TOGGLE PORTA ^=  LED1;<br /><br />//--------------------------------------------------------------<br />void RS485_init()<br />{<br />/* Set baud rate */<br />UBRR0H = (unsigned char)(BRC485 &gt;&gt; 8);<br />UBRR0L = (unsigned char) BRC485;<br />/* Just in case ;) */<br />UCSR0A = 0;<br />/* receiver and transmitter */<br />UCSR0B = (1 &lt;&lt; TXEN0)|(1&lt;&lt;RXEN0);<br />/* Set frame format: 8data, 1stop bit */<br />UCSR0C = (1 &lt;&lt; URSEL0)|(3 &lt;&lt; UCSZ00);//(1&lt;&lt;USBS0)|<br />    // kierunek -&gt; nadajnik; //DDRD |= 0x04; // PD2:Dir<br />DDRD |= (1 &lt;&lt; PD2);<br />_delay_ms(500);<br />}<br />void RS232_init()<br />{<br />/* Set baud rate */<br />UBRR1H = (unsigned char)(BRC232 &gt;&gt; 8);<br />UBRR1L = (unsigned char) BRC232;<br />/* Just in case ;) */<br />UCSR1A = 0;<br />/* receiver and transmitter */<br />UCSR1B = (1 &lt;&lt; TXEN1)|(1&lt;&lt;RXEN1);<br />/* Set frame format: 8data, 1stop bit */<br />UCSR1C = (1 &lt;&lt; URSEL1)|(3 &lt;&lt; UCSZ10);//(1&lt;&lt;USBS1)|<br />_delay_ms(500);<br />}<br />//--------------------------------------------------------------<br />void RS485_nadawanie()<br />{<br />PORTD |=  0x04; //OFF<br />LED1_ON;<br />}<br />void RS485_odbior()<br />{<br />PORTD &amp;= ~0x04; //ON<br />LED1_OFF;<br />}<br />void RS485_sendByte(unsigned char temp)<br />{<br />/* Wait for empty transmit buffer */<br />while ( !( UCSR0A &amp; (1&lt;&lt;UDRE0)) ) ;<br />/* Put data into buffer, sends the data */<br />UDR0 = temp;<br />}<br />void RS232_sendByte(unsigned char temp)<br />{<br />/* Wait for empty transmit buffer */<br />while ( !( UCSR1A &amp; (1&lt;&lt;UDRE1)) ) ;<br />/* Put data into buffer, sends the data */<br />UDR1 = temp;<br />}<br />unsigned char RS485_receiveByte( void )<br />{<br />/* Wait for data to be received */<br />while ( !(UCSR0A &amp; (1&lt;&lt;RXC0)) ) ;<br />/* Get and return received data from buffer */<br />return UDR0;<br />}<br />unsigned char RS232_receiveByte( void )<br />{<br />/* Wait for data to be received */<br />while ( !(UCSR1A &amp; (1&lt;&lt;RXC1)) ) ;<br />/* Get and return received data from buffer */<br />return UDR1;<br />}<br />//--------------------------------------------------------------<br />//--------------------------------------------------------------<br />int main(void)<br />{<br />// kierunek portów<br />DDRA |= (1 &lt;&lt; PA0); // żółta<br />//<br />RS485_init();<br />RS232_init();<br />//<br />_delay_ms(1000);<br />unsigned char dana;<br /><br />RS485_odbior();<br />LED1_ON;<br />while (1)<br />{<br />RS485_odbior();<br />dana = RS485_receiveByte();<br />LED1_TOGGLE;<br />RS232_sendByte(dana);<br />}<br />/*<br />while (1)<br />{<br />LED1_TOGGLE;<br />RS485_nadawanie();<br />for(unsigned char i=0; i&lt;=7 ;i++)<br />{<br />RS485_sendByte(i);<br />}<br />// Wait for empty transmit buffer<br />while ( !( UCSR1A &amp; (1&lt;&lt;UDRE1)) ) ;<br />_delay_ms(2000);<br />}<br />*/<br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=18248">gotik</a> — 18 lis 2017, o 22:06</p><hr />
]]></content>
</entry>
</feed>