Go Down

Topic: Burn bootloader for new chip by Arduino software and USBAsp (Read 5504 times) previous topic - next topic

chenlawrence

Hello all, here is the issue. I have new board with 328p microcontroller and nothing but 6 pins ISP connetor on the PCB.
1. first time connect to some USBAsp software read the signature bytes......OK!
2. then, put other components onto the PCB include the FTDI usb -> serial convertor;
3. connect to the Arduino software and do follow the instruction to burn the bootloader, show the
    Double check connections and try again, or use -F to override this check.
4. after that I use USBAsp software to read the signature bytes again, the chip will not respose any more.
I have tried many times to find this problem, firstly thinking is the Arduino software have done something to the chip, but I don't know what it has done.
Could anybody support on this trouble?
Thanks.

johnwasser

If you burn an Arduino bootloader you will need an 8MHz or 16MHz crystal or ceramic resonator to provide a system clock in order to do any more serial (ISP) programming.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

nickgammon

If you have a spare (working) Uno lying around, upload this sketch to it:

Code: [Select]
void setup ()
  {
  // set up 8 MHz timer on pin 9
  pinMode (9, OUTPUT);
  // set up Timer 1
  TCCR1A = _BV (COM1A0);  // toggle OC1A on Compare Match
  TCCR1B = _BV(WGM12) | _BV(CS10);   // CTC, no prescaling
  OCR1A =  0;       // output every cycle
  }
 
void loop () {}


That will output 8 MHz to pin 9. Connect that to Xtal1 (pin 9 on the chip) of your Atmega328, that will give you a clock. Then you can reprogram the fuse to run from the internal clock. Or, do what johnwasser said, and provide a crystal or resonator.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

spycatcher2k

Hi Nick - Do you have an equivalent sketch for the attiny 45/85 ? Only needs to be 1MHz Minimum - or as fast as possible.
This direct port stuff gives me nightmares ;-)
Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

chenlawrence

Thank you for your suggestion! I do have the 16MHz clock on board. I have all necessary component that he datasheet required for serial programming. Even though, the read signature could work without any clock. Because SCK is clock, just as JTAG programming.
Do you know what commands have sent to the chip when try to burn the bootloader by this Ardunio? You have mentioned the fuse. The process should be more safe to avoid this kind of problem by move the fuse operation to good place than at the beginning. 
Another question is why the Ardunio need both ISP connection and USB2Serial connection at same time? If we use the ISP then every byte of memory could programmed by this program. If we use serial port to use as programming port, we can use the UART programming port. Why here need both?

By the way, I post the develop environment here.
Dell laptop> USBAsp software/ Ardunio/ AVR stuido v4-> usb cable -> USBAsp/ MkII -> ISP connect on PCB-> 328p isp port(VCC/SCK/GND/SDI/SDO/RST)
                                                                                          -> FTDI USB2serial chip -> 328p uart port(RX/TX)
Thanks.

johnwasser

>  Even though, the read signature could work without any clock. Because SCK is clock, just as JTAG programming.

Sadly the ATmega uses the system clock to sample the SPI clock so without a system clock you can't do serial (SPI) programming.

> Do you know what commands have sent to the chip when try to burn the bootloader by this Ardunio? You have mentioned
> the fuse. The process should be more safe to avoid this kind of problem by move the fuse operation to good place than at the
> beginning.

The boards.txt file tells Arduino how to configure the fuses which set the system clock configuration.  If you have the hardware that matches the boards.txt entry you have chosen then everything should work.
 
> Another question is why the Ardunio need both ISP connection and USB2Serial connection at same time?

The USB-to-Serial hardware is used by the bootloader.  It's handy because more people have serial ports than have ICSP programmers.  The ICSP header is there so you can re-write the bootloader if necessary.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

nickgammon


Hi Nick - Do you have an equivalent sketch for the attiny 45/85 ? Only needs to be 1MHz Minimum - or as fast as possible.
This direct port stuff gives me nightmares ;-)


Here:

Code: [Select]
// For ATtiny85

void setup ()
  {
  // set up 4 MHz timer on pin 3 (D4)
  pinMode (4, OUTPUT);
  // set up Timer 1
  TCCR1 = _BV (CTC1) | _BV(CS10);  // CTC mode, no prescaler
  GTCCR = _BV (COM1B0);    // toggle OC1B on Compare Match
  TCNT1 = 0;  // set back to start
  OCR1C = 0;  // what to compare to for CTC mode
  }
 
void loop () {}


On my 8 MHz ATtiny85 that output 4 MHz on pin 3. Increase OCR1C to get a slower speed.

I could only get that to compile under v0022 of the IDE. Maybe my Attiny files are out of date.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

nickgammon


Do you know what commands have sent to the chip when try to burn the bootloader by this Ardunio?


This sketch will program a bootloader:

http://www.gammon.com.au/forum/?id=11635

Quote
If we use the ISP then every byte of memory could programmed by this program.


In that case you don't need a bootloader.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

chenlawrence

Now I got confused... But still thanks a lot for your fast response!
The board which need program is not buy as Ardunio hardware from web shop. The IC, I think is totally blank, just come from the supplier. I have no other Ardunio board to support the programming, but USBAsp and MK II from Atmel tool.  So under these conditions, if I want the Ardunio bootload into that IC. What shall I do?

Issue now is at first time USBAsp software(not Ardunio ) could read the signature when have not connected to Ardunio software. But after try to download the bootload which is not successful, the USBAsp software can't read the signature. Can I bring them back? It seems the procedure is OK according information from website. http://www.gammon.com.au/forum/?id=11635 The fuse is written at finial stage.

Erasing chip ...
Writing bootloader ...
Committing page starting at 0x7E00
Committing page starting at 0x7E80
Committing page starting at 0x7F00
Committing page starting at 0x7F80
Written.
Verifying ...
No errors found.
Writing fuses ...
LFuse = 0xFF
HFuse = 0xDE
EFuse = 0xFD
Lock byte = 0xCF
Done.
Type 'C' when ready to continue with another chip ...

nickgammon

In my case I wrote the fuses last. From page 298 of the datasheet:

Quote
The fuse values are latched when the device enters programming mode and changes of the fuse values will have no effect until the part leaves Programming mode.


In other words, the order won't matter.

Quote
If we use the ISP then every byte of memory could programmed by this program. If we use serial port to use as programming port, we can use the UART programming port. Why here need both?


Do you want to use the bootloader or not? If you have an ICSP programmer than uploading a bootloader is not necessary. You can configure the IDE to simply upload sketches using the USBAsp or the AVRISP Mk II.

Do you, or do you not, have a crystal or resonator attached to the processor clock pins? Can you take a clear photo please?
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

spycatcher2k

Hi Nick - Many Thanks - Works fine here on IDE 1.0 (Using the attached Tiny Core)

Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

nickgammon

Thanks, that fixed it. I got kinda confused here. I have so much rubbish in my hardware folder. ;)
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

chenlawrence

OK, I go through all the thing again. It was the problem from clock. I have one SMD ceramic resonator, which could not assembly right. I checked the clock source to 8MHz by external crystal. Then it is OK. I also do the test that remove the USB2Serial chip. I think the reason need the USB cable to connect the board mainly to provide the 5v power. The ISP would be do the main programming when upload the bootload. And I do check the first operation from Arduino software to the IC, it is $AC $53 $00 $00, which means Programming Enable. And it will retry many times.
Thank you all! The problem is solved. 

Go Up