<?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=4&amp;t=17418&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2017-01-24T17:00:37+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=17418&amp;mode</id>
<entry>
<author><name><![CDATA[mirekk36]]></name></author>
<updated>2017-01-24T17:00:37+01:00</updated>
<published>2017-01-24T17:00:37+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180665#p180665</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180665#p180665"/>
<title type="html"><![CDATA[Re: Przerwanie USART nie zostaje wywoływane nigdy.]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180665#p180665"><![CDATA[
<div class="quotetitle"><b>Quote:</b></div><div class="quotecontent"><br />Teraz kiedy wysyłam bit do uC to przestaje się wykonywać główna pętla (pierwszy post).<br /></div><br />Dlatego że teraz wymyślasz już totalnie przedziwne rzeczy - czyli wewnątrz przerwania próbujesz wysłać znak a procedura czeka na zakończenie przerwania które się jeszcze nie zakończyło - i wąż zjada własny ogon .... <br /><br />Do wysyłania użyj albo w sposób blokujący samego transmitbyte albo jeśli chcesz na przerwaniach .... hmmm to hmmm ta biblioteka w ogóle tego nie uwzględnia. Ty zaś próbujesz robić to na zasadzie - &quot;a może się tak uda, albo tak .... .... bez jak na razie widzę wiedzy jak w ogóle działa system przerwań procka&quot; ... i to powoduje że błądzisz<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=54">mirekk36</a> — 24 sty 2017, o 17:00</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Trebuh]]></name></author>
<updated>2017-01-24T15:32:33+01:00</updated>
<published>2017-01-24T15:32:33+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180660#p180660</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180660#p180660"/>
<title type="html"><![CDATA[Re: Przerwanie USART nie zostaje wywoływane nigdy.]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180660#p180660"><![CDATA[
[syntax=c]ISR(USART_TX_vect)<br />{<br />transmitByte(128);<br />}<br />// ----[/syntax]<br /><br />Teraz kiedy wysyłam bit do uC to przestaje się wykonywać główna pętla (pierwszy post).<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=16248">Trebuh</a> — 24 sty 2017, o 15:32</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Trebuh]]></name></author>
<updated>2017-01-24T13:39:02+01:00</updated>
<published>2017-01-24T13:39:02+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180655#p180655</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180655#p180655"/>
<title type="html"><![CDATA[Re: Przerwanie USART nie zostaje wywoływane nigdy.]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180655#p180655"><![CDATA[
Oczywiście ją kupię tylko teraz mam inne wydatki.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=16248">Trebuh</a> — 24 sty 2017, o 13:39</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[mirekk36]]></name></author>
<updated>2017-01-24T13:19:03+01:00</updated>
<published>2017-01-24T13:19:03+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180654#p180654</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180654#p180654"/>
<title type="html"><![CDATA[Re: Przerwanie USART nie zostaje wywoływane nigdy.]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180654#p180654"><![CDATA[
Ja ze swojej strony polecę tę książkę:<br /><br /><!-- m --><a class="postlink" href="http://atnel.pl/mikrokontrolery-avr-jezyk-c.html" >http://atnel.pl/mikrokontrolery-avr-jezyk-c.html</a><!-- m --><br /><br />będziesz wiedział dokładnie co robisz i o co chodzi z obsługą UART i to w oparciu o bufory cykliczne<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=54">mirekk36</a> — 24 sty 2017, o 13:19</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Trebuh]]></name></author>
<updated>2017-01-24T13:14:42+01:00</updated>
<published>2017-01-24T13:14:42+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180653#p180653</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180653#p180653"/>
<title type="html"><![CDATA[Re: Przerwanie USART nie zostaje wywoływane nigdy.]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180653#p180653"><![CDATA[
Ustawiłem ten bit (w initUSART):<br />[syntax=c]UCSR0B = (1 &lt;&lt; TXEN0) | (1 &lt;&lt; RXEN0) | (1 &lt;&lt; RXCIE0);[/syntax]<br />i kod odpowiedzialny za przerwanie:<br />[syntax=c]ISR(USART_RX_vect)<br />{<br />transmitByte(128);<br />}[/syntax]<br /><br />Teraz dostaję tylko przerwanie nawet kiedy nic nie wysyłam.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=16248">Trebuh</a> — 24 sty 2017, o 13:14</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[andrews]]></name></author>
<updated>2017-01-24T06:31:34+01:00</updated>
<published>2017-01-24T06:31:34+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180633#p180633</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180633#p180633"/>
<title type="html"><![CDATA[Re: Przerwanie USART nie zostaje wywoływane nigdy.]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180633#p180633"><![CDATA[
Nazwę przerwania masz źle. Powinno być <em>ISR(USART_RX_vect)</em>.<br /><br />Jeśli mikrokontroler ma wchodzić do procedury obsługi przerwania <em>ISR(USART_RX_vect)</em>, to powinien być ustawiony bit RXCIE0 w rejestrze UCSR0B, a nie zauważyłem w kodzie, żebyś go ustawiał.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=14165">andrews</a> — 24 sty 2017, o 06:31</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Trebuh]]></name></author>
<updated>2017-01-24T00:29:47+01:00</updated>
<published>2017-01-24T00:29:47+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180631#p180631</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180631#p180631"/>
<title type="html"><![CDATA[Przerwanie USART nie zostaje wywoływane nigdy.]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=17418&amp;p=180631#p180631"><![CDATA[
Cześć,<br />mam taki kod main.c<br />[syntax=c]#include &lt;avr/io.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br />#include &lt;util/delay.h&gt;<br />#include &quot;USART.h&quot;<br /><br />ISR(USART_RXC)<br />{<br />transmitByte(77);<br />}<br />// -------- Funkcje --------- //<br />static inline void initFreerunningADC(void) {<br />ADMUX |= (1 &lt;&lt; REFS0);                  /* napięcie referencyjne to AVCC */<br />ADCSRA |= (0 &lt;&lt; ADPS2) | (1 &lt;&lt; ADPS1) | (0 &lt;&lt; ADPS0); /* preskaler zegara konwertera /4 */<br /><br />ADMUX |= (1 &lt;&lt; ADLAR); /* wyrównaj wynik do lewej, zwracaj tylko 8 bitów */<br /><br />ADCSRA |= (1 &lt;&lt; ADEN);                             /* włącz konwerter AC */<br />ADCSRA |= (1 &lt;&lt; ADATE);                             /* włącz tryb ciągły */<br />ADCSRA |= (1 &lt;&lt; ADSC);                     /* uruchom pierwszą konwersję */<br />}<br />void Delay_ms(int n) { //nie mozna uzyc zmiennej do delay (jako argument) cos jak tab&#91;var&#93; w c++<br />  while (n--) {<br />   _delay_ms(1);<br /> }<br />}<br /><br />int main(void) {<br />initUSART();<br />initFreerunningADC();<br />sei();<br />uint8_t delay = 20;<br />while (1)<br />{<br />transmitByte(ADCH);<br />Delay_ms(delay);<br />}<br />  return (0);<br />}[/syntax]<br /><br />USART.c<br />[syntax=c]/*<br />  Quick and dirty functions that make serial communications work.<br /><br />  Note that receiveByte() blocks -- it sits and waits _forever_ for<br />   a byte to come in.  If you're doing anything that's more interesting,<br />   you'll want to implement this with interrupts.<br /><br />   initUSART requires BAUDRATE to be defined in order to calculate<br />     the bit-rate multiplier.  9600 is a reasonable default.<br /><br />  May not work with some of the older chips:<br />    Tiny2313, Mega8, Mega16, Mega32 have different pin macros<br />    If you're using these chips, see (e.g.) iom8.h for how it's done.<br />    These old chips don't specify UDR0 vs UDR1.<br />    Correspondingly, the macros will just be defined as UDR.<br />*/<br /><br />#include &lt;avr/io.h&gt;<br />#include &quot;USART.h&quot;<br />#include &lt;util/setbaud.h&gt;<br /><br />void initUSART(void) {                                /* requires BAUD */<br />  UBRR0H = UBRRH_VALUE;                        /* defined in setbaud.h */<br />  UBRR0L = UBRRL_VALUE;<br />#if USE_2X<br />  UCSR0A |= (1 &lt;&lt; U2X0);<br />#else<br />  UCSR0A &amp;= ~(1 &lt;&lt; U2X0);<br />#endif<br />                                  /* Enable USART transmitter/receiver */<br />  UCSR0B = (1 &lt;&lt; TXEN0) | (1 &lt;&lt; RXEN0);<br />  UCSR0C = (1 &lt;&lt; UCSZ01) | (1 &lt;&lt; UCSZ00);   /* 8 data bits, 1 stop bit */<br />}<br /><br /><br />void transmitByte(uint8_t data) {<br />                                     /* Wait for empty transmit buffer */<br />  loop_until_bit_is_set(UCSR0A, UDRE0);<br />  UDR0 = data;                                            /* send data */<br />}<br /><br />uint8_t receiveByte(void) {<br />  loop_until_bit_is_set(UCSR0A, RXC0);       /* Wait for incoming data */<br />  return UDR0;                                /* return register value */<br />}<br /><br /><br />                       /* Here are a bunch of useful printing commands */<br /><br />void printString(const char myString&#91;&#93;) {<br />  uint8_t i = 0;<br />  while (myString&#91;i&#93;) {<br />    transmitByte(myString&#91;i&#93;);<br />    i++;<br />  }<br />}<br /><br />void readString(char myString&#91;&#93;, uint8_t maxLength) {<br />  char response;<br />  uint8_t i;<br />  i = 0;<br />  while (i &lt; (maxLength - 1)) {                   /* prevent over-runs */<br />    response = receiveByte();<br />    transmitByte(response);                                    /* echo */<br />    if (response == '\r') {                     /* enter marks the end */<br />      break;<br />    }<br />    else {<br />      myString&#91;i&#93; = response;                       /* add in a letter */<br />      i++;<br />    }<br />  }<br />  myString&#91;i&#93; = 0;                          /* terminal NULL character */<br />}<br /><br />void printByte(uint8_t byte) {<br />              /* Converts a byte to a string of decimal text, sends it */<br />  transmitByte('0' + (byte / 100));                        /* Hundreds */<br />  transmitByte('0' + ((byte / 10) % 10));                      /* Tens */<br />  transmitByte('0' + (byte % 10));                             /* Ones */<br />}<br /><br />void printWord(uint16_t word) {<br />  transmitByte('0' + (word / 10000));                 /* Ten-thousands */<br />  transmitByte('0' + ((word / 1000) % 10));               /* Thousands */<br />  transmitByte('0' + ((word / 100) % 10));                 /* Hundreds */<br />  transmitByte('0' + ((word / 10) % 10));                      /* Tens */<br />  transmitByte('0' + (word % 10));                             /* Ones */<br />}<br /><br />void printBinaryByte(uint8_t byte) {<br />                       /* Prints out a byte as a series of 1's and 0's */<br />  uint8_t bit;<br />  for (bit = 7; bit &lt; 255; bit--) {<br />    if (bit_is_set(byte, bit))<br />      transmitByte('1');<br />    else<br />      transmitByte('0');<br />  }<br />}<br /><br />char nibbleToHexCharacter(uint8_t nibble) {<br />                                   /* Converts 4 bits into hexadecimal */<br />  if (nibble &lt; 10) {<br />    return ('0' + nibble);<br />  }<br />  else {<br />    return ('A' + nibble - 10);<br />  }<br />}<br /><br />void printHexByte(uint8_t byte) {<br />                        /* Prints a byte as its hexadecimal equivalent */<br />  uint8_t nibble;<br />  nibble = (byte &amp; 0b11110000) &gt;&gt; 4;<br />  transmitByte(nibbleToHexCharacter(nibble));<br />  nibble = byte &amp; 0b00001111;<br />  transmitByte(nibbleToHexCharacter(nibble));<br />}<br /><br />uint8_t getNumber(void) {<br />  // Gets a numerical 0-255 from the serial port.<br />  // Converts from string to number.<br />  char hundreds = '0';<br />  char tens = '0';<br />  char ones = '0';<br />  char thisChar = '0';<br />  do {                                                   /* shift over */<br />    hundreds = tens;<br />    tens = ones;<br />    ones = thisChar;<br />    thisChar = receiveByte();                   /* get a new character */<br />    transmitByte(thisChar);                                    /* echo */<br />  } while (thisChar != '\r');                     /* until type return */<br />  return (100 * (hundreds - '0') + 10 * (tens - '0') + ones - '0');<br />}[/syntax]<br />USART.h<br />[syntax=c]/* Functions to initialize, send, receive over USART<br /><br />   initUSART requires BAUD to be defined in order to calculate<br />     the bit-rate multiplier.<br /> */<br /><br />#ifndef BAUD                          /* if not defined in Makefile... */<br />#define BAUD  9600                     /* set a safe default baud rate */<br />#endif<br /><br />                                  /* These are defined for convenience */<br />#define   USART_HAS_DATA   bit_is_set(UCSR0A, RXC0)<br />#define   USART_READY      bit_is_set(UCSR0A, UDRE0)<br /><br />/* Takes the defined BAUD and F_CPU,<br />   calculates the bit-clock multiplier,<br />   and configures the hardware USART                   */<br />void initUSART(void);<br /><br />/* Blocking transmit and receive functions.<br />   When you call receiveByte() your program will hang until<br />   data comes through.  We'll improve on this later. */<br />void transmitByte(uint8_t data);<br />uint8_t receiveByte(void);<br /><br />void printString(const char myString&#91;&#93;);<br />             /* Utility function to transmit an entire string from RAM */<br />void readString(char myString&#91;&#93;, uint8_t maxLength);<br />/* Define a string variable, pass it to this function<br />   The string will contain whatever you typed over serial */<br /><br />void printByte(uint8_t byte);<br />                  /* Prints a byte out as its 3-digit ascii equivalent */<br />void printWord(uint16_t word);<br />        /* Prints a word (16-bits) out as its 5-digit ascii equivalent */<br /><br />void printBinaryByte(uint8_t byte);<br />                                     /* Prints a byte out in 1s and 0s */<br />char nibbleToHex(uint8_t nibble);<br />void printHexByte(uint8_t byte);<br />                                   /* Prints a byte out in hexadecimal */<br />uint8_t getNumber(void);<br />/* takes in up to three ascii digits,<br /> converts them to a byte when press enter */[/syntax]<br /><br />kod USART.c i USART.h pochodzi z książki &quot;Programowanie układów AVR dla praktyków&quot;. Uruchomiłem globalne przerwania sei() ale nie widzę żadnego rezultatu (nie odbieram tego co powinno się wysłać podczas przerwania). Programuję na układzie ATMEGA328P. Co może być przyczyną tego?<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=16248">Trebuh</a> — 24 sty 2017, o 00:29</p><hr />
]]></content>
</entry>
</feed>