NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Getting started with 328P mcu (makefile setting using winavr)

August 07, 2010
by kle8309
kle8309's Avatar

Hey guys, I just bought a blank 328P and uploaded the NK 328P foodloader using avrisp stk500 but im not sure what to change in the makefile when trying to make a simple blinking led using the NK usb cable and WinAVR

Note: I did tried on the atmega168 with the appropriate settings and it worked. Just this one doesn't.

here is the makefile

GCCFLAGS=-g -Os -Wall -mmcu=atmega328p
LINKFLAGS=-Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt -lm
AVRDUDEFLAGS=-c avr109 -p m328p -b 115200 -P COM10
LINKOBJECTS=../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o

all:    led_blink-upload

led_blink.hex:  led_blink.c
    make -C ../libnerdkits
    avr-gcc ${GCCFLAGS} ${LINKFLAGS} -o led_blink.o led_blink.c ${LINKOBJECTS}
    avr-objcopy -j .text -O ihex led_blink.o led_blink.hex

led_blink.ass:  led_blink.hex
    avr-objdump -S -d led_blink.o > led_blink.ass

led_blink-upload:   led_blink.hex
    avrdude ${AVRDUDEFLAGS} -U flash:w:led_blink.hex:a

OUTPUT from WinAVR

> "make.exe" all
make -C ../libnerdkits
make[1]: Entering directory `C:/Users/Kelvin/Desktop/Code (1)/Code/libnerdkits'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `C:/Users/Kelvin/Desktop/Code (1)/Code/libnerdkits'
avr-gcc -g -Os -Wall -mmcu=atmega328p -Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt -lm -o led_blink.o led_blink.c ../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o
avr-objcopy -j .text -O ihex led_blink.o led_blink.hex
avrdude -c avr109 -p m328p -b 115200 -P COM10 -U flash:w:led_blink.hex:a

Connecting to programmer: .
Found programmer: Id = "FDL v02"; type = S
    Software Version = 0.2; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:
    Device code: 0x35

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e950f
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "led_blink.hex"
avrdude: input file led_blink.hex auto detected as Intel Hex
avrdude: writing flash (7670 bytes):

Writing | ################################################## | 100% 0.78s

avrdude: 7670 bytes of flash written
avrdude: verifying flash memory against led_blink.hex:
avrdude: load data flash data from input file led_blink.hex:
avrdude: input file led_blink.hex auto detected as Intel Hex
avrdude: input file led_blink.hex contains 7670 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.78s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0x0c != 0xff
avrdude: verification error; content mismatch

avrdude done.  Thank you.

make.exe: *** [led_blink-upload] Error 1

> Process Exit Code: 2
> Time Taken: 00:04
August 07, 2010
by kle8309
kle8309's Avatar

Also, COM10 worked for atmega168 so lets assume that is out of the question

August 07, 2010
by Rick_S
Rick_S's Avatar

I really don't see anything glaring wrong with what you did there.

It appeared to compile fine, erase the chip, write the chip, then the chip doesn't verify.

Did you set the fuses according to fuses_mike.txt in the bootloader328P folder?

Another thing, I've had problems on occasion with the 168 object files left in the libnerdkits folder not being re-compiled for the 368. To ensure they do, delete the *.o files in the libnerdkits folder before compiling for the 368 for the 1st time.

Rick

August 07, 2010
by kle8309
kle8309's Avatar

rick, about the fuses. I did tried to follow the fuses_mike.txt but was unable to set them in avr studio. All the high, low, and extended are the same but the lock bit is not. I used 0xef instead for lock bit. Funny thing because when I 'read' a NK atmega168 chip w/ bootloader, the lock bits read was 0xef. That's how i got the idea of using 0xef for lockbits.
Do you use avr studio or ponypong to program the ps. I did try to delete the .o and .hex before and nothing changed.

August 07, 2010
by Rick_S
Rick_S's Avatar

Actually, I use AVRDude to program the fuse settings. On occasion I've used BASCOM-AVR (a basic compiler for AVR's) to set them. I do know once certain lock bits are set, a chip erase is all that will allow them to be changed. I ran into this when I purchased some 328's with the arduino bootloader. The only way to set the fuses and lock bits according to Mike's settings, I had to do a chip erase 1st.

Also, the fuse settings for teh 328 are not the same as the 168

Rick

August 07, 2010
by kle8309
kle8309's Avatar

ha ha yes I forgot about that. I thought of that when I was on the way home. Thanks I will try the new 328p settings

August 07, 2010
by kle8309
kle8309's Avatar

Update, I got the 328P to work! the main reasons are the high and low fuse settings. Here is mike's: E: 0x05 H: 0xd2 L: 0xf7 LB: 0x2f Here is the best I could do with avr studio (it won't set otherwise): E: 0xf8 H: 0xd2 L: 0xf7 LB:0xef

settings not according to mike's setting were chosen based on actual read from an atmega168 via avr studio.

ps. Rick, is it safe to have both the NK usb cable and avrisp hooked up at the same time.

Post a Reply

Please log in to post a reply.

Did you know that using an alternating excitation voltage can reduce the noise in many sensor measurements? Learn more...