Dick Cappels' project pages http://www.projects.cappels.org


Return to HOME (more projects)
AttoBasic Home

AttoBasic Version 2.1 -Now with support for USB and Arduino
Byte wide basic, based on the original AttoBasic, version 2.1 includes all of the functions of version 2 that make it an
excellent hardware debug tool, as well as a platform for small programs, but it also includes Scott Vitale's
adaptation
to allow control via  USB in addition to the original serial port, and it now includes
bootloader support, especially useful Arduino platforms.


Code revised to level 2.1.1 on 8 March, 2012



A precision frequency generator using AttoBasic 2.1 with USB for debugging




Downloads are at the bottom of this page. CLICK HERE

Overview
AttoBasic version 2.1 includes all the features of AttoBasic 2.0, including Scott Vitale's enhancements, but also includes additional code from Scott Vitale that allows control via USB or the serial port  and boot loaders on supported AVR controllers and Arduino platforms. Non-ATmega32U4 versions of ARDUINO do not support USB serial I/O on-chip but ARDUINO's have inherant on-board support for USB by means of the FTDI serial-to-USB converter.

Operation
Programs are typed or loaded from a terminal via a line editor, and stored in internal RAM. SAVE and LOAD commands save and load the program from the on-chip EEPROM.

A Self-Start feature causes AttoBasic program stored in EEPROM to be loaded into RAM and begin execution if the Self-Start pin is held low during boot-up. This pin can be assigned during assembly. In the hex files on this web page the Self-Start pin is Port C bit 3 for the
ATmega88/168/328 versions and Port D bit 7 on the ATmega32U4. These pins have ineternal pull-ups.
 
The lower 256 memory locations is available for examination and modification via PEEK and POKE commands. 26 Variables (A..Z) are supported. All arithmetic and variables are byte-wide. Strings are not directly supported though all characters can be read with "KEY" and printed with "EMIT" commands.

The Line editor supports destructive backspace (delete key), line replacement, line deletion, and line insertion. Valid line numbers range is 0..255. Lines entered with a numeral in the first column will be stored, others will be interpreted when the carriage return (ENTER key) is received. The interpreter is not case-sensitive. PEEK and Poke provide access to the entire 64k data memory space which includes all I/O registers and all RAM -this can be useful for debugging or additional, indexed data storage. all on-chip peripherals. Special I/O commands support bit and byte I/O. GOSUB-RETURN and FOR-NEXT loops have one return level.


To view the set of commands supported by AttoBasic Version 2, click here:commandlist_AB21.html

Device Programming Instructions By Scott Vitale

Introduction


AttoBASIC Version 2.1, hereinafter referred to as AttoBASIC, supports most flavors of the ATMEL 8-bit series of AVR microcontrollers having at least 8K FLASH memory, 1K SRAM and 512 bytes of EEPROM.

AttoBASIC comes with pre-assembled HEX files for the ATmega88/P/A/PA, ATmega168/P/A/PA, ATmega328/P/A/PA and ATmega32U4 microcontrollers at clock speeds of 4 MHz, 8 MHz, 16 MHz and 20 MHz.  Other clock speeds can be built from the source code, in the Downloads section of this page, and if one has the knowledge to do so, additional commands and hardware can be added.

The only difference in the immediately supported μC's, besides the amount of memory, is that the ATmega32U4 has a built-in USB hardware controller.  Thus, the ATmega32U4 builds can be communicated with via the USART or the USB emulating a Virtual Com Port (VCP).  The free WINDOWS® drivers are
supplied with AttoBASICv2.1 in the folder entitled "_USB_Drivers".  Linux natively supports the VCP interface as either /dev/ttyACMx or /dev/ttyUSBx devices.

Most ARDUINO™ flavors and their clones use the ATmega168(P) or ATmega328(P).  The ATmega88/168/328 μC's use the USART to communicate through.  Hardware platforms using those μC's with a standard RS-232 interface are directly supported.  However, the ARDUINO™-type hardware platforms communicate through a Virtual Serial Port using a separate on-board USB to Serial converter to make the translation to USB.  This poses no problem for AttoBASIC because the hardware is the same as a non-USB platform and no modifications to software or hardware are required.

