ATmegaa32U4 USB with internal RC clock - Page 1
Forum section: electronics / general

author: pburger
author_rank: Contributor
timestamp: November 04, 2014, 04:54:48 pm
content: Does anyone have any experience using USB on the ATmega32U4 configured with the internal 8MHz oscillator clock source?I am unable to communicate with the ATmega32U4 via USB.My computer (Mac with OS X) does indicate that my board is connected.I am using an Arduino Uno as a programmer via the ISP interface.I can successfully burn a boot loader into the chip whilst setting the fuses as required.My board seems to operate ok and simple test code can be uploaded to it (via the Arduino ISP) and it works as expected.If the chip is programmed with the fuses set to output the clock on Port C pin 7, then a waveform extremely close to 8MHz is seen.I have tried setting the LSM bit in UDCON to force low speed USB and this is reported as 1.5MHz by the Computer.If I try and upload code via the USB connection then the programming fails saying it can't find the device on the port.Do I have to use a special/modified boot loader to use the internal RC?Is there anything specific that I have to do in order to get the USB working?Is there something really basic that I have missed?Any other suggestions most welcome.Many thanks in advance...

author: bobcat
author_rank: Regular Contributor
timestamp: November 04, 2014, 07:24:54 pm
content: I believe the Atmel USB micros use a 12MHz clock for USB.You should use a crystal or accurate resonator.Did you burn the Arduino bootloader?Is the Arduino system compatible with ATMega8?

author: pburger
author_rank: Contributor
timestamp: November 04, 2014, 07:41:47 pm
content: Thanks for your reply... however, 8MHz is correctalso, from data sheet....21.4 Crystal-less operationTo reduce external components count and BOM cost, the USB module can be configured to operate in low-speed mode with internal RC oscillator as input source clock for the PLL. The internal RC oscillator is factory calibrated to satisfy the USB low speed frequency accuracy within the 0°C and +40°C temperature range.For USB full-speed operation only external crystal oscillator or external source clock can be used.Yes it was the Arduino boot loader for the Arduino Micro.Sorry - my mistype - its not Mega8... its Mega32U4.... Corrected now!

author: jeremy
author_rank: Super Contributor
timestamp: November 04, 2014, 08:13:26 pm
content: What fuses do you set when you burn the boot loader? Can you plug it into a linux computer and run dmesg to see any usb detection messages?Why do you need to burn a boot loader when there is already one there?

author: pburger
author_rank: Contributor
timestamp: November 05, 2014, 01:55:56 am
content: Low Fuse = F2 (or C2 to output clock on PorT C,Pin 7)High Fuse = D8Ext Fuse = CBThe chips don't have a boot loader when new (well not one that I can use with an Arduino as ISP programmer as far as I can tell)

author: Psi
author_rank: Super Contributor
timestamp: November 05, 2014, 02:18:57 am
content: This is usually when the OP posts a pic of a messy breadboard with wires everywhere and horrible grounding and we all go Ah ha!Hehe

author: pburger
author_rank: Contributor
timestamp: November 05, 2014, 11:21:30 am
content: Its only a prototype.... will this do?

author: jeremy
author_rank: Super Contributor
timestamp: November 05, 2014, 12:06:36 pm
content: Quote from: pburger on November 05, 2014, 01:55:56 amIf you have the ATMEGA32U4 and not the ATMEGA32U4RC, then I 150% guarantee they come with a usb bootloader from the factory. I have built production devices that rely on thatLook up AVR FLIP on google. But if you have ISP programmed the device, then you have already wiped it as it is stored at the start of flash. You can get the hex file from somewhere on Atmel's website if you want to put it back.You have also disabled the AVR FLIP bootloader from being activated in the fuse settings, see the HWBE fuse bit.According tohttp://www.engbedded.com/fusecalc/your fuses are incorrect. Try: LOW=E2, HIGH=D8, EXT=FB. According to that calculator, you currently have it set to external clock.hope this helpsEdit: It just occurred to me that either the arduino bootloader or the FLIP bootloader may try to work in full speed mode, in which case you are out of luck.

