<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forums.obdev.at/app.php/feed/topic/2349" />

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2009-04-24T17:49:10+02:00</updated>

	<author><name><![CDATA[Objective Development Forums]]></name></author>
	<id>https://forums.obdev.at/app.php/feed/topic/2349</id>

		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2009-04-24T17:49:10+02:00</updated>

		<published>2009-04-24T17:49:10+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=2349&amp;p=9056#p9056</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=9056#p9056"/>
		<title type="html"><![CDATA[Re: usb polling disrupted by UART interrupts]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=9056#p9056"><![CDATA[
<blockquote><div><cite>maciek_urbanski wrote:</cite>Q0: Why not use memory for REG_UARTFLAGS_B ?<br /></div></blockquote><br />Because access to I/O registers is faster by 1 cycle. You can use a memory location instead, of course.<br /><blockquote class="uncited"><div>Q1: Is uartScratch always mapped to R2 (and not used for some else variable by compiler ) ? Could we used it as storage instead of GPIOR1 ?<br /></div></blockquote><br />In principle, all modules must be compiled with<br />register uchar  uartScratch    asm(&quot;r2&quot;);<br />defined. You don't want to recompile avr-libc, though. As far as I know, avr-libc uses R2 only for floating point. So if you don't use floating point, that should be OK as long as you define this global register variable in all modules.<br /><br />And yes, you could use another register variable instead of GPIOR1, but since global register variables are such a pain, I try to avoid them when possible.<br /><br /><blockquote class="uncited"><div><div class="codebox"><p>Code: </p><pre><code>static void uartInit(void)<br />{<br />    REG_UARTFLAGS_B |= _BV(TXEN0) | _BV(RXEN0); // enable rx and tx<br />    UBRR0L = BAUDRATE_VALUE;<br />    UCSR0B = REG_UARTFLAGS_B | _BV(RXCIE0);     // enable USART rx interrupt<br />}<br /></code></pre></div><br />IT: Here you <strong class="text-strong">OR</strong> UART flag with previous contents of REG_UARTFLAGS_B.<br />Q2: What's &quot;default&quot; (after reset) value of GPIO1 ?<br />Q3: Shouldn't you <strong class="text-strong">SET</strong> it ? It wasn't initialized before, so it has 'default' value ?<br /></div></blockquote><br />Ah, sorry. The init routine should SET GPIO1. The default value of all I/O registers is 0, so that should not matter.<br /><br /><blockquote class="uncited"><div>And a side question:<br />Q4: When enabling global interrupts during UDRE interrupt routine UDRE must be disabled, but should RX be disabled too ?<br /></div></blockquote><br /><br />This depends on your implementation. If Rx and Tx routines are independent, you don't need to lock them against each other.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Fri Apr 24, 2009 5:49 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[maciek_urbanski]]></name></author>
		<updated>2009-04-24T15:55:51+02:00</updated>

		<published>2009-04-24T15:55:51+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=2349&amp;p=9055#p9055</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=9055#p9055"/>
		<title type="html"><![CDATA[Re: usb polling disrupted by UART interrupts]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=9055#p9055"><![CDATA[
I'm trying to understand your code <strong class="text-strong">christian</strong>, so bear with me. <img class="smilies" src="./../../../images/smilies/icon_smile.gif" alt=":-)" title="Smile" /><br />IT = I Think.<br /><br /><div class="codebox"><p>Code: </p><pre><code>#define REG_UARTFLAGS_B     GPIOR1<br />register uchar  uartScratch    asm(&quot;r2&quot;);<br /></code></pre></div><br />IT: Here you use a GPIOR1 port as a storage for pre-defined flags and define register uartScratch that will always get mapped to R2 by compiler.<br />Q0: Why not use memory for REG_UARTFLAGS_B ?<br />Q1: Is uartScratch always mapped to R2 (and not used for some else variable by compiler ) ? Could we used it as storage instead of GPIOR1 ?<br /><br /><div class="codebox"><p>Code: </p><pre><code>static void uartInit(void)<br />{<br />    REG_UARTFLAGS_B |= _BV(TXEN0) | _BV(RXEN0); // enable rx and tx<br />    UBRR0L = BAUDRATE_VALUE;<br />    UCSR0B = REG_UARTFLAGS_B | _BV(RXCIE0);     // enable USART rx interrupt<br />}<br /></code></pre></div><br />IT: Here you <strong class="text-strong">OR</strong> UART flag with previous contents of REG_UARTFLAGS_B.<br />Q2: What's &quot;default&quot; (after reset) value of GPIO1 ?<br />Q3: Shouldn't you <strong class="text-strong">SET</strong> it ? It wasn't initialized before, so it has 'default' value ?<br /><br />And a side question:<br />Q4: When enabling global interrupts during UDRE interrupt routine UDRE must be disabled, but should RX be disabled too ?<br /><br />Thx,<br />Maciej<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1901">maciek_urbanski</a> — Fri Apr 24, 2009 3:55 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2009-04-22T11:28:39+02:00</updated>

		<published>2009-04-22T11:28:39+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=2349&amp;p=9012#p9012</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=9012#p9012"/>
		<title type="html"><![CDATA[Re: usb polling disrupted by UART interrupts]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=9012#p9012"><![CDATA[
This is exactly what my code is intended to do. If you do it this way, the assembler emits tons of push instructions before you can actually enable global interrupts. These probably take longer than the driver allows. The code I suggested uses a naked routine to do the interrupt magic before any pushes. But you need to understand what it does to adapt the code for your needs because this is only a sketch.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Wed Apr 22, 2009 11:28 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[maciek_urbanski]]></name></author>
		<updated>2009-04-21T20:41:52+02:00</updated>

		<published>2009-04-21T20:41:52+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=2349&amp;p=9005#p9005</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=9005#p9005"/>
		<title type="html"><![CDATA[Re: usb polling disrupted by UART interrupts]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=9005#p9005"><![CDATA[
Good news!<br />...and then some more good news!<br /><br />First and foremost I've managed to get my STK600 repaired (with a help of friend). One of DC-DC buck converters (TPS62040DRC) got toasted, and since it's in SON-10 package (3.15mm*3.15mm, lead-less) replacing it was quite a challenge... But it works now.  <img class="smilies" src="./../../../images/smilies/icon_biggrin.gif" alt=":D" title="Very Happy" /><br /><br />The second news is I managed to get SW working.<br /><br />As <strong class="text-strong">nuh</strong> suggested I routed USB lines to port C, what solved most of problems. There were some occasional USB transmission errors during UART processing.<br /><br />Sadly <strong class="text-strong">christian</strong>s code did not help, but it could be because I didn't understood it completely... but it gave me an idea.<br /><br />I'm using both USART_RX and USART_UDRE of Atmega88.<br /><br />At the begging of USART_RX vector I disable RX IRQ and enable global interrupt mask via:<br /><div class="codebox"><p>Code: </p><pre><code>UCSR0B &amp;= ~_BV(RXCIE0);<br />sei();<br /></code></pre></div><br />...and at the end I re-enable RX via:<br /><div class="codebox"><p>Code: </p><pre><code>UCSR0B |= _BV(RXCIE0);<br /></code></pre></div><br /><br />I use UDRE IRQ as a re-fill mechanism for UART data. At the beginning of UDRE IRQ I clear UDRE flag and enable interrupts by:<br /><div class="codebox"><p>Code: </p><pre><code>UCSR0B &amp;= ~_BV(UDRIE0);<br />sei();<br /></code></pre></div><br /><br />...then at the end <span style="text-decoration: underline">only when there's more data to send</span> I disable interrupts and re-set UDRE to 1 via:<br /><div class="codebox"><p>Code: </p><pre><code>cli();<br />UCSR0B |= _BV(UDRIE0);<br /></code></pre></div><br /><br />It seem to work - no USB errors so far. I'll create a &quot;burn-in&quot; application constantly reading data from USB and inform if it works.<br /><br />Meanwhile if there's a gaping hole in this solution - please do tell me.  <img class="smilies" src="./../../../images/smilies/icon_cool.gif" alt="8)" title="Cool" /><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1901">maciek_urbanski</a> — Tue Apr 21, 2009 8:41 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2009-04-11T19:00:36+02:00</updated>

		<published>2009-04-11T19:00:36+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8860#p8860</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8860#p8860"/>
		<title type="html"><![CDATA[Re: usb polling disrupted by UART interrupts]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8860#p8860"><![CDATA[
Running UART interrupts with global interrupts enabled is tricky, because with the naive approach you end up in an infinite interrupt loop.<br /><br />I've done the following:<br /><div class="codebox"><p>Code: </p><pre><code>#define REG_UARTFLAGS_B     GPIOR1<br />register uchar  uartScratch    asm(&quot;r2&quot;);<br /><br />ISR(SIG_USART_RECV, ISR_NAKED)<br />{<br />    // be careful not to modify any registers or SREG flags<br />    asm volatile(<br />        &quot;in     r2, %0\n\t&quot;<br />        &quot;sts    %1, r2\n\t&quot;<br />        &quot;sei\n\t&quot;   // run with global interrupts enabled, but USART RX disabled<br />        &quot;;rjmp   __vector_Receiver &#91;commented out because fallthrough&#93;&quot;<br />        :           // no output operands<br />        : &quot;I&quot; (_SFR_IO_ADDR(REG_UARTFLAGS_B)), &quot;i&quot; (&amp;UCSR0B)<br />    );<br />}<br />/* The former ISR is naked and has no reti or rjmp and thus falls through into<br /> * the following pseudo-ISR.<br /> */<br />ISR(__vector_Receiver)<br />{<br />    do receiver jobs here<br />    UCSR0B = REG_UARTFLAGS_B | _BV(RXCIE0); /* re-enable USART RX before we return */<br />}<br /><br />static void uartInit(void)<br />{<br />    REG_UARTFLAGS_B |= _BV(TXEN0) | _BV(RXEN0); // enable rx and tx<br />    UBRR0L = BAUDRATE_VALUE;<br />    UCSR0B = REG_UARTFLAGS_B | _BV(RXCIE0);     // enable USART rx interrupt<br />}<br /></code></pre></div><br /><br />That should explain the general concept: In the interrupt handler disable uart interrupts, then enable global interrupts and before you return, enable uart interrupts again.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Sat Apr 11, 2009 7:00 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[maciek_urbanski]]></name></author>
		<updated>2009-03-14T03:42:01+02:00</updated>

		<published>2009-03-14T03:42:01+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8328#p8328</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8328#p8328"/>
		<title type="html"><![CDATA[usb polling disrupted by UART interrupts]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8328#p8328"><![CDATA[
Thanks, but I'll have forced break in my development. <img class="smilies" src="./../../../images/smilies/icon_sad.gif" alt=":(" title="Sad" /><br /><br />I've connected JTAG debugger to a bad pin of my dev. board and I've toasted it. <img class="smilies" src="./../../../images/smilies/icon_sad.gif" alt=":(" title="Sad" /> It's a rather uncommon board (Atmel STK600), so repairs will take a while... And there's a chance I will have to buy new one (if one of MCUs on it got toasted).<br /><br />Sorry for off topic - just venting...<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1901">maciek_urbanski</a> — Sat Mar 14, 2009 3:42 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nuh]]></name></author>
		<updated>2009-03-13T14:51:12+02:00</updated>

		<published>2009-03-13T14:51:12+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8317#p8317</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8317#p8317"/>
		<title type="html"><![CDATA[usb polling disrupted by UART interrupts]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8317#p8317"><![CDATA[
It's great! I am trying to solve the same problem. But now I work at USB part. The Rx\Tx communication is my next stage. Your achievements are very interesting .  This may be the decision of your problem.<br />Move D- and D+ to PORTC.2 and PORTC.3 (for example) and also connect D+ to INTO (PORTD.2). Then change appropriate parameters in file usbconfig.h<br />--------------------------------------------------<br />#define USB_CFG_IOPORTNAME      C<br /><br />#define USB_CFG_DMINUS_BIT      2<br /><br />#define USB_CFG_DPLUS_BIT       3<br />---------------------------------------------------<br />I have tested this. It works.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1910">nuh</a> — Fri Mar 13, 2009 2:51 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[maciek_urbanski]]></name></author>
		<updated>2009-03-13T12:34:49+02:00</updated>

		<published>2009-03-13T12:34:49+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8315#p8315</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8315#p8315"/>
		<title type="html"><![CDATA[usb polling disrupted by UART interrupts]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8315#p8315"><![CDATA[
Device I'm using is ATmega88. It has UART pins on D port (0,1).<br />In my current setup USB driver uses port D, pins 2,4.<br /><br />I'm using 16.5MHz config, so after looking into &quot;usbdrvasm165.inc&quot; it seems that code reads/writes entire D port (for example via &quot;in x1, USBIN&quot; and &quot;out USBOUT, x1&quot;).<br /><br />I'm guessing (and <strong class="text-strong">do</strong> correct me if i wrong here) it can disrupt/be-disrupted-by USART.<br /><br />So - can I move <strong class="text-strong">all</strong> USB lines to other port than D ? (And if yes - how ?)<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1901">maciek_urbanski</a> — Fri Mar 13, 2009 12:34 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[maciek_urbanski]]></name></author>
		<updated>2009-03-12T23:41:48+02:00</updated>

		<published>2009-03-12T23:41:48+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8312#p8312</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8312#p8312"/>
		<title type="html"><![CDATA[usb polling disrupted by UART interrupts]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8312#p8312"><![CDATA[
Hmm - that made a mess. <img class="smilies" src="./../../../images/smilies/icon_cool.gif" alt="8)" title="Cool" /><br /><br />Result of adding ISR_NOBLOCK to UART RXC and UDRE vectors was a constant repetition of disconnections and re-connections of USB (and no transmission on UART either).<br /><br />I'm a newbie in this so excuse me if I'm deep in the mist here but Atmel docs say that lower-address IRQs have higher priority, so UART should not interrupt USB, right ?<br /><br />Currently I'm asuming that the delay introduced by UART IRQs between USB packets is causing this, but I may be &quot;reaching&quot;...<br /><br />Any help would be most apprectiated. <img class="smilies" src="./../../../images/smilies/icon_smile.gif" alt=":-)" title="Smile" /><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1901">maciek_urbanski</a> — Thu Mar 12, 2009 11:41 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Grendel]]></name></author>
		<updated>2009-03-12T20:20:38+02:00</updated>

		<published>2009-03-12T20:20:38+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8311#p8311</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8311#p8311"/>
		<title type="html"><![CDATA[usb polling disrupted by UART interrupts]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=2349&amp;p=8311#p8311"><![CDATA[
The USB IRQ needs to be able to interrupt the USART ISRs -- either put a sli after saving the sr (assembler) or define your ISRs as<br /><br />ISR( UARTn_.._vect, ISR_NOBLOCK )<br />{<br />  ..<br />}<br /><br />when using GCC w/ avr_libc.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=101">Grendel</a> — Thu Mar 12, 2009 8:20 pm</p><hr />
]]></content>
	</entry>
	</feed>
