Atmega8535 OK / Atmega328p FAIL

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
favrer
Posts: 1
Joined: Wed Dec 30, 2009 7:51 pm

Re: Atmega8535 OK / Atmega328p FAIL

Post by favrer » Wed Dec 30, 2009 7:59 pm

I started to switch from ATmega168 with USBaspLoader to the ATmega328p and I always get an unrecognized USB device.
I run all my devices with 12MHz and program via avrdude from the makefile without problems so far.

Thanks for all tips in this thread so far :) !
It did follow the recommendation to treat the 328P chip 100% like the 168, but this fails.

I also changed the interrupt vector as recommended by Detlev in usbdrvasm.S
# ifndef USB_INTR_VECTOR /* default to hardware interrupt INT0 */
# define USB_INTR_VECTOR INT0_vect /* 30Dec09 SIG_INTERRUPT0 viewtopic.php?f=8&t=2663 */
# endif

But now compiling and flashing (successfully) as 328P or as 168 still fails, with an unrecognized USB device. :(

What else needs to be changed to run USBaspLoader onto an 328P with my case 12MHz ?

Alan Chatham
Rank 1
Rank 1
Posts: 28
Joined: Wed Sep 30, 2009 3:36 am
Location: Osaka, Japan
Contact:

Re: Atmega8535 OK / Atmega328p FAIL

Post by Alan Chatham » Fri Feb 12, 2010 3:58 pm

I started to switch from ATmega168 with USBaspLoader to the ATmega328p and I always get an unrecognized USB device.

I'm not sure if you solved your issue with the bootloader, but one thing to make sure of is that you're putting the bootloader in the correct place. I just spent a few hours struggling to figure out why HIDBootloader wasn't working on my 328p when it was working just fine on my 168, and it turned out that I simply needed to make sure that when I compiled, I put my code in the 328p's bootloader section, which starts at a much higher address than the 168. For a 1024 word bootloader section on the 328p, the bootloader needs to be compiled such that it starts at 7800 instead of 3800 for the 168. Hope it helps someone!

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: Atmega8535 OK / Atmega328p FAIL

Post by ulao » Tue Aug 31, 2010 6:24 pm

he bootloader needs to be compiled such that it starts at 7800 instead of 3800 for the 168


Could some one explain how exactly you do that? I get options to pick from not a way to enter it manually? 2048 puts it at 3800? Is there a ways to define BOOTLOADER_ADDRESS avr studio to override the gui? I'm using the make option not a file, guessing if I made a mFile I could do it in there?

According to my AVR studio with the 328p selected I get 4 options.
Boot Flash size=256 words start address=$3F00
Boot Flash size=512 words start address=$3E00
Boot Flash size=1024 words start address=$3C00
Boot Flash size=2048 words start address=$3800
Last edited by ulao on Tue Aug 31, 2010 11:56 pm, edited 1 time in total.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: Atmega8535 OK / Atmega328p FAIL

Post by christian » Tue Aug 31, 2010 10:16 pm

The figures from AVR Studio are in words (16 bits = 2 bytes) while gcc's values and thus the values specified in the Makefile are in bytes.

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: Atmega8535 OK / Atmega328p FAIL

Post by ulao » Tue Aug 31, 2010 11:34 pm

So I should chose $3800 in avr studio, yet still no luck? What else could I have missed? I did try the latest code.
My avr fuses I find the closest match are

0xFF extended
0xD8 High
0xDF low
Last edited by ulao on Tue Aug 31, 2010 11:41 pm, edited 2 times in total.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: Atmega8535 OK / Atmega328p FAIL

Post by christian » Tue Aug 31, 2010 11:40 pm

No. Half of 7800 is 3C00. And you should choose a boot section size of 1024 words (= 2048 bytes).

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: Atmega8535 OK / Atmega328p FAIL

Post by ulao » Tue Aug 31, 2010 11:42 pm

but how can you do that if they are on the same line? In avr studio I only get the 4 options.

Boot Flash size=256 words start address=$3F00
Boot Flash size=512 words start address=$3E00
Boot Flash size=1024 words start address=$3C00
Boot Flash size=2048 words start address=$3800

Will I need to use an mFile and will the defines override the gui?

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: Atmega8535 OK / Atmega328p FAIL

Post by christian » Tue Aug 31, 2010 11:48 pm

You want

Boot Flash size=1024 words start address=$3C00

That's 2048 BYTES of boot flash size starting at the correct position.

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: Atmega8535 OK / Atmega328p FAIL

Post by ulao » Tue Aug 31, 2010 11:53 pm

Wow, then I must be confusing myself here. I figure Boot Flash size was in bytes since it didnt have the '$' but now I see the "word" . Either way I have tried them all. What about the hint that a change should be made here

# ifndef USB_INTR_VECTOR /* default to hardware interrupt INT0 */
# ifdef INT0_vect
# define USB_INTR_VECTOR INT0_vect // this is the "new" define for the vector
# else
# define USB_INTR_VECTOR SIG_INTERRUPT0 // this is the "old" vector
# endif
# endif

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: Atmega8535 OK / Atmega328p FAIL

Post by christian » Tue Aug 31, 2010 11:57 pm

You don't need to change anything here, the code you quote already takes care of the p suffix devices.

BTW: The "$" does not mean words or bytes here, it means that the value is in hex, not in dec.

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: Atmega8535 OK / Atmega328p FAIL

Post by ulao » Wed Sep 01, 2010 12:13 am

Well, thx for all the help Christian. I certainly understand things better now ;) However I do not understand why every thing works when flash to a 168 and not a 328p.


I have the new code that handles the pico bug.
I have the right fuses FF,DA,DF. ( not 100% on the Brown-out but disabled works on 168 ( tried all other options ) )
Tried multiple chips.
Tried burning as if it were a 168 ( dont agree with that but didnt help )
BootRst is check ( at least this is needed for 168 )
Set MCU to 328p in project settings.
Didn't read any changes needed in the Bootloader code.

I continue to get usb device not recognized on this chip. Any more ideas?

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: Atmega8535 OK / Atmega328p FAIL

Post by christian » Wed Sep 01, 2010 12:17 am

You can first try to load it as normal application at address 0 instead of the boot area. Don't know which boot loader you use, but USBaspLoader has an optional define "NO_FLASH_WRITE". If you set it, it's compiled as normal application which can be loaded at address 0.

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: Atmega8535 OK / Atmega328p FAIL

Post by ulao » Wed Sep 01, 2010 12:21 am

Sorry I'm using BootloadHID. I can use any v-usb example on the 328p just fine, only the bootloader gives me troubles. I didnt see NO_FLASH_WRITE in there.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: Atmega8535 OK / Atmega328p FAIL

Post by christian » Wed Sep 01, 2010 11:58 am

The define in bootloadHID is "TEST_MODE". Did you check the over-all code size? It might exceed the 2k of the boot area.

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: Atmega8535 OK / Atmega328p FAIL

Post by ulao » Wed Sep 01, 2010 4:13 pm

2k as in Program and data together?

Code: Select all

AVR Memory Usage
----------------
Device: atmega328p

Program:    1946 bytes (5.9% Full)
(.text + .data + .bootloader)

Data:         59 bytes (2.9% Full)
(.data + .bss + .noinit)
I removed all debug code to shrink it down a bit.

I did not see a define for TEST_MODE, but I do see the #if for it, so I set TEST_MODE 1 and tried to flash without the bootrst fuse bit. This did not seem to help, does this imply its related to code, since all other apps seem to flash correctly?

Post Reply