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

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2016-08-09T22:46:11+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=15957&amp;mode</id>
<entry>
<author><name><![CDATA[anshar]]></name></author>
<updated>2016-08-09T22:46:11+01:00</updated>
<published>2016-08-09T22:46:11+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165768#p165768</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165768#p165768"/>
<title type="html"><![CDATA[Re: Strumienie printf i scanf - wykorzystanie w UART.]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165768#p165768"><![CDATA[
Jeśli używasz Eclipsa <br />to poczytaj<br /><a href="http://mirekk36.blogspot.co.uk/2013/04/eclipse-nie-dziaa-mi-printf-dla-float.html"  class="postlink">tutaj.</a><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=7157">anshar</a> — 9 sie 2016, o 22:46</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[dawid75_75]]></name></author>
<updated>2016-08-09T20:37:04+01:00</updated>
<published>2016-08-09T20:37:04+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165762#p165762</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165762#p165762"/>
<title type="html"><![CDATA[Re: Strumienie printf i scanf - wykorzystanie w UART.]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165762#p165762"><![CDATA[
Tę linijkę akurat już wywaliłem i zapomniałem zaktualizować kodu wyżej. Włączyłem w PuTTy local echo i już to nie jest więcej potrzebne, przynajmniej z założenia. Ale scanf nie działa dalej.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=11277">dawid75_75</a> — 9 sie 2016, o 20:37</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Daro69]]></name></author>
<updated>2016-08-09T20:28:15+01:00</updated>
<published>2016-08-09T20:28:15+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165761#p165761</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165761#p165761"/>
<title type="html"><![CDATA[Re: Strumienie printf i scanf - wykorzystanie w UART.]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165761#p165761"><![CDATA[
to dla mnie nowy temat jeszcze odległy, ale w przerwaniu chyba &quot;CHYBA&quot; czy nie powinno być przy wysyłaniu strumienia scanf : uart_putchar(...,str); ? zamiast stream. ?<br />jeżeli powinno być tak jak jest . To sorka za zamieszanie .  <img src="https://forum.atnel.pl/images/smilies/icon_e_confused.gif" alt=":?" title="Boi się" /> <br />Może ktoś obeznany się skusi i ruszy z pomocą.<br /><br /><strong><span style="color: #808000">------------------------ [ Dodano po: 6 minutach ]</span></strong><br /><br />no nie bo to odbieranie, a nie wysyłanie.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=11549">Daro69</a> — 9 sie 2016, o 20:28</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[dawid75_75]]></name></author>
<updated>2016-08-09T20:15:37+01:00</updated>
<published>2016-08-09T20:15:37+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165760#p165760</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165760#p165760"/>
<title type="html"><![CDATA[Re: Strumienie printf i scanf - wykorzystanie w UART.]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165760#p165760"><![CDATA[
Cześć,<br />dziękuję za odpowiedź <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" /> Po czym poznałem? Po prostu program stał w miejscu. Nawet komunikatów z printfa nie dostałem kiedy mam scanf w kodzie. Dopiero jak skasowałem scanfa to wyświetliło mi napisy.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=11277">dawid75_75</a> — 9 sie 2016, o 20:15</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Daro69]]></name></author>
<updated>2016-08-09T20:06:51+01:00</updated>
<published>2016-08-09T20:06:51+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165759#p165759</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165759#p165759"/>
<title type="html"><![CDATA[Re: Strumienie printf i scanf - wykorzystanie w UART.]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165759#p165759"><![CDATA[
witam,<br />nie jestem pewien, ale nikt się nie odzywa więc może ruszę temat <img src="https://forum.atnel.pl/images/smilies/icon_e_confused.gif" alt=":?" title="Boi się" /> <br />zastanawiam się po czym poznajesz ze scanf(..., str) nie hula?<br />gdzie sprawdzasz wartości przechwycone do tablicy str[80] ?<br />ewentualnie w którym miejscu kodu tę tablicę wysyłasz.?<br /><br />hm.. przy okazji może coś się nauczę. <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" /><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=11549">Daro69</a> — 9 sie 2016, o 20:06</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[dawid75_75]]></name></author>
<updated>2016-08-07T13:29:39+01:00</updated>
<published>2016-08-07T13:29:39+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165616#p165616</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165616#p165616"/>
<title type="html"><![CDATA[Strumienie printf i scanf - wykorzystanie w UART.]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15957&amp;p=165616#p165616"><![CDATA[
Szanowni Forumowicze,<br />uruchomiłem sobie sprzętowego UARTa wykorzystując bibliotekę ze strony atmela. Wszystko działa, łączę się z terminalem na komputerze, wyświetla się to co powinno. Dodałem też funkcję do wysyłania całego łańcucha znaków wykorzystując wskaźnik, gdyż w atmelowskiej bibliotece znalazłem jedynie do wysyłania konkretnych pojedynczych znaków. Wyczytałem też, że można do komunikacji wykorzystać strumienie printf i scanf. I o ile printf działa poprawnie to ze scanf mam problem. Kod może wydawać się obszerny ze względu na szczegółowe komentarze producenta i wyłączone przeze mnie pewne fragmenty kodu. Oto i kod:<br />[syntax=c]#include &lt;stdio.h&gt;<br />#include &quot;usart_driver.h&quot;<br />#include &quot;usart_driver.c&quot;<br />#include &quot;avr_compiler.h&quot;<br /><br />/*! Number of bytes to send in test example. */<br />#define NUM_BYTES  3<br />/*! Define that selects the Usart used in example. */<br />#define USART USARTC0<br /><br />/*! USART data struct used in example. */<br />USART_data_t USART_data;<br />/*! Test data to send. */<br />uint8_t sendArray&#91;NUM_BYTES&#93; = {0x55, 0x0d,0x0a };<br />/*! Array to put received data in. */<br />uint8_t receiveArray&#91;NUM_BYTES&#93;;<br />/*! Success variable, used to test driver. */<br />bool success;<br />//void sendString(char *text);<br />void uart_puts(char *s);<br /><br />// funkcje dotyczące obsługi strumieni printf i scanf.<br />static int uart_putchar(char c, FILE *stream);<br />int uart_getchar(FILE *stream);<br />static FILE mystdout = FDEV_SETUP_STREAM (uart_putchar, uart_getchar, _FDEV_SETUP_RW);<br /><br /><br />/*! \brief Example application.<br /> *<br /> *  Example application. This example configures USARTC0 for with the parameters:<br /> *      - 8 bit character size<br /> *      - No parity<br /> *      - 1 stop bit<br /> *      - 9600 Baud<br /> *<br /> *  This function then sends three bytes and tests if the received data is<br /> *  equal to the sent data. The code can be tested by connecting PC3 to PC2. If<br /> *  the variable 'success' is true at the end of the function, the three bytes<br /> *  have been successfully sent and received.<br />*/<br />int main(void)<br />{<br /><br />CPU_CCP         =CCP_IOREG_gc;                 // odblokowanie modyfikacji ważnych rejestrów<br />CLK.CTRL=CLK_SCLKSEL_RC2M_gc;<br /><br />stdout = &amp;mystdout;<br />stdin  = &amp;mystdout;<br /><br />/* counter variable. */<br />uint8_t i;<br /><br />/* This PORT setting is only valid to USARTC0 if other USARTs is used a<br /> * different PORT and/or pins are used. */<br />  /* PC3 (TXD0) as output. */<br />PORTC.DIRSET   = PIN3_bm;<br />/* PC2 (RXD0) as input. */<br />PORTC.DIRCLR   = PIN2_bm;<br /><br />/* Use USARTC0 and initialize buffers. */<br />USART_InterruptDriver_Initialize(&amp;USART_data, &amp;USART, USART_DREINTLVL_LO_gc);<br /><br />/* USARTC0, 8 Data bits, No Parity, 1 Stop bit. */<br />USART_Format_Set(USART_data.usart, USART_CHSIZE_8BIT_gc,<br />                     USART_PMODE_DISABLED_gc, false);<br /><br />/* Enable RXC interrupt. */<br />USART_RxdInterruptLevel_Set(USART_data.usart, USART_RXCINTLVL_LO_gc);<br /><br />/* Set Baudrate to 9600 bps:<br /> * Use the default I/O clock frequency that is 2 MHz.<br /> * Do not use the baudrate scale factor<br /> *<br /> * Baudrate select = (1/(16*(((I/O clock frequency)/Baudrate)-1)<br /> *                 = 12<br /> */<br />USART_Baudrate_Set(&amp;USART, 12 , 0);<br /><br />/* Enable both RX and TX. */<br />USART_Rx_Enable(USART_data.usart);<br />USART_Tx_Enable(USART_data.usart);<br /><br />/* Enable PMIC interrupt level low. */<br />PMIC.CTRL |= PMIC_LOLVLEX_bm;<br /><br />/* Enable global interrupts. */<br />sei();<br /><br />while(1)<br />{<br />/* Send sendArray. */<br />i = 0;<br />while (i &lt; NUM_BYTES) {<br />bool byteToBuffer;<br />byteToBuffer = USART_TXBuffer_PutByte(&amp;USART_data, (char)sendArray&#91;i&#93;);<br />if(byteToBuffer){<br />i++;<br />}<br />}<br />success = true;<br />/*Fetch received data as it is received.<br />i = 0;<br />while (i &lt; NUM_BYTES) {<br />if (USART_RXBufferData_Available(&amp;USART_data)) {<br />receiveArray&#91;i&#93; = USART_RXBuffer_GetByte(&amp;USART_data);<br />i++;<br />}<br />}*/<br /><br />/* Test to see if sent data equals received data. */<br />/* Assume success first.<br />success = true;<br />for(i = 0; i &lt; NUM_BYTES; i++) {<br /> //Check that each element is received correctly. <br />if (receiveArray&#91;i&#93; != sendArray&#91;i&#93;) {<br />success = false;<br />}<br />}*/<br /><br />/* If success the program ends up inside the if statement.*/<br />if(success){<br />PORTC.DIRSET   = PIN1_bm;<br />PORTC.OUTSET   = PIN1_bm;<br />//char znak = 'c';<br />//USART_PutChar(&amp;USART, znak);<br />//while(true);<br />_delay_ms(1000);<br />PORTC.OUTCLR   = PIN1_bm;<br />//_delay_ms(2000);<br />}else{<br />  //while(true);<br />  _delay_ms(5000);<br />}<br />uart_puts(&quot;Hello World!\n\r&quot;);<br />printf(&quot;Wpisz cos! printf\n&quot;);<br />char str &#91;80&#93;;<br />scanf(&quot;%79s&quot;,str);<br />}<br /><br />}<br /><br /><br />/*! \brief Receive complete interrupt service routine.<br /> *<br /> *  Receive complete interrupt service routine.<br /> *  Calls the common receive complete handler with pointer to the correct USART<br /> *  as argument.<br /> */<br />ISR(USARTC0_RXC_vect)<br />{<br />USART_RXComplete(&amp;USART_data);<br />}<br /><br /><br />/*! \brief Data register empty  interrupt service routine.<br /> *<br /> *  Data register empty  interrupt service routine.<br /> *  Calls the common data register empty complete handler with pointer to the<br /> *  correct USART as argument.<br /> */<br />ISR(USARTC0_DRE_vect)<br />{<br />USART_DataRegEmpty(&amp;USART_data);<br />}<br /><br />void uart_puts(char *s)// funkcja wysyłająca cały łańcuch znaków<br />{<br />char c;<br />while((c = *s++))<br />{<br />while (!USART_IsTXDataRegisterEmpty(&amp;USART));<br />USART_PutChar(&amp;USART, c);<br />}<br /><br />}<br /><br />static int uart_putchar (char c, FILE *stream)// wysyłanie znaku przy pomocy strumienia printf<br />{<br />if (c == '\n')<br />uart_putchar('\r', stream);<br /><br />// Wait for the transmit buffer to be empty<br />while ( !( USARTC0.STATUS &amp; USART_DREIF_bm) );<br /><br />// Put our character into the transmit buffer<br />USARTC0.DATA = c;<br /><br />return 0;<br />}<br /><br />int uart_getchar(FILE *stream)// odbieranie znaku przy pomocy strumienia scanf<br />{<br />while( !(USARTC0_STATUS &amp; USART_RXCIF_bm) );// Wait until data has been received.<br />char data = USARTC0_DATA;// Temporarly store received data<br />if(data == '\r') data = '\n';<br />uart_putchar(data, stream);// Send to console what has been received, so we can see when typing<br />return data;<br />}[/syntax]<br /><br />Zarówno kod do printf jak i scanf brałem z jednego źródła. Printf jak mówiłem działa, a scanf się opiera. Czym może być to spowodowane?<br />Proszę uprzejmie o wskazówki i pozdrawiam,<br />Dawid.<br /><br />PS: W załączniku cały mój projekt i wszystkie potrzebne pliki. Program pisany pod Xmega128A3U.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=11277">dawid75_75</a> — 7 sie 2016, o 13:29</p><hr />
]]></content>
</entry>
</feed>