AttoBASIC also includes pre-assembled HEX files for the aforementioned microcontrollers and clock speeds containing the "OptiBoot" boot-loader, which is supported by the programming utility avrdude and the ARDUINO™ development environment.

Firmware Flavor Files
AttoBASICv2.1 comes with pre-assembled HEX files listed in the Downloads section of this page, which are stored in the AVR_Specific_Builds folder.  There are versions with and without boot-loader support as well as with and without USB serial I/O support for the ATmega32U4.  You should be able to determine the configuration of each file from the file name.

Loading the firmware into a specific hardware platform
For most hardware platforms, using the In System Programming (ISP) feature of the AVR μC's is the preferred method.  Choose a file and clock speed that is compatible with the μC on the target platform.  Keep in mind that all "factory fresh" AVR's come with the fuse setting that enables the on-chip oscillator and divide by 8 prescaler so the μC runs at 1 MHz.  One will need to insure that the programmer's ISP clock speed is ¼ of the μC's clock and likely wish to set the fuses to enable an external crystal and disable the divide by 8 prescaler.  Setting the AVR's fuses is beyond the scope of this writing.  Refer to target μC's datasheet and programmer's documentation for further information.

ARDUINO™:  For those having an ARDUINO™ compatible platform available, the ATmega88/168/328 firmware files with the "nobtldr" suffixes can be directly uploaded using the avrdude utility, which is available as part of the avr-gcc software package under Linux or the WinAVR software package under WINDOWS®.

If using the WINDOWS® OS, open a CMD window, traverse to the appropriate folder containing the desired HEX file and issue one of the two following commands (boot-loader dependant):

avrdude.exe -V -F -p atmega328p -c arduino -P COMx -b 115200 -U flash:w:myprogram.hex

avrdude.exe -V -F -p atmega328p -c stk500v1 -P COMx -b 57600 -U flash:w:myprogram.hex

Replace "atmega328p" with the target μC, "myprogram.hex" with the desired firmware filename and "COMx" with the actual serial port name your ARDUINO™ responds on.

If using the Linux OS (or Mac OSX?), open a terminal window, traverse to the appropriate path containing the desired HEX file and issue one of the two following commands (boot-loader dependant):

avrdude -V _F -p atmega328p -c arduino -P /dev/ttyACMx -b 115200 -U flash:w:myprogram.hex

avrdude -V _F -p atmega328p -c stk500v1 -P /dev/ttyACMx -b 57600 -U flash:w:myprogram.hex

Replacing "atmega328p" with the target μC, "myprogram.hex" with the desired firmware filename and "/dev/ttyACMx" with the actual serial port name your ARDUINO™ responds on (usually /dev/ttyACMx or /dev/ttyUSBx where x is a number between 0 and 9).

Notes:
1.    If avrdude responds with a "stk500_getsync(): not in sync" message, it is because the ARDUINO™ boot-loader is not responding.  Check the command line for correctness.   If avrdude continues to error with the same message, substitute either "115200", "57600", "19200" or "9600" as the baud rate in the "-b NNNNN" option and/or power-cycle the ARDUINO™.  If the problem persists, consult other resources for remedy.

2.    Do not attempt to use the ARDUINO™ boot-loader to upload a firmware file that contains a boot-loader image as this will corrupt the existing boot-loader and render it inoperable.  Those particular firmware files are meant to be programmed with an ISP programmer only and is the only way to recover from this error.

3. AttoBASIC contains the BLDR command to invoke the resident boot-loader if one exists.
However, if the BOOTRST fuse is programmed, the resident boot-loader will automatically be
invoked. On ARDUINO™ platforms, the resident boot-loader will start the application program
after a short delay. Using AttoBASIC to invoke a boot-loader that uses the serial port may emit
non-printable characters that confuse the terminal emulator program. This will likely require a
restart of the terminal emulator program to recover. One’s particular boot-loader’s behavior may
vary

