This is a method I have tested that will allow you to re-program Atmel ATtiny MCUs successfully over and over. My example is based on an Attiny13A. My development system is as follows:
Mikroelektronika EasyAVRv7
MikroBasic Pro for AVR v6.0.0
AVRFlash utility v2.14
Make sure these switches are ON..SW10-6, SW3-6, SW3-7, SW3-8. All others OFF.
The jumper just to the left of DIP8 should be on RS.
The External Clock jumper (just below DIP8) should be on PB3
Project Settings in mikroBasic : Attiny13A, 8.000MHz
Here's the short answer that has ONLY been tested on the above configuration...
ALWAYS turn off power to the Development Board (EasyAVR7) before starting AVRFlash Utility. (ie, before clicking on Build and Program). Turn power on after AVRFlash starts. That's it in a nutshell. Failure to turn off power will, most likely, brick the chip!
<<< Software developers at mikroElektronika, please see questions/suggestions at end >>>
-------------------------------------------------------------------------------------------------
If you're interested, here's the long version. This method should work with Basic, C or Pascal compilers since the problems you may have been experiencing are NOT due to the compilers The problem lies in the AVRFlash utility.
1. Start a new project and write a simple program (or modify one of the example programs provided by mikroElektronika like I did) for your Attiny chip. The following program will strobe the the 6 ports of the Attiny13A and will illuminate the PORTB LEDs. (well, really it will only illuminate 5 LEDs, but I'll explain how to turn on PORTB-5 in another thread)
Code: Select all
program Attiny13A_LED_chaser_shift_register
' This a stripped down version of the program “LED_Curtain”
'courtesy and copyright of mikroElektronika , 2013
' Declarations section
dim counter as byte
sub procedure Wait()
Delay_ms(400)
end sub
main:
DDRB = 0xFF ' set PORTB direction to be output
PORTB = 0x00 ' turn OFF the PORTB leds
while TRUE
for counter = 0 to 5
PORTB = PORTB or 1 << counter
Wait()
next counter
counter = 0
while (counter < 6)
PORTB = PORTB and not(1 << counter)
wait()
Inc(counter)
wend
wend
end.
2. Make sure your EasyAVR board is turned OFF. This is VERY IMPORTANT.
3. Build & Program (CTRL-F11) the Hex file. The program should compile without errors and the AVRFlash utility should start.
4. Change the clock source settings in AVRFlash to “Cal. Internal RC Oscillator-9.6MHz”.
5. Leave all other settings at their default setting.
6. Now, turn ON the EasyAVR board.
7. Using the AVRFlash utility, WRITE (F11) the HEX file to the Attiny13A.
8. You're done. Chip should be programmed, LEDs will be flashing. Try changing the numeric value of Wait(). Repeat the above steps to re-program the chip, remembering to TURN OFF the EasyAVR board BEFORE starting AVRFlash ( before clicking on Build & Program)
The reason this method works is twofold...
First, if your EasyAVR board is powered up when you Build & Program (IE. Start the AVRFlash utility), the flash utility will automatically try to program the chip using the default clock setting ”External Clock”. From my experience a brand new chip can tolerate this setting. You can clear the “can not synchronize...” error message, change the clock to Internal Oscillator and successfully write to the chip. But if you're trying to re-program a chip and the utility is set to “External Clock” you'll brick the chip.
Second, the AVRFlash utility does not remember settings from the last time you programmed a chip. It always reloads it's default values.
So, 2 questions/suggestions to the software developers at mikroElektronika...
1. Can you give us way to start the AVR Flash utility without it automatically trying to program the chip? Maybe “Build & Start”?
2. Can you give us the option to either use default settings or use “previously used” settings for all the clock, fuse and Lock Bit settings? Or perhaps you can create a “Clock Source” dialog box in the Project Settings and just import that data into AVRFlash like you currently do with the Device Name and Clock Frequency.