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

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2013-09-15T04:20:36+02:00</updated>

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

		<entry>
		<author><name><![CDATA[Nitz76]]></name></author>
		<updated>2013-09-15T04:20:36+02:00</updated>

		<published>2013-09-15T04:20:36+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25805#p25805</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25805#p25805"/>
		<title type="html"><![CDATA[Re: ATMEGA328P on V-USB]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25805#p25805"><![CDATA[
<blockquote><div><cite>ulao wrote:</cite>what's funny about that is I had that same misunderstanding. <br /><!-- m --><a class="postlink" href="http://www.avrfreaks.net/index.php?name=PNphpBB2&amp;file=viewtopic&amp;t=97483&amp;highlight=bootloader">http://www.avrfreaks.net/index.php?name ... bootloader</a><!-- m --><br />Guess who helped me?<br /><br />Though I completely over looked that. <img class="smilies" src="./../../../images/smilies/icon_redface.gif" alt=":oops:" title="Embarassed" /></div></blockquote><br /><br />So funny!  <img class="smilies" src="./../../../images/smilies/icon_razz.gif" alt=":P" title="Razz" />  Sometimes... well almost all the times it's something obviously simple but forgotten...  <img class="smilies" src="./../../../images/smilies/icon_mrgreen.gif" alt=":mrgreen:" title="Mr. Green" /> <br /><br />Cheers everyone!<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=12540">Nitz76</a> — Sun Sep 15, 2013 4:20 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ulao]]></name></author>
		<updated>2013-09-10T13:32:10+02:00</updated>

		<published>2013-09-10T13:32:10+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25789#p25789</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25789#p25789"/>
		<title type="html"><![CDATA[Re: ATMEGA328P on V-USB]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25789#p25789"><![CDATA[
what's funny about that is I had that same misunderstanding. <br /><!-- m --><a class="postlink" href="http://www.avrfreaks.net/index.php?name=PNphpBB2&amp;file=viewtopic&amp;t=97483&amp;highlight=bootloader">http://www.avrfreaks.net/index.php?name ... bootloader</a><!-- m --><br />Guess who helped me?<br /><br />Though I completely over looked that. <img class="smilies" src="./../../../images/smilies/icon_redface.gif" alt=":oops:" title="Embarassed" /><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1281">ulao</a> — Tue Sep 10, 2013 1:32 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Nitz76]]></name></author>
		<updated>2013-09-10T01:40:33+02:00</updated>

		<published>2013-09-10T01:40:33+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25788#p25788</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25788#p25788"/>
		<title type="html"><![CDATA[Re: ATMEGA328P on V-USB]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25788#p25788"><![CDATA[
Guys... this is a basic mistake;<br /><br />if the bootloader is set to 0x3800... this is counted in &quot;words&quot;.  When you move the origin of the program, it's counted in &quot;bytes&quot; (2x) sooo  when you set the bootloader start address, it's 2x 0x3800 = 0x7000.<br /><br />End of the story.<br /><br />Thanks to clawson@avrfreaks <a href="http://www.avrfreaks.net/index.php?name=PNphpBB2&amp;file=viewtopic&amp;p=1097841#1097841" class="postlink">http://www.avrfreaks.net/index.php?name=PNphpBB2&amp;file=viewtopic&amp;p=1097841#1097841</a><br /><br />And thank you all for your answers and toughts!!!  <img class="smilies" src="./../../../images/smilies/icon_biggrin.gif" alt=":D" title="Very Happy" /><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=12540">Nitz76</a> — Tue Sep 10, 2013 1:40 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Nitz76]]></name></author>
		<updated>2013-09-09T15:47:01+02:00</updated>

		<published>2013-09-09T15:47:01+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25785#p25785</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25785#p25785"/>
		<title type="html"><![CDATA[Re: ATMEGA328P on V-USB]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25785#p25785"><![CDATA[
Here you go.  <br /><br />P.S. I changed the boot address to $3800 <br /><br /><div class="codebox"><p>Code: </p><pre><code>main.elf:     file format elf32-avr<br /><br />SYMBOL TABLE:<br />00003800 l    d  .text   00000000 .text<br />00800100 l    d  .bss   00000000 .bss<br />00820000 l    d  .fuse   00000000 .fuse<br />00830000 l    d  .lock   00000000 .lock<br />00840000 l    d  .signature   00000000 .signature<br />00000000 l    d  .debug_aranges   00000000 .debug_aranges<br />00000000 l    d  .debug_pubnames   00000000 .debug_pubnames<br />00000000 l    d  .debug_info   00000000 .debug_info<br />00000000 l    d  .debug_abbrev   00000000 .debug_abbrev<br />00000000 l    d  .debug_line   00000000 .debug_line<br />00000000 l    d  .debug_frame   00000000 .debug_frame<br />00000000 l    d  .debug_str   00000000 .debug_str<br />0000387e l       .text   00000000 .do_clear_bss_start<br />0000387c l       .text   00000000 .do_clear_bss_loop<br />00000000 l    df *ABS*   00000000 main.c<br />0000003f l       *ABS*   00000000 __SREG__<br />0000003e l       *ABS*   00000000 __SP_H__<br />0000003d l       *ABS*   00000000 __SP_L__<br />00000034 l       *ABS*   00000000 __CCP__<br />00000000 l       *ABS*   00000000 __tmp_reg__<br />00000001 l       *ABS*   00000000 __zero_reg__<br />0000395e l       .text   00000000 __stop_program<br />0000388c  w      .text   00000000 __vector_22<br />0000392c g     F .text   00000018 __vector_1<br />00003868 g       .text   00000000 __trampolines_start<br />00003960 g       .text   00000000 _etext<br />0000388c  w      .text   00000000 __vector_24<br />0000388c  w      .text   00000000 __vector_12<br />0000388c g       .text   00000000 __bad_interrupt<br />00003960 g       *ABS*   00000000 __data_load_end<br />0000388c  w      .text   00000000 __vector_6<br />00003868 g       .text   00000000 __trampolines_end<br />0000388c  w      .text   00000000 __vector_3<br />0000388c  w      .text   00000000 __vector_23<br />00003960 g       *ABS*   00000000 __data_load_start<br />00003868 g       .text   00000000 __dtors_end<br />00800101 g       .bss   00000000 __bss_end<br />0000388c  w      .text   00000000 __vector_25<br />00840000 g     O .signature   00000003 __signature<br />00800100 g     O .bss   00000001 polarity<br />0000388c  w      .text   00000000 __vector_11<br />00003868  w      .text   00000000 __init<br />0000388c  w      .text   00000000 __vector_13<br />0000388c  w      .text   00000000 __vector_17<br />0000388c  w      .text   00000000 __vector_19<br />000038f2 g     F .text   0000003a __vector_7<br />00003874 g       .text   00000000 __do_clear_bss<br />00810000 g       .bss   00000000 __eeprom_end<br />00003800 g       .text   00000000 __vectors<br />00003800  w      .text   00000000 __vector_default<br />0000388c  w      .text   00000000 __vector_5<br />00003868 g       .text   00000000 __ctors_start<br />00800100 g       .bss   00000000 __bss_start<br />00003890 g     F .text   00000062 main<br />0000388c  w      .text   00000000 __vector_4<br />00830000 g     O .lock   00000001 __lock<br />00000000  w      *ABS*   00000000 __heap_end<br />0000388c  w      .text   00000000 __vector_9<br />00003944 g     F .text   00000018 __vector_2<br />0000388c  w      .text   00000000 __vector_21<br />0000388c  w      .text   00000000 __vector_15<br />00003868 g       .text   00000000 __dtors_start<br />00003868 g       .text   00000000 __ctors_end<br />000008ff  w      *ABS*   00000000 __stack<br />00800100 g       .text   00000000 _edata<br />00800101 g       .bss   00000000 _end<br />0000388c  w      .text   00000000 __vector_8<br />00820000 g     O .fuse   00000003 __fuse<br />0000395c  w      .text   00000000 exit<br />0000395c g       .text   00000000 _exit<br />0000388c  w      .text   00000000 __vector_14<br />0000388c  w      .text   00000000 __vector_10<br />0000388c  w      .text   00000000 __vector_16<br />0000388c  w      .text   00000000 __vector_18<br />0000388c  w      .text   00000000 __vector_20<br /><br /><br /><br />Disassembly of section .text:<br /><br />00003800 &lt;__vectors&gt;:<br />    3800:   0c 94 34 1c    jmp   0x3868   ; 0x3868 &lt;__ctors_end&gt;<br />    3804:   0c 94 96 1c    jmp   0x392c   ; 0x392c &lt;__vector_1&gt;<br />    3808:   0c 94 a2 1c    jmp   0x3944   ; 0x3944 &lt;__vector_2&gt;<br />    380c:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    3810:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    3814:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    3818:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    381c:   0c 94 79 1c    jmp   0x38f2   ; 0x38f2 &lt;__vector_7&gt;<br />    3820:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    3824:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    3828:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    382c:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    3830:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    3834:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    3838:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    383c:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    3840:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    3844:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    3848:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    384c:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    3850:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    3854:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    3858:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    385c:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    3860:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br />    3864:   0c 94 46 1c    jmp   0x388c   ; 0x388c &lt;__bad_interrupt&gt;<br /><br />00003868 &lt;__ctors_end&gt;:<br />    3868:   11 24          eor   r1, r1<br />    386a:   1f be          out   0x3f, r1   ; 63<br />    386c:   cf ef          ldi   r28, 0xFF   ; 255<br />    386e:   d8 e0          ldi   r29, 0x08   ; 8<br />    3870:   de bf          out   0x3e, r29   ; 62<br />    3872:   cd bf          out   0x3d, r28   ; 61<br /><br />00003874 &lt;__do_clear_bss&gt;:<br />    3874:   11 e0          ldi   r17, 0x01   ; 1<br />    3876:   a0 e0          ldi   r26, 0x00   ; 0<br />    3878:   b1 e0          ldi   r27, 0x01   ; 1<br />    387a:   01 c0          rjmp   .+2         ; 0x387e &lt;.do_clear_bss_start&gt;<br /><br />0000387c &lt;.do_clear_bss_loop&gt;:<br />    387c:   1d 92          st   X+, r1<br /><br />0000387e &lt;.do_clear_bss_start&gt;:<br />    387e:   a1 30          cpi   r26, 0x01   ; 1<br />    3880:   b1 07          cpc   r27, r17<br />    3882:   e1 f7          brne   .-8         ; 0x387c &lt;.do_clear_bss_loop&gt;<br />    3884:   0e 94 48 1c    call   0x3890   ; 0x3890 &lt;main&gt;<br />    3888:   0c 94 ae 1c    jmp   0x395c   ; 0x395c &lt;_exit&gt;<br /><br />0000388c &lt;__bad_interrupt&gt;:<br />    388c:   0c 94 00 1c    jmp   0x3800   ; 0x3800 &lt;__vectors&gt;<br /><br />00003890 &lt;main&gt;:<br />    Parameters :    none<br />    Return values :   none<br />**************************************************************************************************************/<br />__attribute__ ((OS_main)) int main(void)<br />{<br />   MCUCR = (1 &lt;&lt; IVCE);   // enable change of interrupt vectors <br />    3890:   81 e0          ldi   r24, 0x01   ; 1<br />    3892:   85 bf          out   0x35, r24   ; 53<br />   MCUCR = (1 &lt;&lt; IVSEL);   // move interrupts to bootloader flash section<br />    3894:   82 e0          ldi   r24, 0x02   ; 2<br />    3896:   85 bf          out   0x35, r24   ; 53<br /><br />   //Input<br />   DDRD &amp;= ~((1&lt;&lt;PD2)|(1&lt;&lt;PD3));   // PD2=INT0=Button0/PD3=INT1=Button1<br />    3898:   8a b1          in   r24, 0x0a   ; 10<br />    389a:   83 7f          andi   r24, 0xF3   ; 243<br />    389c:   8a b9          out   0x0a, r24   ; 10<br />   PORTD |= ((1&lt;&lt;PD2)|(1&lt;&lt;PD3));   // Pull-UP<br />    389e:   8b b1          in   r24, 0x0b   ; 11<br />    38a0:   8c 60          ori   r24, 0x0C   ; 12<br />    38a2:   8b b9          out   0x0b, r24   ; 11<br /><br />   //Output<br />   DDRD |= ((1&lt;&lt;PD4)|(1&lt;&lt;PD5)|(1&lt;&lt;PD6)|(1&lt;&lt;PD7));      // PD4=RedLED/PD5=GreenLED/PD6=LED0/PD7=LED1<br />    38a4:   8a b1          in   r24, 0x0a   ; 10<br />    38a6:   80 6f          ori   r24, 0xF0   ; 240<br />    38a8:   8a b9          out   0x0a, r24   ; 10<br />   PORTD &amp;= ~((1&lt;&lt;PD4)|(1&lt;&lt;PD5)|(1&lt;&lt;PD6)|(1&lt;&lt;PD7));   // Off<br />    38aa:   8b b1          in   r24, 0x0b   ; 11<br />    38ac:   8f 70          andi   r24, 0x0F   ; 15<br />    38ae:   8b b9          out   0x0b, r24   ; 11<br /><br />   // Set timer 2 for each second<br />   TCCR2A |= (1&lt;&lt;WGM21); // CTC<br />    38b0:   80 91 b0 00    lds   r24, 0x00B0<br />    38b4:   82 60          ori   r24, 0x02   ; 2<br />    38b6:   80 93 b0 00    sts   0x00B0, r24<br />   TCCR2B |= ((1&lt;&lt;CS20)|(1&lt;&lt;CS21)|(1&lt;&lt;CS22)); // XTAL/1024<br />    38ba:   80 91 b1 00    lds   r24, 0x00B1<br />    38be:   87 60          ori   r24, 0x07   ; 7<br />    38c0:   80 93 b1 00    sts   0x00B1, r24<br /><br />   OCR2A=(unsigned char)((F_XTAL)/1024); // 1Hz<br />    38c4:   8f e1          ldi   r24, 0x1F   ; 31<br />    38c6:   80 93 b3 00    sts   0x00B3, r24<br /><br />   TIMSK2 |= (1&lt;&lt;OCIE2A);   // Ativate interrupt on timer 2A output compare<br />    38ca:   80 91 70 00    lds   r24, 0x0070<br />    38ce:   82 60          ori   r24, 0x02   ; 2<br />    38d0:   80 93 70 00    sts   0x0070, r24<br /><br />   TCNT2=0; // Restart timer 2<br />    38d4:   10 92 b2 00    sts   0x00B2, r1<br /><br />   // Global variable init<br />   polarity=0;<br />    38d8:   10 92 00 01    sts   0x0100, r1<br /><br />   // Enable interrupt on buttons<br />   EIMSK |= ((1&lt;&lt;INT0)|(1&lt;&lt;INT1));<br />    38dc:   8d b3          in   r24, 0x1d   ; 29<br />    38de:   83 60          ori   r24, 0x03   ; 3<br />    38e0:   8d bb          out   0x1d, r24   ; 29<br />   EICRA |= ((1&lt;&lt;ISC01)|(1&lt;&lt;ISC11));   // Interrupt on falling edge<br />    38e2:   80 91 69 00    lds   r24, 0x0069<br />    38e6:   8a 60          ori   r24, 0x0A   ; 10<br />    38e8:   80 93 69 00    sts   0x0069, r24<br /><br />   sei();   // Enable interrupts<br />    38ec:   78 94          sei<br /><br />   PORTD |= (1&lt;&lt;PD4);   // RedLED on<br />    38ee:   5c 9a          sbi   0x0b, 4   ; 11<br />    38f0:   ff cf          rjmp   .-2         ; 0x38f0 &lt;main+0x60&gt;<br /><br />000038f2 &lt;__vector_7&gt;:<br />/*************************************************************************************************************<br />    Interruption:   TIMER2_COMPA_vect<br />    Description:   Happen each time TCNT2A = OCR2A (1 second)<br />**************************************************************************************************************/<br />ISR(TIMER2_COMPA_vect)<br />{<br />    38f2:   1f 92          push   r1<br />    38f4:   0f 92          push   r0<br />    38f6:   0f b6          in   r0, 0x3f   ; 63<br />    38f8:   0f 92          push   r0<br />    38fa:   11 24          eor   r1, r1<br />    38fc:   8f 93          push   r24<br />    38fe:   9f 93          push   r25<br />   // GreenLED flash<br />   polarity=polarity?0:1;<br />    3900:   80 91 00 01    lds   r24, 0x0100<br />    3904:   90 e0          ldi   r25, 0x00   ; 0<br />    3906:   88 23          and   r24, r24<br />    3908:   09 f4          brne   .+2         ; 0x390c &lt;__vector_7+0x1a&gt;<br />    390a:   91 e0          ldi   r25, 0x01   ; 1<br />    390c:   90 93 00 01    sts   0x0100, r25<br /><br />   if(polarity)<br />    3910:   80 91 00 01    lds   r24, 0x0100<br />    3914:   88 23          and   r24, r24<br />    3916:   11 f0          breq   .+4         ; 0x391c &lt;__vector_7+0x2a&gt;<br />      PORTD |= (1&lt;&lt;PD5);<br />    3918:   5d 9a          sbi   0x0b, 5   ; 11<br />    391a:   01 c0          rjmp   .+2         ; 0x391e &lt;__vector_7+0x2c&gt;<br />   else<br />      PORTD &amp;= ~(1&lt;&lt;PD5);<br />    391c:   5d 98          cbi   0x0b, 5   ; 11<br />}<br />    391e:   9f 91          pop   r25<br />    3920:   8f 91          pop   r24<br />    3922:   0f 90          pop   r0<br />    3924:   0f be          out   0x3f, r0   ; 63<br />    3926:   0f 90          pop   r0<br />    3928:   1f 90          pop   r1<br />    392a:   18 95          reti<br /><br />0000392c &lt;__vector_1&gt;:<br />/*************************************************************************************************************<br />    Interruption:   INT0_vect <br />    Description:   Happen each time But0 is pushed<br />**************************************************************************************************************/<br />ISR(INT0_vect)<br />{<br />    392c:   1f 92          push   r1<br />    392e:   0f 92          push   r0<br />    3930:   0f b6          in   r0, 0x3f   ; 63<br />    3932:   0f 92          push   r0<br />    3934:   11 24          eor   r1, r1<br />   PORTD |= ((1&lt;&lt;PD6));   // Led0 on<br />    3936:   5e 9a          sbi   0x0b, 6   ; 11<br />   PORTD &amp;= ~((1&lt;&lt;PD7));   // Led1 off<br />    3938:   5f 98          cbi   0x0b, 7   ; 11<br />}<br />    393a:   0f 90          pop   r0<br />    393c:   0f be          out   0x3f, r0   ; 63<br />    393e:   0f 90          pop   r0<br />    3940:   1f 90          pop   r1<br />    3942:   18 95          reti<br /><br />00003944 &lt;__vector_2&gt;:<br />/*************************************************************************************************************<br />    Interruption:   INT1_vect <br />    Description:   Happen each time But1 is pushed<br />**************************************************************************************************************/<br />ISR(INT1_vect)<br />{<br />    3944:   1f 92          push   r1<br />    3946:   0f 92          push   r0<br />    3948:   0f b6          in   r0, 0x3f   ; 63<br />    394a:   0f 92          push   r0<br />    394c:   11 24          eor   r1, r1<br />   PORTD &amp;= ~((1&lt;&lt;PD6));   // Led0 off<br />    394e:   5e 98          cbi   0x0b, 6   ; 11<br />   PORTD |= ((1&lt;&lt;PD7));   // Led1 on<br />    3950:   5f 9a          sbi   0x0b, 7   ; 11<br />}<br />    3952:   0f 90          pop   r0<br />    3954:   0f be          out   0x3f, r0   ; 63<br />    3956:   0f 90          pop   r0<br />    3958:   1f 90          pop   r1<br />    395a:   18 95          reti<br /><br />0000395c &lt;_exit&gt;:<br />    395c:   f8 94          cli<br /><br />0000395e &lt;__stop_program&gt;:<br />    395e:   ff cf          rjmp   .-2         ; 0x395e &lt;__stop_program&gt;<br /></code></pre></div><br /><br />main.c<br /><div class="codebox"><p>Code: </p><pre><code>/*************************************************************************************************************<br />*    Title         : Test bootloader atmega328p<br />*    File         : main.c<br />*    SW Version   : <br />*    HW Version   : <br />*    MCU          : ATMEGA328P<br />*    Start date   : 9/9/2013<br />*    Update       : <br />**************************************************************************************************************/<br /><br />#include &lt;avr/io.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br /><br />#include &quot;fuses.h&quot;<br /><br />#define F_XTAL   32000<br /><br />volatile unsigned char polarity;<br /><br />/*************************************************************************************************************<br />    Function :      main  <br />    Description :   Main function<br />    Parameters :    none<br />    Return values :   none<br />**************************************************************************************************************/<br />__attribute__ ((OS_main)) int main(void)<br />{<br />   MCUCR = (1 &lt;&lt; IVCE);   // enable change of interrupt vectors <br />   MCUCR = (1 &lt;&lt; IVSEL);   // move interrupts to bootloader flash section<br /><br />   //Input<br />   DDRD &amp;= ~((1&lt;&lt;PD2)|(1&lt;&lt;PD3));   // PD2=INT0=Button0/PD3=INT1=Button1<br />   PORTD |= ((1&lt;&lt;PD2)|(1&lt;&lt;PD3));   // Pull-UP<br /><br />   //Output<br />   DDRD |= ((1&lt;&lt;PD4)|(1&lt;&lt;PD5)|(1&lt;&lt;PD6)|(1&lt;&lt;PD7));      // PD4=RedLED/PD5=GreenLED/PD6=LED0/PD7=LED1<br />   PORTD &amp;= ~((1&lt;&lt;PD4)|(1&lt;&lt;PD5)|(1&lt;&lt;PD6)|(1&lt;&lt;PD7));   // Off<br /><br />   // Set timer 2 for each second<br />   TCCR2A |= (1&lt;&lt;WGM21); // CTC<br />   TCCR2B |= ((1&lt;&lt;CS20)|(1&lt;&lt;CS21)|(1&lt;&lt;CS22)); // XTAL/1024<br /><br />   ASSR |= (1&lt;&lt;AS2); // Async<br /><br />   OCR2A=(unsigned char)((F_XTAL)/1024); // 1Hz<br /><br />   TIMSK2 |= (1&lt;&lt;OCIE2A);   // Ativate interrupt on timer 2A output compare<br /><br />   TCNT2=0; // Restart timer 2<br /><br />   // Global variable init<br />   polarity=0;<br /><br />   // Enable interrupt on buttons<br />   EIMSK |= ((1&lt;&lt;INT0)|(1&lt;&lt;INT1));<br />   EICRA |= ((1&lt;&lt;ISC01)|(1&lt;&lt;ISC11));   // Interrupt on falling edge<br /><br />   sei();   // Enable interrupts<br /><br />   PORTD |= (1&lt;&lt;PD4);   // RedLED on<br /><br />   for(;;)   // Infinite loop<br />   {<br />   }<br />}<br /><br />/*************************************************************************************************************<br />    Interruption:   TIMER2_COMPA_vect<br />    Description:   Happen each time TCNT2A = OCR2A (1 second)<br />**************************************************************************************************************/<br />ISR(TIMER2_COMPA_vect)<br />{<br />   // GreenLED flash<br />   polarity=polarity?0:1;<br /><br />   if(polarity)<br />      PORTD |= (1&lt;&lt;PD5);<br />   else<br />      PORTD &amp;= ~(1&lt;&lt;PD5);<br />}<br /><br />/*************************************************************************************************************<br />    Interruption:   INT0_vect <br />    Description:   Happen each time But0 is pushed<br />**************************************************************************************************************/<br />ISR(INT0_vect)<br />{<br />   PORTD |= ((1&lt;&lt;PD6));   // Led0 on<br />   PORTD &amp;= ~((1&lt;&lt;PD7));   // Led1 off<br />}<br /><br />/*************************************************************************************************************<br />    Interruption:   INT1_vect <br />    Description:   Happen each time But1 is pushed<br />**************************************************************************************************************/<br />ISR(INT1_vect)<br />{<br />   PORTD &amp;= ~((1&lt;&lt;PD6));   // Led0 off<br />   PORTD |= ((1&lt;&lt;PD7));   // Led1 on<br />}<br /></code></pre></div><br /><br />fuses.h<br /><div class="codebox"><p>Code: </p><pre><code>/*************************************************************************************************************<br />*    Title :         Header file for fuses<br />*    File :          fuses.h<br />*************************************************************************************************************/<br /><br />/*************************************************************************************************************<br />*   DEVICE = ATMEGA328P<br />*   FUSES = LOW = 0xC2, HIGH = 0xD8, EXTENDED = 0xFD<br />*   -----<br />*   BODLEVEL = 2.7V<br />*   RSTDISBL = NO<br />*   DWEN = NO<br />*   SPIEN = YES<br />*   WDTON = NO<br />*   EESAVE = YES<br />*   BOOTSZ = Boot Flash size=2048 words, Boot address 0x3800<br />*   BOOTRST = YES<br />*   CKDIV8 = NO<br />*   CKOUT = NO<br />*   SUT_CKSEL = Int.Crystal/Osc 8.0Mhz; 6CK/14CK + 0ms<br />*************************************************************************************************************/<br /><br />/*************************************************************************************************************<br />*   LOCKBITS = 0xFC<br />*   --------<br />*   LB = FURTHER PROGRAMMING &amp; VERIFICATION DISABLED<br />**************************************************************************************************************/<br /><br />#include &lt;avr/io.h&gt;<br />#include &lt;avr/signature.h&gt; <br /><br />#ifndef FUSES_H<br />#define FUSES_H<br /><br />__fuse_t __fuse __attribute__((section (&quot;.fuse&quot;))) = <br />{<br />    .low = 0xC2,<br />    .high = 0xD8,<br />   .extended = 0xFD,<br />};<br /><br />unsigned char __lock __attribute__((section (&quot;.lock&quot;))) = 0xFC;<br /><br />#endif<br /></code></pre></div><br /><br />Makefile<br /><div class="codebox"><p>Code: </p><pre><code>###############################################################################<br /># Makefile for the project main<br />###############################################################################<br /><br />## General Flags<br />PROJECT = main<br />MCU = atmega328p<br />TARGET = main.elf<br />CC = avr-gcc<br /><br />CPP = avr-g++<br /><br />## Options common to compile, link and assembly rules<br />COMMON = -mmcu=$(MCU)<br /><br />## Compile options common for all C compilation units.<br />CFLAGS = $(COMMON)<br />CFLAGS += -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums  -Wall <br />CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d <br /><br />## Assembly specific flags<br />ASMFLAGS = $(COMMON)<br />ASMFLAGS += $(CFLAGS)<br />ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2<br /><br />## Linker flags<br />LDFLAGS = $(COMMON)<br />LDFLAGS +=  -Wl,--section-start=.text=0x3800  -Wl,-Map=main.map<br /><br /><br />## Intel Hex file production flags<br />HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature<br /><br />HEX_EEPROM_FLAGS = -j .eeprom<br />HEX_EEPROM_FLAGS += --set-section-flags=.eeprom=&quot;alloc,load&quot;<br />HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings<br /><br /><br />## Objects that must be built in order to link<br />OBJECTS = main.o <br /><br />## Objects explicitly added by the user<br />LINKONLYOBJECTS = <br /><br />## Build<br />all: $(TARGET) main.hex main.eep main.lss size<br /><br />## Compile<br />main.o: main.c<br />   $(CC) $(INCLUDES) $(CFLAGS) -c  $&lt;<br /><br />##Link<br />$(TARGET): $(OBJECTS)<br />    $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)<br /><br />%.hex: $(TARGET)<br />   avr-objcopy -O ihex $(HEX_FLASH_FLAGS)  $&lt; $@<br /><br />%.eep: $(TARGET)<br />   -avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $&lt; $@ || exit 0<br /><br />%.lss: $(TARGET)<br />   avr-objdump -h -S $&lt; &gt; $@<br /><br />size: ${TARGET}<br />   @echo<br />   @avr-size -C --mcu=${MCU} ${TARGET}<br /><br />## Clean target<br />.PHONY: clean<br />clean:<br />   -rm -rf $(OBJECTS) main.elf dep/* main.hex main.eep main.lss main.map<br /><br /><br />## Other dependencies<br />-include $(shell mkdir dep 2&gt;NUL) $(wildcard dep/*)<br /><br /></code></pre></div><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=12540">Nitz76</a> — Mon Sep 09, 2013 3:47 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2013-09-09T12:40:34+02:00</updated>

		<published>2013-09-09T12:40:34+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25784#p25784</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25784#p25784"/>
		<title type="html"><![CDATA[Re: ATMEGA328P on V-USB]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25784#p25784"><![CDATA[
<blockquote><div><cite>Nitz76 wrote:</cite>MCUCR = (1 &lt;&lt; IVCE); /* enable change of interrupt vectors */<br />MCUCR = (1 &lt;&lt; IVSEL); /* move interrupts to bootloader flash section */</div></blockquote><br />Hi.<br />Can you please send us the complete objectdumped  (&quot;avr-objdump -Stdr main.elf &gt; main.asm&quot;) firmware you have flashed?<br />And maybe a flash (readback) dump, too.<br /><br />BR vouvoume<p>Statistics: Posted by Guest — Mon Sep 09, 2013 12:40 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Nitz76]]></name></author>
		<updated>2013-09-09T03:54:38+02:00</updated>

		<published>2013-09-09T03:54:38+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25782#p25782</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25782#p25782"/>
		<title type="html"><![CDATA[Re: ATMEGA328P on V-USB]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25782#p25782"><![CDATA[
Hey, I tried some things today.<br />I have another board using a atmega328p. I'm 100% sure this one is powered/decoupled properly.<br /><br />I wrote a simple bootloader application.  I moved that application to 0x3C00 + fuses to start bootloader at $3C00 and BOOTRST set.<br />This application turns on a led and loop.  It works.<br />I then added a led blinking fuction in interrupt.  Works at 0x000 no problem.<br />When I move it to 0x3C00 and added;<br />    MCUCR = (1 &lt;&lt; IVCE);     /* enable change of interrupt vectors */<br />    MCUCR = (1 &lt;&lt; IVSEL);    /* move interrupts to bootloader flash section */<br />This function stop working.<br /><br />Is there someting else to do?<br /><br />Thanks!<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=12540">Nitz76</a> — Mon Sep 09, 2013 3:54 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Nitz76]]></name></author>
		<updated>2013-09-08T01:39:20+02:00</updated>

		<published>2013-09-08T01:39:20+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25781#p25781</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25781#p25781"/>
		<title type="html"><![CDATA[Re: ATMEGA328P on V-USB]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25781#p25781"><![CDATA[
I ordered some atmega168a from digikey. Looks like 168 has been corrected for... things... thus they issued a new part number with an &quot;a&quot;. It is not a picopower.<br />This is the first time I deal with bootloader with picopower atmega.  <img class="smilies" src="./../../../images/smilies/icon_neutral.gif" alt=":|" title="Neutral" /> I'll try to correct the board just to prove that it's the issue. I want to use the 328p in the future for other application since it's a very convenient size vs fuctionality.<br /><br />Thanks guys!  I'll let you know how it turns out.  <img class="smilies" src="./../../../images/smilies/icon_wink.gif" alt=":wink:" title="Wink" /> <br /><br />Nitz<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=12540">Nitz76</a> — Sun Sep 08, 2013 1:39 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ulao]]></name></author>
		<updated>2013-09-07T23:53:20+02:00</updated>

		<published>2013-09-07T23:53:20+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25780#p25780</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25780#p25780"/>
		<title type="html"><![CDATA[Re: ATMEGA328P on V-USB]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25780#p25780"><![CDATA[
You know I meant to bring that up, do you really need that much flash? The 168 is a very rock solid chip and easy to find without pico power. I have had great success with my 328's thus far. I never used a second bypass capacitor like that. Assuming its also near the mcu that good enough. I do put 27 pf around my oscillator though.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1281">ulao</a> — Sat Sep 07, 2013 11:53 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Nitz76]]></name></author>
		<updated>2013-09-07T20:05:23+02:00</updated>

		<published>2013-09-07T20:05:23+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25779#p25779</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25779#p25779"/>
		<title type="html"><![CDATA[Re: ATMEGA328P on V-USB]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25779#p25779"><![CDATA[
So... you're saying that I can use an Atmega168 and I should not have any issue like i'm having right now?  I'll give it a try, since my PCB is already setup at my PCB fab. I would save some $$$.<br /><br />Thanks!<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=12540">Nitz76</a> — Sat Sep 07, 2013 8:05 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Nitz76]]></name></author>
		<updated>2013-09-07T19:30:44+02:00</updated>

		<published>2013-09-07T19:30:44+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25778#p25778</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25778#p25778"/>
		<title type="html"><![CDATA[Re: ATMEGA328P on V-USB]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=4022&amp;p=25778#p25778"><![CDATA[
Here are the picture of the board and the schematic:<br /><br /><img src="http://francis.gradel.ca/images/joyv2_sch.jpg" class="postimage" alt="Image" /><br /><br /><img src="http://francis.gradel.ca/images/joyv2_img.jpg" class="postimage" alt="Image" /><br /><br />Maybe there are 1 or 2 caps missing.  <img class="smilies" src="./../../../images/smilies/icon_sad.gif" alt=":(" title="Sad" /><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=12540">Nitz76</a> — Sat Sep 07, 2013 7:30 pm</p><hr />
]]></content>
	</entry>
	</feed>
