<?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/1937" />

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2008-12-01T22:07:16+02:00</updated>

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

		<entry>
		<author><name><![CDATA[Grendel]]></name></author>
		<updated>2008-12-01T22:07:16+02:00</updated>

		<published>2008-12-01T22:07:16+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6793#p6793</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6793#p6793"/>
		<title type="html"><![CDATA[Activating USART-interrupt makes controller reset]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6793#p6793"><![CDATA[
<blockquote><div><cite>Alloc wrote:</cite>I assume SREG has to be saved in case that some instructions were aborted before entering the interrupt which have some results in the flags in SREG like signbit or half carry ...<br />But why does avr-gcc save r0 itself before that? <img class="smilies" src="./../../../images/smilies/icon_biggrin.gif" alt=":D" title="Very Happy" /></div></blockquote><br />The AVR interrupt mechanism just sets the I flag, pushes the return address, and jumps to the ISR. The CPU is still in the state where it got interrupted and needs to be preserved. In order to save the SR you have to load it into a register, that register needs to be saved beforehand -- hence the 1st &quot;push r0&quot; <img class="smilies" src="./../../../images/smilies/icon_wink.gif" alt=";)" title="Wink" /> r1 could be pushed after that sequence  tho.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=101">Grendel</a> — Mon Dec 01, 2008 10:07 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2008-12-01T12:08:29+02:00</updated>

		<published>2008-12-01T12:08:29+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6787#p6787</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6787#p6787"/>
		<title type="html"><![CDATA[Activating USART-interrupt makes controller reset]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6787#p6787"><![CDATA[
You have found out most of the details yourself. R0 is used for temporary results and R1 should always be zero.<br /><br />If you make the routine naked, you have to push registers from inline assembler without knowing what to push. A new compiler version might assign registers in a different way. But at least it's a viable solution.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Mon Dec 01, 2008 12:08 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Alloc]]></name></author>
		<updated>2008-11-30T23:15:38+02:00</updated>

		<published>2008-11-30T23:15:38+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6782#p6782</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6782#p6782"/>
		<title type="html"><![CDATA[Activating USART-interrupt makes controller reset]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6782#p6782"><![CDATA[
Since there are no subroutine calls in the vector (or did you talk about sub-calls in the whole source?) that's probly not possible. Does avr-gcc use any registers as special functions? Eg, why does avr-gcc push all those registers at the beginning of the interrupt?<br /><div class="codebox"><p>Code: </p><pre><code> 282:   1f 92          push   r1<br /> 284:   0f 92          push   r0<br /> 286:   0f b6          in   r0, 0x3f   ; 63<br /> 288:   0f 92          push   r0<br /> 28a:   11 24          eor   r1, r1<br /> 28c:   8f 93          push   r24<br /> 28e:   9f 93          push   r25<br /> 290:   ef 93          push   r30<br /> 292:   ff 93          push   r31</code></pre></div><br />Ok, r24/25 and 30/31 seem to be because they're used in the vector by instruction a few lines after that. But what is that push r0 -&gt; in r0 -&gt; push r0?<br /><br />Regards,<br />Chris<br /><br />/Edit:<br />Ok, 0x3f is SREG, but why is it saved before executing the routine? The code doesn't access the stuff in there anyway?!<br /><br />/Edit2:<br />Okay, forget that ... I assume SREG has to be saved in case that some instructions were aborted before entering the interrupt which have some results in the flags in SREG like signbit or half carry ...<br />But why does avr-gcc save r0 itself before that? <img class="smilies" src="./../../../images/smilies/icon_biggrin.gif" alt=":D" title="Very Happy" /><br /><br /><br />/Edit3:<br />What I have in mind is simply make the ISR naked, have it only push SREG and clear the UDRIE-bit directly afterwards. After that I'd manually place all the other push operations I kicked out by making the ISR naked.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=851">Alloc</a> — Sun Nov 30, 2008 11:15 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2008-11-30T22:40:27+02:00</updated>

		<published>2008-11-30T22:40:27+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6781#p6781</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6781#p6781"/>
		<title type="html"><![CDATA[Activating USART-interrupt makes controller reset]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6781#p6781"><![CDATA[
Without looking at the details: I think the 12 and 16 MHz module have the same latency from start of interrupt to reading the first bit. It should therefore be OK to scale the 25 cycles with 16/12. This would be 33 cycles.<br /><br />You can probably reduce the number of pushes in your interrupt if you avoid subroutine calls which can't be inlined.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Sun Nov 30, 2008 10:40 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Alloc]]></name></author>
		<updated>2008-11-30T22:34:57+02:00</updated>

		<published>2008-11-30T22:34:57+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6780#p6780</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6780#p6780"/>
		<title type="html"><![CDATA[Activating USART-interrupt makes controller reset]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6780#p6780"><![CDATA[
I use the 16 MHz variant ... unfortunately there's no information on &quot;allowable interrupt latency&quot;. Only 12 and 16.5 MHz include that information.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=851">Alloc</a> — Sun Nov 30, 2008 10:34 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2008-11-30T22:16:21+02:00</updated>

		<published>2008-11-30T22:16:21+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6779#p6779</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6779#p6779"/>
		<title type="html"><![CDATA[Activating USART-interrupt makes controller reset]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6779#p6779"><![CDATA[
<blockquote class="uncited"><div>At how many cycles starts &quot;too slow&quot;?  <br /></div></blockquote><br />See the comment at the beginning of the respective assembler module. For 12 MHz:<br /><div class="codebox"><p>Code: </p><pre><code>;max allowable interrupt latency: 34 cycles -&gt; max 25 cycles interrupt disable</code></pre></div><br />Your interrupt takes 3 cycles until it executes, 2 cycles for the jump to the vector and 18 cycles until sei. This adds to any interrupt-disable time in the main code (which is at least 3 cycles since there may be 3 cycle instructions).<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Sun Nov 30, 2008 10:16 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Alloc]]></name></author>
		<updated>2008-11-30T01:20:13+02:00</updated>

		<published>2008-11-30T01:20:13+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6774#p6774</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6774#p6774"/>
		<title type="html"><![CDATA[Activating USART-interrupt makes controller reset]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6774#p6774"><![CDATA[
<blockquote><div><cite>christian wrote:</cite>For USART_UDRE, you probably need to write an assembler routine. Executing sei() after resetting the pending flag might be too slow. But look at the disassembler listing to be sure.</div></blockquote><br />At how many cycles starts &quot;too slow&quot;? <img class="smilies" src="./../../../images/smilies/icon_biggrin.gif" alt=":D" title="Very Happy" /> <br /><div class="codebox"><p>Code: </p><pre><code>00000282 &lt;__vector_14&gt;:<br /> 282:   1f 92          push   r1<br /> 284:   0f 92          push   r0<br /> 286:   0f b6          in   r0, 0x3f   ; 63<br /> 288:   0f 92          push   r0<br /> 28a:   11 24          eor   r1, r1<br /> 28c:   8f 93          push   r24<br /> 28e:   9f 93          push   r25<br /> 290:   ef 93          push   r30<br /> 292:   ff 93          push   r31<br /> 294:   55 98          cbi   0x0a, 5   ; 10<br /> 296:   78 94          sei<br /></code></pre></div><br />That's how the Vector starts ... I don't get why the compiler does all those pushes before the cbi though...<br /><br /><blockquote class="uncited"><div>The macros for declaring this type of interrupt have changed during previous releases. To be compatible, I usually take my own macro.</div></blockquote><br />Ah, ok =)<br /><br />Chris<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=851">Alloc</a> — Sun Nov 30, 2008 1:20 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2008-11-29T23:12:40+02:00</updated>

		<published>2008-11-29T23:12:40+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6773#p6773</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6773#p6773"/>
		<title type="html"><![CDATA[Activating USART-interrupt makes controller reset]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6773#p6773"><![CDATA[
For USART_UDRE, you probably need to write an assembler routine. Executing sei() after resetting the pending flag might be too slow. But look at the disassembler listing to be sure.<br /><br />In an assembler routine, you may push only one or two registers, handle the pending flag and then execute sei.<br /><br /><br /><blockquote class="uncited"><div>Btw, you (christian) suggested in other threads to define a macro for non-blocking interrupts. Why not simply use the avr-libc ISR-macro with the attribute ISR_NOBLOCK like <br /></div></blockquote><br /><br />The macros for declaring this type of interrupt have changed during previous releases. To be compatible, I usually take my own macro.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Sat Nov 29, 2008 11:12 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Alloc]]></name></author>
		<updated>2008-11-29T16:34:35+02:00</updated>

		<published>2008-11-29T16:34:35+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6770#p6770</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6770#p6770"/>
		<title type="html"><![CDATA[Activating USART-interrupt makes controller reset]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6770#p6770"><![CDATA[
Hi,<br /><br />think I understood the reason ... The UDRE-flag is set as long as UDR is not written to. By enabling interrupts at the beginning of the UDRE-interrupt another interrupt is executed ... endless loop.<br /><br />Is the USART_UDRE_vect0-ISR small enough for not enabling interrupts?<br /><br />Btw, you (christian) suggested in other threads to define a macro for non-blocking interrupts. Why not simply use the avr-libc ISR-macro with the attribute ISR_NOBLOCK like<br /><div class="codebox"><p>Code: </p><pre><code>ISR &#40;intvector, ISR_NOBLOCK&#41; &#123; ... &#125;</code></pre></div>?<br /><br />Regards,<br />Chris<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=851">Alloc</a> — Sat Nov 29, 2008 4:34 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Alloc]]></name></author>
		<updated>2008-11-29T04:11:36+02:00</updated>

		<published>2008-11-29T04:11:36+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6765#p6765</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6765#p6765"/>
		<title type="html"><![CDATA[Activating USART-interrupt makes controller reset]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=1937&amp;p=6765#p6765"><![CDATA[
Hi,<br /><br />I'm currently trying to get a mega16 to act as a bridge between USB and USART. Everything works fine, as long as I don't enable the USART Data Register Empty Interrupt (USART_UDRE_vect). As soon as I enable it the uC hangs and after a short period does a watchdog-reset, *but only* if the interrupt is declared as UTIL_INTERRUPT.<br /><div class="codebox"><p>Code: </p><pre><code>#define UTIL_INTERRUPT&#40;signame&#41;                         \<br />    void signame &#40;void&#41; __attribute__ &#40;&#40;interrupt&#41;&#41;;    \<br />    void signame &#40;void&#41;</code></pre></div><br />Declaring the interrupt the avrlibc-way ( ISR(USART_UDRE_vect) ) does work though. The assembler listing only differs in the sei() instruction appearing at the beginning of the vector in the UTIL_INTERRUPT-version.<br /><br />Testing by sending a few bytes over USB to the device which puts those bytes in a new buffer and enables the UDRE_vect. The vector itself only disables itself again (for debugging purposes ... should do the sending of the data later on). Don't see any reason why it should reset when actually reactivating the interrupts and not when keeping them disabled <img class="smilies" src="./../../../images/smilies/icon_sad.gif" alt=":(" title="Sad" /><br /><br />Any hints?<br /><br /><a href="http://svn.chrilly.net/uc-tech/USB-SPI/" class="postlink">uC-Code</a> (USB-stuff in main.c -&gt; usbFunctionWrite() and main() -&gt; close to the end, USART stuff in usart.c/h)<br /><a href="http://svn.chrilly.net/java/TestLibUsb/" class="postlink">Java app</a><br /><a href="http://svn.chrilly.net/java/USBbridge/" class="postlink">Java lib</a><br /><a href="https://libusbjava.svn.sourceforge.net/svnroot/libusbjava/trunk" class="postlink">LibUsbJava</a><br /><br />Regards,<br />Chris<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=851">Alloc</a> — Sat Nov 29, 2008 4:11 am</p><hr />
]]></content>
	</entry>
	</feed>
