Hallo Forum,
ich habe ein Problem mit einem Atmega32U2 (Breakout Board von ehajo, 16MHz-Quartz, Flip als Bootloader). Ich hatte ihn bereits mit BascomAVR programmiert möchte aber auf AVR Studio 4 umsteigen. Die Anleitung hab ich von Stefan Frings.
Das einfache Blink-Programm läuft auf dem µC, aber die erwarteten Zeiten stimmen nicht, anstatt 8s braucht die Hauptschleife 8x solange. Das Timing ist mir sehr wichtig, denn ich will später noch einen virtuellen Com-Port auf dem Chip betreiben.
Im AVR-Studio hab ich 16MHz und Atmega32U2 eingestellt.
Hier der Code:
Und die Compiler-Ausgabe:Code:#include <avr/io.h> #include <stdint.h> // #define F_CPU 2000000UL // <- damit komm ich auf die 8s #include <util/delay.h> int main(){ CLKSEL0 |= (1 << EXTE); // CKSEL0.EXTE = 1; // Enable_external_clock(); while ( (CLKSTA & (1 << EXTON)) == 0 ){} // while (CLKSTA.EXTON != 1); // while (!External_clock_ready()); CLKSEL0 |= (1 << CLKS); // CLKSEL0.CLKS = 1; // Select_external_clock(); CLKPR = 0b10000000; // Unterschiedliche Einstellungen des Prescalers wirken sich nicht aus. uint8_t aPLLCSR = PLLE; aPLLCSR |= PLLP0; // Damit sollten die 16MHz halbiert werden- PLLCSR |= aPLLCSR; // PLLCSR.PLLE = 1; // Enable_pll(); CLKSEL0 &= ~(1 << RCE); // CLKSEL0.RCE = 0; // Disable_RC_clock(); while ( (PLLCSR & (1 << PLOCK)) == 0){} // while (PLLCSR.PLOCK != 1); // while (!Pll_ready()); USBCON &= ~(1 << FRZCLK); // USBCON.FRZCLK = 0; // Usb_unfreeze_clock(); DDRB=1; while(1) { for (uint8_t i=0; i<5; i++){ // 5x1s -> 5s PORTB=0; _delay_ms(500); PORTB=1; _delay_ms(500); } for (uint8_t i=0; i<30; i++){ // 30x 0,1s -> 3s PORTB=0; _delay_ms(50); PORTB=1; _delay_ms(50); } } // Insgesamt 8s, aber es dauert ca. 64s }
Ich würd gern wissen wie es funktioniert, aber zur Not langt mir auch ein funtionierender Code-Schnipsel.Code:rm -rf AVR_Test001.o AVR_Test001.elf dep/* AVR_Test001.hex AVR_Test001.eep AVR_Test001.lss AVR_Test001.map Build succeeded with 0 Warnings... avr-gcc -mmcu=atmega32u2 -Wall -gdwarf-2 -std=gnu99 -gstrict-dwarf -DF_CPU=16000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT AVR_Test001.o -MF dep/AVR_Test001.o.d -c ../AVR_Test001.c avr-gcc -mmcu=atmega32u2 -Wl,-Map=AVR_Test001.map AVR_Test001.o -o AVR_Test001.elf avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature AVR_Test001.elf AVR_Test001.hex avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ihex AVR_Test001.elf AVR_Test001.eep || exit 0 avr-objdump -h -S AVR_Test001.elf > AVR_Test001.lss Build succeeded with 0 Warnings...
Danke im voraus.







 
			
			 
					
					
					
						 Zitieren
Zitieren 
			

Lesezeichen