Go Down

Topic: ArduinoISP @57600 baud instead of 19200 (Read 16550 times) previous topic - next topic

qistoph

Hi,

Yesterday my extra Atmega328P arrived. Today I finally had time to play with it.

I have programmed my Arduino Duemilanove with the ArduinoISP from the Examples menu. So now I can program the new Atmega328P.

There's one thing I can get to work and searching the internet and forums isn't helping me out.
I've tried to increase the baud rate to speed up the programming. In the ArduinoISP's setup() is a Serial.begin(19200). So I thought changing this to 57600 would do the trick. It doesn't :(

When I change it to 57600 (or anything else) I keep getting errors. e.g.
Code: [Select]
D:\Development\Arduino\temp>avrdude -p m328p -c avrisp -P COM3 -b 57600 -v -u -U flash:w:RgbMatrix.cpp.hex

avrdude: Version 5.10, compiled on Jan 19 2010 at 10:45:23
        Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
        Copyright (c) 2007-2009 Joerg Wunsch

        System wide configuration file is "C:\Programs\WinAVR_20100110\bin\avrdude.conf"

        Using Port                    : COM3
        Using Programmer              : avrisp
        Overriding Baud Rate          : 57600
        AVR Part                      : ATMEGA328P
        Chip Erase delay              : 9000 us
        PAGEL                         : PD7
        BS2                           : PC2
        RESET disposition             : dedicated
        RETRY pulse                   : SCK
        serial program mode           : yes
        parallel program mode         : yes
        Timeout                       : 200
        StabDelay                     : 100
        CmdexeDelay                   : 25
        SyncLoops                     : 32
        ByteDelay                     : 0
        PollIndex                     : 3
        PollValue                     : 0x53
        Memory Detail                 :

                                 Block Poll               Page      Polled
          Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
          ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
          eeprom        65     5     4    0 no       1024    4      0  3600  3600 0xff 0xff
          flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
          lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
          hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
          efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
          lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
          calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
          signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

        Programmer Type : STK500
        Description     : Atmel AVR ISP
        Hardware Version: 2
        Firmware Version: 1.18
        Topcard         : Unknown
        Vtarget         : 0.0 V
        Varef           : 0.0 V
        Oscillator      : Off
        SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.13s

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 "RgbMatrix.cpp.hex"
avrdude: input file RgbMatrix.cpp.hex auto detected as Intel Hex
avrdude: writing flash (3436 bytes):

Writing |                                                    | 0% 0.00s
avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0x64
avrdude: stk500_cmd(): protocol error

D:\Development\Arduino\temp>


After this the target Atmega looks erased and doesn't do anything. (Switching back to 19200 baud allows me to program it again.)

How can I increase the programming speed of ArduinoISP?

Another question I'd like to be sure about:
When I write a program to the target Atmega using ArduinoISP, it overwrites the Arduino bootloader, right?

Grumpy_Mike

The programming speed is not limited by the baud rate it is determned largley by the rate the flash memory is programmed. There is nothing you can do to speed this up.

borref

#2
Jun 10, 2010, 06:23 am Last Edit: Jun 10, 2010, 07:32 am by borref Reason: 1
Quote
When I change it to 57600 (or anything else) I keep getting errors. e.g.


If you look at the source of  ArduinoISP, there is a call to a blink led function called "heartbeat":

Code: [Select]
 // light the heartbeat LED
 heartbeat();
 if (Serial.available()) {
   avrisp();
 }


If you comment out this call to heartbeat, you should be able to run ArduinoISP at 57600 baud.

The problem is that heartbeat uses delay and while blinking at high baudrates, serial input data will overflow the input buffer and loss of data occurs. Baudrate is a limiting factor and so increasing it should give you a faster overall programming speed as well.

WARNING!
Please note that when changing the baudrate to 57600 there is no protection against incidentally invoking the Arduino bootloader rather than the ISP sketch it is running.  As a consequence you may erase and reprogram your programmer (Arduino) rather then the target device.

Unless you are aware of this issue and understand how to safely disable auto-reset, I would recomend keeping speed at 19200 baud and not attempt this modification.

leppie

Quote
If you comment out this call to heartbeat, you should be able to run ArduinoISP at 57600 baud.


Interesting, gonna try it out too :)

qistoph

BenF, thanks for the very useful reply.

When I accidentally overwrite the programmer, that is within the bootloader right? So I should be able to reprogram it as usual, with just the Arduino board, over USB.

I'm still not sure when the bootloader is overwritten and when it's not. Anyone any comments on that?

leppie

Quote
As a consequence you may erase and reprogram your programmer (Arduino) rather then the target device.


Please explain how that is possible.  

How would it program when the programmer is not available?

borref

Quote
When I accidentally overwrite the programmer, that is within the bootloader right? So I should be able to reprogram it as usual, with just the Arduino board, over USB.

Yes, you should be able to reprogram the Arduino through the USB/IDE as usual.

The standard behavior of avrdude (the AVR upload tool used by Arduino) is to do a complete chip erase prior to programming. This step however is ignored by the bootloader to avoid  self destruct.

If your Arduino is configured for auto-reset, the bootloader will start when avrdude attempts to access your board. If the commanded baudrate is different from that of the Arduino (the bootloader expects 57600 baud) it will time out and eventually sync up with the Arduino ISP sketch. This timeout, resynchronization and finally programming at a moderate baudrate add to total programming time. For users who just use the programmer for the occasional upload of a bootloader - the longer time may not be an issue at all.

Quote
How would it program when the programmer is not available?

Form the point of avrdude, a bootloader is just another programmer. When your Arduino resets, the bootloadrt starts and it behaves just like a programmer.

leppie

Quote
Form the point of avrdude, a bootloader is just another programmer. When your Arduino resets, the bootloadrt starts and it behaves just like a programmer.


You mean the 'sketch area' (iow where the ISP is loaded on the flash) of the Arduino acting as the programmer?

leppie

#8
Jun 29, 2010, 06:59 pm Last Edit: Jun 29, 2010, 07:11 pm by leppie Reason: 1
I have been just messing around, but I seem to have it running quite reliably at 115200bps.

Here are my modifications:

Add:

Code: [Select]
#define MAXZ (19200L * 30)
#define BAUDRATE 115200
#define HBDELAY MAXZ/BAUDRATE


Modify:

Code: [Select]
void setup() {
 Serial.begin(BAUDRATE);
 ...
}



Code: [Select]
uint8_t hbval=128;
int8_t hbdelta=3; // play with this to get what you like
void heartbeat() {
 if (hbval > 224) hbdelta = -hbdelta;
 if (hbval < 16) hbdelta = -hbdelta;
 hbval += hbdelta;
 analogWrite(LED_HB, hbval);
 delay(HBDELAY);
}


Proof?   ::)

Code: [Select]
>avrdude -Cavrdude.conf -cstk500v1 -P\\.\COM3 -b115200 -p atmega8  -U flash:w:ArduinoISP2.cpp.hex:i

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.04s

avrdude: Device signature = 0x1e9307
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 "ArduinoISP2.cpp.hex"
avrdude: writing flash (4386 bytes):

Writing | ################################################## | 100% 2.78s

avrdude: 4386 bytes of flash written
avrdude: verifying flash memory against ArduinoISP2.cpp.hex:
avrdude: load data flash data from input file ArduinoISP2.cpp.hex:
avrdude: input file ArduinoISP2.cpp.hex contains 4386 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 2.56s

avrdude: verifying ...
avrdude: 4386 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

Go Up