4.     AttoBASIC is using "OptiBoot" for its boot-loader support. The avrdude command line that supports Optiboot contains "-c arduino".

    a.    for the ATmega168(P), the boot-loader resides at 0x1F00 and the BOOTRST fuse must be programmed.

    b.    for the ATmega328(P), the boot-loader resides at 0x3F00 and the BOOTRST fuse must be programmed.


5.    The "Self-Start" feature uses PINC3 on the ATmega88/168/328 firmware images.  If that feature is not used, the I/O pin can be used as an I/O port pin without interference from AttoBASIC and does not require and external pull-up resistor."

ATmega32U4:  For those having a ATmega32U4 compatible platform available (like the ADAFRUIT Mega32U4 Breakout Board), the ATmega32U4 firmware files with the "nobtldr" and/or "nousb" suffixes can be programmed into the target μC using that manufacturer's programming tool.  The boot-loader incorporated into AttoBASICv2.1 for the ATmega32U4 is Dean Camera's LUFA in DFU mode.  Therefore ATMEL's FLIP programming tool can be used, which is available for the WINDOWS® and Linux computing platforms.

Notes:

1.    On the USB enabled version of the ATmega32U4 firmware, one must type a key on the terminal emulator once a connection to the ATmega32U4 is achieved.  AttoBASIC will then respond with its sign-on message.

2.    For the ATmega32U4 with boot-loader support, the boot-loader resides at 0x3800 and the BOOTRST fuse must be programmed.

3.      The "Self-Start" feature uses PIND7 on the ATmega32U4 firmware images.  If that feature is not used, the I/O pin can be used as an I/O port pin without interference from AttoBASIC and does not require and external pull-up resistor.


Questions about Device Programming Instructions should be addressed to Scott Vitale  at ksv_prj(at)gmx.com.  Replace "(at)" with "@" before mailing.

Downloads
  You may need to right-click to download the files.


AttoBasic 2.1 Command List
commandlist_AB21


Device Programming Instructions 
Everything you need to know about programming your AVR  AB_2.1_Device_Programming_Instructions.pdf


Hex Files

All files below provide 19,200 baud operation with the indicated clock frequency.

ATmega32u4
ATTOBASICV211_M32u4-4MHZ-uart_btldr.hex

ATTOBASICV211_M32u4-4MHZ-uart_nobtldr.hex

ATTOBASICV211_M32u4-8MHZ-uart_btldr.hex

ATTOBASICV211_M32u4-8MHZ-uart_nobtldr.hex

ATTOBASICV211_M32u4-8MHZ-usb_btldr.hex (Note: download of this file not recommended while a bug is being investitated)

ATTOBASICV211_M32u4-8MHZ-usb_nobtldr.hex
(Note: download of this file not recommended while a bug is being investitated)

ATTOBASICV211_M32u4-16MHZ-uart_btldr.hex

ATTOBASICV211_M32u4-16MHZ-uart_nobtldr.hex


ATTOBASICV211_M32u4-16MHZ-usb_btldr.hex

ATTOBASICV211_M32u4-16MHZ-usb_nobtldr.hex


ATTOBASICV211_M32u4-20MHZ-uart_btldr.hex

ATTOBASICV211_M32u4-20MHZ-uart_nobtldr.hex



ATmega88
ATTOBASICV211_M88-4MHZ-uart.hex

ATTOBASICV211_M88-8MHZ-uart.hex

ATTOBASICV211_M88-16MHZ-uart.hex

ATTOBASICV211_M88-20MHZ-uart.hex



ATmega168
ATTOBASICV211_M168-4MHZ-uart_btldr.hex

ATTOBASICV211_M168-4MHZ-uart_nobtldr.hex

ATTOBASICV211_M168-8MHZ-uart_btldr.hex

ATTOBASICV211_M168-8MHZ-uart_nobtldr.hex

ATTOBASICV211_M168-16MHZ-uart_btldr.hex

ATTOBASICV211_M168-16MHZ-uart_nobtldr.hex