author: pburger
author_rank: Contributor
timestamp: November 05, 2014, 12:59:25 pm
content: Thanks for your reply Jeremy.Like an idiot, I mistakenly ordered the non-RC chipsUnfortunately I'm using a Mac and the Flip and AVR studio run on PCs :-(I'm checking the fuses suggestion you gave... Not sure what makes it think external clock s in use though.Re your last edit, this thought had occurred to me, hence my thoughts that a specific/special boot loader hex file may be required?

author: jeremy
author_rank: Super Contributor
timestamp: November 05, 2014, 01:04:04 pm
content: Hi pburger,I'm a mac user too. You can program with them via dfu-programmer. Works on linux as well.It's easy to install with homebrew: brew install dfu-programmerthen just add this at the top of your makefile:Code:MCU = atmega32u4TARGET = thingieand at the bottomCode:flash:dfu-programmer $(MCU) erasedfu-programmer $(MCU) flash $(TARGET).hexdfu-programmer $(MCU) resetand then 'make flash' will automatically find, program and reset your device. Just make sure there is only one plugged in.

author: jeremy
author_rank: Super Contributor
timestamp: November 05, 2014, 01:06:22 pm
content: Quote from: pburger on November 05, 2014, 12:59:25 pmThe non-RC ones are the ones with the bootloader preinstalled. Sorry if this wasn't clear.

author: pburger
author_rank: Contributor
timestamp: November 05, 2014, 01:31:37 pm
content: Thanks again Jeremy... I'll let you know how I get on.Re preinstalled boot loader: I've re-read what you wrote and it is perfectly clear... I got it wrong!

author: pburger
author_rank: Contributor
timestamp: November 06, 2014, 11:35:22 am
content: QuoteI have tried this and....1stly: programming the ext fuse to FB fails.... read back gives CB (the original value I used) so looks like the4 bits may not be changeable?2ndly: Writing FB or CB to the Ext fuse disables the HWBE since 0 is the programmed state.... I tried clearing that bit (sending C3) but not help.3rdly: Lo fuse E2 only changes the start up delay... the 2 nibble is the same as I was using and indeed selects internal clock.Trying to get the DFU-Programer working... can't see any reference to setting the fuses though??

author: jeremy
author_rank: Super Contributor
timestamp: November 06, 2014, 12:33:37 pm
content: Well I am unsure about for the internal clock, but for external 8MHz crystal I have used this exact command to burn the atmel bootloader to a ton of 32U4RC chips and they all worked:Code:avrdude -p m32u4 -c avrispmkii -U flash:w:ATMega32U4-usbdevice_dfu-1_0_0.hex -U lfuse:w:0x5e:m -U hfuse:w:0x99:m -U efuse:w:0xc3:mPerhaps you could try this?

author: pburger
author_rank: Contributor
timestamp: November 06, 2014, 01:31:22 pm
content: I'll try... although looking at the data sheet this will work for 8MHz external divided by 8 for 1MHz operation so does your USB then still work?

author: jeremy
author_rank: Super Contributor
timestamp: November 06, 2014, 02:07:04 pm
content: It definitely does for me. I pulled this command out of a production script. IIRC I based it on directly reading the fuses from a brand new part.

author: pburger
author_rank: Contributor
timestamp: November 06, 2014, 05:28:50 pm
content: Nope - Board is uploadable via ISP and works but no USB... but then my Leonardo board has a 16MHz crystal so the divide my 8 gives 2MHz and the USB requires an 8MHz source.

author: jeremy
author_rank: Super Contributor
timestamp: November 07, 2014, 08:45:31 am
content: Is there any way you could swap out the 16 for an 8? I don't think Atmel provides the source for their bootloader. I suppose you could try to modify Caterina though.

author: pburger
author_rank: Contributor
timestamp: November 07, 2014, 10:52:29 am
content: Thanks for your continued thoughts, Jeremy.I see what you're saying.... Effectively duplicating the setup you have used previously... however, I want to use ONLY the internal RC oscillator and have no external clock components at all - and use USB for uploading code.I am looking into the possibility of modifying Caterina... I think I can see what has to be done, its just I'm not a hardcore programmer and am not sure how to set up and compile/build from the source code. There is a 'make' file supplied with the Arduino app software, but I think this is for windows machines not a Mac

