Fundino Pro Mini Blinken nach flashen

#5301012
Lesenswert?

Hallo Leute,

ich bin das erste mal dabei einen MCU direkt zu programmieren. Stellt 
sich heraus, dass es schwieriger ist als einfach einen Arduino mit 
seriellen Port anzuschliessen :)

Nun habe ich folgendes gemacht:

1. Ich habe mir einen USBASP besorgt und diesen mit dem Board verbunden.

2. Ein kleines C Programm geschrieben und CMakeLists.txt mit folgendem 
Inhalt erstellt:
SET(MCU "atmega328p")
SET(F_CPU "16000000")
SET(CMAKE_SYSTEM_NAME Generic)
# For some reason, these paths have to be absolute, otherwise
# CLion won't be able to find headers etc.
SET(CMAKE_C_COMPILER /usr/bin/avr-gcc)
SET(CMAKE_CXX_COMPILER /usr/bin/avr-g++)

SET(CMAKE_C_FLAGS "-mmcu=${MCU} -DF_CPU=${F_CPU} -Os")
SET(CMAKE_C_LINK_FLAGS "-mmcu=${MCU}")

SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

3. Ein main.c erstellt mit folgendem Inhalt:
#ifndef F_CPU
#define F_CPU 1000000UL // or whatever may be your frequency
#endif

#include <avr/io.h>
#include <util/delay.h>                // for _delay_ms()

int main(void)
{
    DDRD = 0b00000100;                       // initialize port D
    while(1)
    {
        // LED on
        PORTD = 0b00000100;            // PD2 = High = Vcc
        _delay_ms(500);                // wait 500 milliseconds

        //LED off
        PORTD = 0b00000000;            // PD2 = Low = 0v
        _delay_ms(500);                // wait 500 milliseconds
    }
}

4. Den Code habe ich nun compiled und geflasht mit folgendem Aufruf 
unter Linux:
avr-gcc -g -Os -mmcu=atmega328p -c main.c && \
avr-gcc -g -mmcu=atmega328p -o main.elf main.o && \
avr-objcopy -j .text -j .data -O ihex main.elf main.hex && \
avrdude -c usbasp -p m328p -U flash:r:main.hex:i

Der Output ist folgender:
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 
0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading flash memory:

Reading | ################################################## | 100% 
12.43s

avrdude: writing output file "main.hex"

avrdude: safemode: Fuses OK (E:FD, H:DA, L:FF)

avrdude done.  Thank you.

Sieht soweit erst einmal korrekt aus. Ich habe allerdings das Problem, 
dass meine angeschlossene LED nicht leuchtet. Die LED ist mit Widerstand 
am PIN D2 angeschlossen. https://i.stack.imgur.com/oOtkU.png

Es leuchtet allerdings die USBASP LED abwechselnd mit der Board LED. 
Siehe Video: 
https://www.youtube.com/watch?v=oIcGt6VgNnw&feature=youtu.be

Nun wuerde ich gerne wissen, woran das liegt. Ist das ein Fehlercode? 
Fehlt noch ein Bootloader?
#5301672
Lesenswert?

Jim M. schrieb:
> Philipp B. schrieb:
>> avrdude: safemode: Fuses OK (E:FD, H:DA, L:FF)
>
> Fusecalc sagt: Bootloader Fuse aktiv. Ich vermute Du hast vergessen dass
> dann auch ein Bootloader geflasht sein muss.
>
> Also entweder einen Bootloader flashen oder die High Fuse auf "DB"
> setzen. Letzteres schaltet den Bootloader aus - den braucht man für ISP
> via USBASP nicht.

Okay, dann schalte ich den mal ab und schaue ob es dann laueft. :) Danke 
dir.
#5301920
Lesenswert?

Jim M. schrieb:
> Philipp B. schrieb:
>> avrdude: safemode: Fuses OK (E:FD, H:DA, L:FF)
>
> Fusecalc sagt: Bootloader Fuse aktiv. Ich vermute Du hast vergessen dass
> dann auch ein Bootloader geflasht sein muss.
>
> Also entweder einen Bootloader flashen oder die High Fuse auf "DB"
> setzen. Letzteres schaltet den Bootloader aus - den braucht man für ISP
> via USBASP nicht.

Ich habe jetzt die Fuse wie folgt gesetzt:

avrdude -u -c usbasp -p m328p -U lfuse:w:0xDF:m -U hfuse:w:0xDB:m -U 
efuse:w:0xFB:m

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 
0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "0xDF"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 
0.00s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xDF:
avrdude: load data lfuse data from input file 0xDF:
avrdude: input file 0xDF contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 
0.00s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude: reading input file "0xDB"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 
0.00s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xDB:
avrdude: load data hfuse data from input file 0xDB:
avrdude: input file 0xDB contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 
0.00s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xFB"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 
0.00s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xFB:
avrdude: load data efuse data from input file 0xFB:
avrdude: input file 0xFB contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 
0.00s

avrdude: verifying ...
avrdude: 1 bytes of efuse verified

avrdude done.  Thank you.

High Fuse auf DB, wie du geschrieben hattest.

Nun flashe das Hex und bekomme folgendes:
avr-gcc -g -Os -mmcu=atmega328p -c main.c && avr-gcc -g -mmcu=atmega328p 
-o main.elf main.o && avr-objcopy -j .text -j .data -O ihex main.elf 
main.hex && avrdude -c usbasp -p m328p -U flash:r:main.hex:i

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 
0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading flash memory:

Reading | ################################################## | 100% 
11.89s

avrdude: writing output file "main.hex"

avrdude: safemode: Fuses OK (E:FB, H:DB, L:DF)

avrdude done.  Thank you.

High Fuse ist also auf DB gesetzt. Allerdings leuchtet die LED immer 
noch nicht und das Abwechselnde Blinken wie auf dem Video ist immer noch 
da. Habe ich einen anderen Fuse falsch gesetzt?

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren