Menu

One example of how to program Mega 2560 With Great Cow Basic

Anobium
2015-10-13
2021-09-14
  • Anobium

    Anobium - 2015-10-13

    INTRODUCTION:

    While most GCB users are likely to be using PIC Microcontrollers, GCB also supports many ATMEL Microcontrollers. If you happen to have an Mega 2560 you can easily use this board with Great Cow Basic. Below are the steps for setting up GCB@Syn to use Mega 2560.

    Note: Programming the Mega 2560 with GCB WILL NOT erase the bootloader on the microcontroller! This means that the Mega 2560 can still be programmed via the Arduino IDE.

    The was tested and used on the Mega 2560 with the CH034G USB chipset.

    Edit the flashavr.bat file as follows:

    "AVRdude\avrdude.exe"  -c **wiring** -p m2560 -P **COM6** -b 115200 -D -U flash:w:%1:i
    

    Also see, here for the Uno.

     
  • mmotte

    mmotte - 2016-01-09

    Evan,
    This worked---Yahhh!--- to allow me to send a program to the mega 2560 that i just started to experiment with. Now do some testing.

    This should be included in the "flashAVR.bat" file. The other avr setups for uno and mini pro worked right off by just changing the com port number.

    br
    mike

     
  • Anobium

    Anobium - 2016-01-09

    I thought I had include in flashavr.bat Version 0.95.001. Can you check this for me? There is an entry 'Call AVRdude for Arduino_Mega2560 bootloader' - does this entry work? or, did I not place the -D in the batch file?

    br

    Anobium

     
  • mmotte

    mmotte - 2016-01-09

    They looked the same but the difference is in the details!

    from "flashAVR.bat"
    ~~~~~~
    REM Call AVRdude for Arduino_Mega2560 bootloader:
    "AVRdude\avrdude.exe" -c wiring -p m2560 -P COM13 -b 115200 -D -U flash:w:%1:i
    rem "AVRdude\avrdude.exe" -c Wiring -P Com13 -b 115200 -p AT%2 -U flash:w:%1:i

    ~~~~~~
    first one works , second one doesn't

    -p m2560 makes it work

    Thanks
    Mike

     
  • Anobium

    Anobium - 2016-01-10

    OK. I will updated flashavr.bat in version 0.95.003 to include this command that now works.

     
  • Frank Steinberg

    Frank Steinberg - 2016-01-10

    Hi guys!

    I have a Arduino Mega2560. I've tested the original code from flashAVR.bat and it works (for me).
    This is what we get after installation:

    REM  Call AVRdude for Arduino_Mega2560 bootloader:
     rem "AVRdude\avrdude.exe" -c Wiring -P Com7 -b 115200 -p AT%2 -U flash:w:%1:i
    

    What is inserted for "%2" depends on the #chip - statement in our code. For an Arduino Mega2560 it has to be:

    #chip mega2560, 16
    

    so the paramer for calling avrdude is ... -p ATmega2580 ... and this should work.

    The -D parameter means "Disable auto erase for flash memory" - not a good idea.

    @mmotte
    Please check your #chip statement.
    Please check the compilation report (html-file) - what is the chip model?
    What chip is mentioned in SynWrites output window?

    Regards
    Frank

     
  • Anobium

    Anobium - 2016-01-10

    For me. I needed the -D I could not make the write operation work.

    Can I simply include both command lines?

     
  • Frank Steinberg

    Frank Steinberg - 2016-01-10

    What is the errormessage without -D?

     
  • Anobium

    Anobium - 2016-01-10

    Using the GUI from AVRDUDESS 2.4 from my v0.95 install.

    Parameters that work (and I verified the upload) are

    -c wiring -p m2560 -P COM6 -b 115200 -D -U  flash:v:"ATmega2560_SSD1289.hex":i 
    

    Using the parameters the dialog is:

    Writing | ################################################## | 100% 39.80s
    
    avrdude.exe: 261406 bytes of flash written
    avrdude.exe: verifying flash memory against C:\Users\admin\Desktop\ATmega2560_SSD1289.hex:
    avrdude.exe: load data flash data from input file C:\Users\admin\Desktop\ATmega2560_SSD1289.hex:
    avrdude.exe: input file C:\Users\admin\Desktop\ATmega2560_SSD1289.hex contains 261406 bytes
    avrdude.exe: reading on-chip flash data:
    
    Reading | ################################################## | 100% 31.19s
    
    avrdude.exe: verifying ...
    avrdude.exe: 261406 bytes of flash verified
    
    avrdude.exe done.  Thank you.
    

    With the -D off. I can detect the device, verify works correctly but a write operations fails as shown below:

    avrdude.exe: AVR device initialized and ready to accept instructions
    
    Reading | ################################################## | 100% 0.01s
    
    avrdude.exe: Device signature = 0x1e9801
    avrdude.exe: NOTE: "flash" memory has been specified, an erase cycle will be performed
                 To disable this feature, specify the -D option.
    avrdude.exe: erasing chip
    avrdude.exe: stk500v2_command(): command failed
    
    avrdude.exe done.  Thank you.
    

    Note: This ATmega2560 has a USB-SERIAL CH340 serial chipset. This may have something to do with the difference.

    End of report. :-)

     

    Last edit: Anobium 2016-01-10
  • mmotte

    mmotte - 2016-01-10

    With this statement in "flashAVR.bat" i get
    "AVRdude\avrdude.exe" -c Wiring -P Com13 -b 115200 -p AT%2 -U flash:w:%1:i

    The following:
    ~~~~~~~~~
    flashAVR.bat

    avrdude.exe: AVR device initialized and ready to accept instructions

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

    avrdude.exe: Device signature = 0x1e9801
    avrdude.exe: NOTE: "flash" memory has been specified, an erase cycle will be performed
    To disable this feature, specify the -D option.
    avrdude.exe: erasing chip
    avrdude.exe: stk500v2_command(): command failed

    avrdude.exe done. Thank you.

    With This one
     "AVRdude\avrdude.exe"  -c wiring -p m2560 -P COM13 -b 115200 -D -U flash:w:%1:i
    
     I get a program written:
     ~~~~~~~~
    *** flashAVR.bat ***
    
    avrdude.exe: AVR device initialized and ready to accept instructions
    
    Reading | ################################################## | 100% -0.00s
    
    avrdude.exe: Device signature = 0x1e9801
    avrdude.exe: reading input file "C:\GCB_usart_workspace_AVR\Mega2560_PortTesting.hex"
    avrdude.exe: writing flash (850 bytes):
    
    Writing | ################################################## | 100% 0.16s
    
    avrdude.exe: 850 bytes of flash written
    avrdude.exe: verifying flash memory against C:\GCB_usart_workspace_AVR\Mega2560_PortTesting.hex:
    avrdude.exe: load data flash data from input file C:\GCB_usart_workspace_AVR\Mega2560_PortTesting.hex:
    avrdude.exe: input file C:\GCB_usart_workspace_AVR\Mega2560_PortTesting.hex contains 850 bytes
    avrdude.exe: reading on-chip flash data:
    
    Reading | ################################################## | 100% 0.12s
    
    avrdude.exe: verifying ...
    avrdude.exe: 850 bytes of flash verified
    
    avrdude.exe: safemode: Fuses OK (E:FF, H:D8, L:FF)
    
    avrdude.exe done.  Thank you.
    
     
    • Anobium

      Anobium - 2016-01-10

      @Mmotte. What chipset is your device? Because yours works as mine does but I do not really undersand the impact of -D

       
  • Frank Steinberg

    Frank Steinberg - 2016-01-10

    Can you try the newest version of avrdude - the stk500v2 protocol in this version is cahnged:

    http://download.savannah.gnu.org/releases/avrdude/avrdude-6.2-mingw32.zip

     
    • Anobium

      Anobium - 2016-01-10

      @Frank. What is plan to review\test and include in GCB package?

       
      • Anobium

        Anobium - 2016-01-10

        I have just updated in my local build.

        With the old version - I got : Detected 1e9801 = ATmega2560
        Now with the new version I get : Unknown signature 1e9801(probablym2560)

        If I were a new user - I would be worried. Should we wait a while whilst this type of issue are ironed out?

         
        • Frank Steinberg

          Frank Steinberg - 2016-01-11

          With the old version - I got : Detected 1e9801 = ATmega2560
          Now with the new version I get : Unknown signature 1e9801(probablym2560)

          If I were a new user - I would be worried. Should we wait a while whilst this type of issue are ironed out?

          I noticed that too. I think it's better to stay with avrdude 6.1.

           
  • Frank Steinberg

    Frank Steinberg - 2016-01-10

    My Arduino has an ATmega16u2 as serial-usb converter. There are others outside with chinese CH340 chip and older ones with ftdi chip (AFAIK).

    What is yours?

     
  • mmotte

    mmotte - 2016-01-10

    My Arduino 2560 has the ATmega16U2.

    I tried the Evan suggested statement without the "-D" and it fails like the original statement. Same exact error.

     
  • Frank Steinberg

    Frank Steinberg - 2016-01-10

    O.K.

    I checked out, what the Arduino IDE does for flashing:
    Parameter -D is always used (also for the ATmega328 devices)!
    Seems, that the Arduino bootloader does not support the flash-erase command, maybe does itself.
    Anyway: What the Arduino IDE does, can't be wrong.Le's add -D to all the Arduino entries in flashAVR.bat.

    Frank

     

    Last edit: Frank Steinberg 2016-01-10
  • Anobium

    Anobium - 2016-01-10

    I change now. This will be included in release v.95.003.

     
  • Rikki

    Rikki - 2021-09-13

    Old thread, sorry to resurrect but it helped me find a workable solution on the unoffical mega 2560 boards

    Problem: need to unplug arduino usb cable every time a code flash needs to be done

    Resolution:

    download xloader (use your favorite search engine and search for "hobbytronics xloader')

    extract the ZIP

    xloader uses a modified configuration that is able to repeatedly program non-official mega 2560 boards.

    copy and paste these three files from xloader into the AVRdude directory in the GCBasic\GCB@syn\ folder, (overwriting existing files) . Save the original files to a backup folder first if desired.

    averdude.conf

    avrdude.exe

    libusb0.dll

    In the GCB IDE menu, select IDE tools ->GCB tools -> edit programmer preferences

    Find Avrdude (Stk500V2 @ 115200) in the list. Click and hold then drag it to the very top of the "Programmers to Use" section.

    Click Avrdude (Stk500V2 @ 115200) to highlight it then click edit.

    Delete everything in the command line parameters box then paste in the following line:

    -c STK500v2 -b 115200 -P %port% -p m2560 -D -U flash:w:"%filename%":i

    On the righthand side of the editor select your comport from the dropdown list. Use device manager in Windows to identify the serial comm port your mega 2560 is connected to.

     
  • stan cartwright

    stan cartwright - 2021-09-14

    Wow! This is so old I forgot. I just tried this on a mega2560 board I had forgotten I had!

    #chip mega2560, 16
    #option explicit
    
    dir portb.7 out
    Do
      portb.7=not portb.7
      wait 1 s
    loop
    

    I selected mega2560 in programmer preferences and pasted it to the top of the list and it flashed and worked ok. This is using the clone board I must have had problems with at the time... 5 years ago!
    Compiler Version: 0.98.07 2021-05-27 (Windows 64 bit) Program Memory: 342/262144 bytes (0.13%) RAM: 0/8192 bytes (0.0%) OSC: 16Mhz Chip: MEGA2560

    So I guess it's been sorted in gcb later releases.

    As I'd forgotten I had a 2560 board I ordered another and it says arduino and the logo so may be genuine. Still in it's anti static bag but told seller that it arrived with socket A8 to A15 bent like it got damaged in post but bent them back while still in anti static so don't know if to send back or open and try it.

     
  • stan cartwright

    stan cartwright - 2021-09-14

    When I first started using gcb I used a uno and xloader to flash the gcb hex.
    Anobium had to look up xloader as he'd never heard of it.
    The gui programmer preferences are easier than editing script as it was.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.