Using Arduino Hardware with Flowcode for AVR
Posted: Fri Oct 29, 2010 10:11 am
Introduction
Arduino produce a range of target boards that can be directly programmed by Flowcode for AVR.
Hardware
Most of the Arduino boards include the standard 6-pin ISP header, allowing them to be programmed using the AVRISPmkII programmer. However, the boards also include USB connection hardware, and the microcontrollers contain bootloader programs that are compatible with the standard Atmel STK500 programming commands. They can therefore be connected directly to a PC using a USB cable and programmed with no additional programming hardware.
Th latest version of the Flowcode software can be downloaded from here: http://www.matrixtsl.com/flowcode.php
Three of the main targets are the Duemilanove and Mini (ATmega328) and Mega1280 (ATmega1280). The USB connection is handled by an FTDI USB to serial chip. Drivers for this device are widely available and are included in the free Arduino programming software download - available from http://www.arduino.cc.
The Duemilanove and Mega1280 have recently been replaced by the Uno (ATmega328) and Mega2560 (ATmega2560). The new boards have an alternative USB interface chip (a USB ATmega device) that requires different drivers to the FTDI chip. The newer drivers are also included in the latest Arduino download (Version 021).
The USB connection appears as a virtual COM (RS232) port. The new com port number needs to be identified to it can be used as a parameter by Flowcode.
Boards with the FTDI chip appear as 'USB Serial Port (COM2 in this case)
The newer boards identify themselves more clearly.
If the COM port number allocated by Windows is too high, the programming software might not be able to locate it. In this case the port number can be changed in the advanced properties of the driver. It might be necessary to reclaim a low numbered COM port that is indicated as being already in use!
The various board types require different programming baud rates - the information is available from files in the Adruino software download. The data received by the USB chip is programmed into the target microcontroller via one of its UARTs, under the control of the bootloader. The bootloader spends a short time checking for incoming programs each time it recovers from a RESET condition.
Programming
Programming is handled by AVRDUDE (as supplied with Flowcode for AVR), so the main changes required to allow Flowcode to program an Arduino board are a new batch file to control the programming, and new Location and Parameter information for the Programmer section of the Compiler Options panel.
The two new batch files must be copied into the Tools\MX_bats folder of the Flowcode AVR V4 installation.
Another requirement for programming the Arduino boards is the ability to reset the target device shortly before transmitting the new program - initiating the bootloader. This can be achieved manually, but the timing is quite critical and an alternative method is available under the control of the COM port.
The boards use a pulse on the RS232-DTR line to RESET the target device temporarily into programming mode. If programming begins within a short time period after the RESET, the chip is held in programming mode and the program is downloaded. If no program information is received within the time period, the device begins to run any program that is already in memory.
Direct control of the DTR line is not easily achieved, but the programming batch files contain DOS Mode commands that appear to generate the required pulse before the download process is started.
Programmer parameter string:
%a stk500v2 com8 115200 "%f.hex"
The com port value will need to match the port allocated by Windows (as described above).
The baud rate (115200 in this case) is dependent on the target board type.
The protocol (stk500v2 in this case) is also dependent on the target board type.
Uno = 115200 Baud, stk500
Duemilanove, Nano (ATmega328) = 57600 Baud, stk500
Diecimilia, Duemilanove, Nano (Atmega168) = 19200 Baud, stk500
Mega2560 = 115200 Baud, stk500v2
Mega1280 = 57600 Baud, stk500
See Arduino documentation for other options.
Programmer path strings:
C:\Program Files\Matrix Multimedia\Flowcode AVR V4\Tools\MX_bats\avrc_arduino1.bat
C:\Program Files\Matrix Multimedia\Flowcode AVR V4\Tools\MX_bats\avrc_arduino2.bat
The avrc_arduino1.bat file seems to work best with the older Arduino boards (FTDI USB chip):
The avrc_arduino2.bat file works with the newer Arduino boards (ATmega USB device):
The path information is based on a default Flowcode installation. If Flowcode has been installed at an alternative location, the path information must be modified as appropriate.
In some cases the programmer will fail on the initial download and AVRDUDE will then be unable to access the allocated COM port. If this happens, disconnecting and removing the power from the Arduino board, then re-connecting everything usually cures the problem.
Flowcode
The Arduino bootloader enables a UART in the target device to allow the program to be transferred. The two pins used by the UART are not available as normal I/O when the UART is enabled. To return the UART pins to normal use, the first instruction in the Flowcode program should be a C code icon containing the following line (for the Duemilanove and Nano boards, other target devices might have different register names):
UCSR0B &= ~((1 <<RXEN0) | (1 << TXEN0)); //disable UART0
Apart from this minor issue (only applicable if the UART port pins are required as programmable I/O) the boards can be sent any normal Flowcode program compiled for the appropriate device and clock speed.
Connections
Arduino boards make I/O connections available using header sockets. These allow some component leads to be inserted directly. The sockets also allow connection of the 'Shield' expansion boards. Some of these are for specific applications, but prototyping versions are also available.
Using a prototype Shield board it is possible to make the I/O connections available in a more convenient form. The example board pictured uses the standard Atmel 2x5 pin headers to make the I/O available as individual ports. Additional ribbon cables and converter PCBs then provide the D9 E-blocks connectors.
The D9 connectors could be soldered directly to the Shield board, or wired to headers and inserted directly into the sockets on the main board.
Arduino produce a range of target boards that can be directly programmed by Flowcode for AVR.
Hardware
Most of the Arduino boards include the standard 6-pin ISP header, allowing them to be programmed using the AVRISPmkII programmer. However, the boards also include USB connection hardware, and the microcontrollers contain bootloader programs that are compatible with the standard Atmel STK500 programming commands. They can therefore be connected directly to a PC using a USB cable and programmed with no additional programming hardware.
Th latest version of the Flowcode software can be downloaded from here: http://www.matrixtsl.com/flowcode.php
Three of the main targets are the Duemilanove and Mini (ATmega328) and Mega1280 (ATmega1280). The USB connection is handled by an FTDI USB to serial chip. Drivers for this device are widely available and are included in the free Arduino programming software download - available from http://www.arduino.cc.
The Duemilanove and Mega1280 have recently been replaced by the Uno (ATmega328) and Mega2560 (ATmega2560). The new boards have an alternative USB interface chip (a USB ATmega device) that requires different drivers to the FTDI chip. The newer drivers are also included in the latest Arduino download (Version 021).
The USB connection appears as a virtual COM (RS232) port. The new com port number needs to be identified to it can be used as a parameter by Flowcode.
Boards with the FTDI chip appear as 'USB Serial Port (COM2 in this case)
The newer boards identify themselves more clearly.
If the COM port number allocated by Windows is too high, the programming software might not be able to locate it. In this case the port number can be changed in the advanced properties of the driver. It might be necessary to reclaim a low numbered COM port that is indicated as being already in use!
The various board types require different programming baud rates - the information is available from files in the Adruino software download. The data received by the USB chip is programmed into the target microcontroller via one of its UARTs, under the control of the bootloader. The bootloader spends a short time checking for incoming programs each time it recovers from a RESET condition.
Programming
Programming is handled by AVRDUDE (as supplied with Flowcode for AVR), so the main changes required to allow Flowcode to program an Arduino board are a new batch file to control the programming, and new Location and Parameter information for the Programmer section of the Compiler Options panel.
The two new batch files must be copied into the Tools\MX_bats folder of the Flowcode AVR V4 installation.
Another requirement for programming the Arduino boards is the ability to reset the target device shortly before transmitting the new program - initiating the bootloader. This can be achieved manually, but the timing is quite critical and an alternative method is available under the control of the COM port.
The boards use a pulse on the RS232-DTR line to RESET the target device temporarily into programming mode. If programming begins within a short time period after the RESET, the chip is held in programming mode and the program is downloaded. If no program information is received within the time period, the device begins to run any program that is already in memory.
Direct control of the DTR line is not easily achieved, but the programming batch files contain DOS Mode commands that appear to generate the required pulse before the download process is started.
Programmer parameter string:
%a stk500v2 com8 115200 "%f.hex"
The com port value will need to match the port allocated by Windows (as described above).
The baud rate (115200 in this case) is dependent on the target board type.
The protocol (stk500v2 in this case) is also dependent on the target board type.
Uno = 115200 Baud, stk500
Duemilanove, Nano (ATmega328) = 57600 Baud, stk500
Diecimilia, Duemilanove, Nano (Atmega168) = 19200 Baud, stk500
Mega2560 = 115200 Baud, stk500v2
Mega1280 = 57600 Baud, stk500
See Arduino documentation for other options.
Programmer path strings:
C:\Program Files\Matrix Multimedia\Flowcode AVR V4\Tools\MX_bats\avrc_arduino1.bat
C:\Program Files\Matrix Multimedia\Flowcode AVR V4\Tools\MX_bats\avrc_arduino2.bat
The avrc_arduino1.bat file seems to work best with the older Arduino boards (FTDI USB chip):
The avrc_arduino2.bat file works with the newer Arduino boards (ATmega USB device):
The path information is based on a default Flowcode installation. If Flowcode has been installed at an alternative location, the path information must be modified as appropriate.
In some cases the programmer will fail on the initial download and AVRDUDE will then be unable to access the allocated COM port. If this happens, disconnecting and removing the power from the Arduino board, then re-connecting everything usually cures the problem.
Flowcode
The Arduino bootloader enables a UART in the target device to allow the program to be transferred. The two pins used by the UART are not available as normal I/O when the UART is enabled. To return the UART pins to normal use, the first instruction in the Flowcode program should be a C code icon containing the following line (for the Duemilanove and Nano boards, other target devices might have different register names):
UCSR0B &= ~((1 <<RXEN0) | (1 << TXEN0)); //disable UART0
Apart from this minor issue (only applicable if the UART port pins are required as programmable I/O) the boards can be sent any normal Flowcode program compiled for the appropriate device and clock speed.
Connections
Arduino boards make I/O connections available using header sockets. These allow some component leads to be inserted directly. The sockets also allow connection of the 'Shield' expansion boards. Some of these are for specific applications, but prototyping versions are also available.
Using a prototype Shield board it is possible to make the I/O connections available in a more convenient form. The example board pictured uses the standard Atmel 2x5 pin headers to make the I/O available as individual ports. Additional ribbon cables and converter PCBs then provide the D9 E-blocks connectors.
The D9 connectors could be soldered directly to the Shield board, or wired to headers and inserted directly into the sockets on the main board.