ATTOBASICV211_M168-20MHZ-uart_btldr.hex

ATTOBASICV211_M168-20MHZ-uart_nobtldr.hex



ATmega328
ATTOBASICV211_M328-4MHZ-uart_btldr.hex

ATTOBASICV211_M328-4MHZ-uart_nobtldr.hex

ATTOBASICV211_M328-8MHZ-uart_btldr.hex

ATTOBASICV211_M328-8MHZ-uart_nobtldr.hex

ATTOBASICV211_M328-16MHZ-uart_btldr.hex

ATTOBASICV211_M328-16MHZ-uart_nobtldr.hex

ATTOBASICV211_M328-20MHZ-uart_btldr.hex

ATTOBASICV211_M328-20MHZ-uart_nobtldr.hex




Example Programs
Zipped package of examples of AttoBasic program files Example_AttoBasic_2.1_Programs.zip
Example programs included in this package can also be downloaded separately:    
AD9337_Setup.txt
ADC_Test.txt
Beeper_Test.txt
BoostRegTest.txt
ICP_test.txt
LCD_BackLightTest.txt
LCD_Init.txt
PFR_V10-Test.txt
SFG200V21DDSTest.txt
SFG200V21PortTest.txt
TWI_test.txt

The example programs can be loaded into the AttoBasic chip using the serial interface while AttoBasic is not intepreting a program.



Source Code
...and all the files you need to build your own version  AttoBasic_2.1 source package

The LUFA bootloader supplied in this package was written by and owned by Dean Camera   dean [at] fourwalledcubicle [dot] com,  http://www.lufa-lib.org
The USB serial I/O code is from USB Serial Example for Teensy USB Development Board was copyrighted by PJRC.COM, LLC. See http://www.pjrc.com/teensy/
Please see the licensing statements accompanying the respective files.

Find updates at www.projects.cappels.org

AttoBasic Home
Return to HOME (More Projects)
 
Contents ©2012 Scott Vitale and Richard Cappels. All Rights Reserved. Find updates at www.projects.cappels.org.

First posted in February, 2012. Code revision 2.1.1 on 8 March 2012.

You can send  email about AttoBasic 2.1 to Scott Vitale  at ksv_prj(at)gmx.com.  Replace "(at)" with "@" before mailing.

        You can send email to Dick Cappels about the web page and site at projects(at)cappels.org. Replace "(at)" with "@" before mailing.


Use of information presented on this page is for personal, nonprofit educational and noncommercial use only. This material (including object files) is copyrighted by Richard Cappels and Scott Vitale and may not be republished or used directly for commercial purposes. For commercial license, click here.

  Liability Disclaimer and intellectual property notice
(Summary: No warranties, use these pages at your own risk. You may use the information provided here for personal and educational purposes but you may not republish or use this information for any commercial purpose without explicit permission.) I neither express nor imply any warranty for the quality, fitness for any particular purpose or  user, or freedom from patents or other restrictions on the rights of use of any software, firmware, hardware, design, service,information, or advice provided, mentioned,or made reference to in these pages. By utilizing or relying on software, firmware, hardware, design, service,information, or advice provided, mentioned, or made reference to in these pages, the user takes responsibility to assume all risk and associated with said activity and hold Richard Cappels harmless in the event of any loss or expense associated with said activity. The contents of this web site, unless otherwise noted, is copyrighted by Richard Cappels. Use of information presented on this site for personal, nonprofit educational and noncommercial use is encouraged, but unless explicitly stated with respect to particular material, the material itself may not be republished or used directly for commercial purposes. For the purposes of this notice, copying binary data resulting from program files, including assembly source code and object (hex) files into semiconductor memories for personal, nonprofit educational or other noncommercial use is not considered republishing. Entities desiring to use any material published in this pages for commercial purposes should contact the respective copyright holder(s).
Original Document Location: http://www.cappels.org/dproj/AttoBasic2_1/AttoBasic_2.1_with_USB_and_Arduino_support.html

web counter
web counter