author: jeremy
author_rank: Super Contributor
timestamp: November 07, 2014, 12:18:19 pm
content: I'll take a look. Hang tight

author: jeremy
author_rank: Super Contributor
timestamp: November 07, 2014, 12:40:41 pm
content: 8MHz version. Compiled on a macCompletely untested as I am overseas. See if it works!Edit: by the way, I'm pretty sure that these bootloaders disable the effect of the clkdiv8 fuse at runtime. So if you use a 8MHz clock, the bootloader should run at that speed. From caterina:Code:clock_prescale_set(clock_div_1);

author: pburger
author_rank: Contributor
timestamp: November 07, 2014, 10:30:45 pm
content: Jeremy, you are a starI can't thank you enough.The file you have created works perfectly on both my standard Leonardo board, and my custom PCB which has no external crystal.(FWIW, I did try enabling the CKDIV8 fuse, but the USB was not recognised by my computer. Also enabling CKOUT to check gave a 1MHz signal)As a matter of interest, what did you change in the source/make files to create this?

author: jeremy
author_rank: Super Contributor
timestamp: November 07, 2014, 10:52:42 pm
content: No worries mate, I know what it is like to play usb boot loader games on these chips and it can be frustrating at timesI just changed F_CPU in the makefile to 8000000 and configured the PID/VID, as well as checking that the code did not rely on any fuses related to the clocks.You can get all of the build tools you need from homebrew and Xcode. I think it's just install Xcode, brew install avr-gcc and you're good to go!

author: pburger
author_rank: Contributor
timestamp: November 07, 2014, 11:13:46 pm
content: Well, thanks again, it was very kind of you to take the troubleI'll take a look at the brew install ave-gcc and see if I can recreate it incase there is a next time

author: elysion
author_rank: Newbie
timestamp: August 26, 2017, 08:36:24 pm
content: I am trying to achieve the exact same thing as the OP, but even with the provided bootloader, am unable to get the board show up as a USB device. Burning the bootloader using Arduino IDE works and after the process has completed, the LED_BUILTIN starts to blink, which afaik should indicate that the bootloader is running. Any ideas what might be the issue? Any tips on how to debug this?Here is the entry from boards.txt I'm using:micro_int.name=Standalone Micromicro_int.vid.0=0x03ebmicro_int.pid.0=0x204amicro_int.upload.tool=avrdudemicro_int.upload.protocol=avr109micro_int.upload.maximum_size=28672micro_int.upload.maximum_data_size=2560micro_int.upload.speed=57600micro_int.upload.disable_flushing=truemicro_int.upload.use_1200bps_touch=truemicro_int.upload.wait_for_upload_port=truemicro_int.bootloader.tool=avrdudemicro_int.bootloader.low_fuses=0xe2micro_int.bootloader.high_fuses=0xd8micro_int.bootloader.extended_fuses=0xfbmicro_int.bootloader.file=caterina-internal/Caterina-eevblog2.hexmicro_int.bootloader.unlock_bits=0x3Fmicro_int.bootloader.lock_bits=0x2Fmicro_int.build.mcu=atmega32u4micro_int.build.f_cpu=8000000Lmicro_int.build.vid=0x03ebmicro_int.build.pid=0x204amicro_int.build.usb_product="Standalone Micro"micro_int.build.board=AVR_LILYPAD_USBmicro_int.build.core=arduinomicro_int.build.variant=leonardomicro_int.build.extra_flags={build.usb_flags}

author: branjb
author_rank: Contributor
timestamp: August 28, 2017, 03:12:45 am
content: Quote from: elysion on August 26, 2017, 08:36:24 pmI made a board with a 32u4 using USB in crystal less mode. There documentation is @https://github.com/lostangles/LoraWAN-Stick, maybe something there can help you.

author: elysion
author_rank: Newbie
timestamp: September 10, 2017, 07:14:57 pm
content: Thanks! I'll take a look.

author: Harmony
author_rank: Newbie
timestamp: June 22, 2018, 07:07:51 am
content: How could I use the "Caterina.hex" file?