dtv2ser Arduino

1. Introduction

The original dtv2ser project uses a custom made board with an ATmega8 to provide the interface between a serial port and the DTV dtvtrans software. The layout and the schematics for the board are freely available but unfortunately most users have difficulties to create the HW from scratch.

With the Arduino platform an AVR ATmega platform was released to the public that is available very easily and rather cheap. This document describes how to transform an off-the shelve Arduino board into a dtv2ser device. The HW modifications required are very simple and this allows even unexperienced users to create their own device.

2. HW Requirements

  • An “Arduino 2009” aka “Arduino Duemilanove” board with ATmega168 or ATmega328
  • 3x LEDs (red, green, blue)
  • 3x 220 Ohm Resistors
  • A DB9 female connector (for the DTV joystick port)
  • some wire

The Arduino2009 has an ATmega168/328 with 16 MHz clock frequency on the board and provides a USB/Serial connector with a FT232 chip that has HW RTS/CTS handshaking support.

You can use one of the many Arduino clones (Seeduino, …) if they have similar HW parameters.

Update (26.2.2012): Even the new Arduino Uno is supported. As it does not have a FT 232 USB chip with HW RTS/CTS on board it does not allow you to enable HW handshaking as described on this page. You rather have to buy an extra FT232 break out board (e.g. from sparkfun) with RTS/CTS signals available and then connect TxD, RxD, RTS, CTS, and GND from this board to your Arduino on the mentioned pins. This Forum64 thread gives instructions on this mod (in german). Then the same firmware can be used.

The Arduino2009’s USB to serial connector is used with 250kB/s as a transfer rate. Please make sure that your host operating system allows to set this non-standard speed. Its reported to work on Mac OS X and Windows with the FTDI drivers.

3. HW Build Instructions

3.1 Add CTS Line to the AVR

The vanilla Arduino board does not allow to control the HW CTS serial signal from the AVR chip. But this is required to allow high performance data transfer for the dtv2ser firmware. Fortunately, this signal of the FT232 chip is available on the solder pad X3 and can be added by soldering a wire from there to a pin that is connected to the AVR port labeled “DIGITAL 2”.

.  Solder Pad X3                              DIGITAL .
.  4   3   2   1                                      .
.  (x) (x) (x) (x)                                    .
.               |                                     * 3
.               +---------------------------------->  * 2
.                                                     * 1 TX
.                                                     * 0 RX

3.2 Add the dtv2ser LEDs

The dtv2ser uses three LEDs in green, orange and red to signal its internal status to the user. In this step we add those LEDs by simple connecting them with a resistor each to the DIGITAL pins 8, 9 and, 10. The positive side of each LED is connected to +5V that is available on the POWER connector.

.                      Red LED
.  Reset *         +------>|----| 220 |--------------* DIGITAL 10
.    3V3 *         |  Orange LED
.     5V *---------+------>|----| 220 |--------------* DIGITAL 9
.    GND *         |  Green LED
.    GND *--+      +------>|----| 220 |--------------* DIGITAL 8
.    Vin *  |
.           |
.           v  This line is used in section 3.3

3.3 Add the joystick connector

Finally, the Arduino needs to be connected to your DTV. As dtvtrans uses one of the joystick ports for communication it is quite common to use a DB9 standard joystick connector for this.

The 6 signal lines and GND need to be soldered to the DB9 (female) connector and on some pin headers to get connected to the Arduino on the connector labeled “ANALOG IN”.


.  DB9 Connector               DB9          ANALOG IN
.  (rear view)                  1 * ----------- * 0
.                               2 * ----------- * 1
.  1 2 3 4 5                    3 * ----------- * 2
.  * * * * *                    4 * ----------- * 3
.   * * * *                     6 * ----------- * 4
.   6 7 8 9                     9 * ----------- * 5

.                             DB9          POWER CONNECTOR (see 3.2)
.                               8 * ----------- * GND

3.4 Add RTS Line to the AVR

The RTS is required for firmware versions 0.5b and up.

The RTS line is available on the left solder pad of the unpopulated resistor found on the right hand side of the X3 pads. Have a look at the picture above to find the exact location. The RTS line needs to be connected to port DIGITAL 3 on the AVR.

.  Solder Pad X3                              DIGITAL .
.  4   3   2   1                                      .
.  (x) (x) (x) (x)                                    .
.                          +---------------------->   * 3
.                          |                          * 2
.                          *  *                       * 1 TX
.                       unpopulated solder pads       * 0 RX

Do NOT connect the line to the right pad and do NOT short circuit poth pads. The right line is the RESET line and will restart your board every time RTS is triggered… You have been warned 😉

That’s it! Now your arduino is a dtv2ser board 😉

4. Flash the firmware

All software including the firmware is included in the dtv2ser release archive on the dtv2ser homepage.

New (3.1.2011): Recompiled Firmware with AVR GCC 4.3.3 and -fno-inline to avoid timing problems in inlined code.

New (3.1.2011): Fixed timing issue with AVR GCC 4.3.3 and added RTS support (requires RTS line as described above)

I use the avrdude command line tool to flash the firmware.

But you can use any downloader SW that supports flashing the arduino.

The firmware file is called “dtv2ser-x.y-250000-arduino2009-atmega168.hex” with x.y being the current version of dtv2ser. This file comes with this distribution.

Connect your Arduino board to your Mac or PC and find out the serial port where it is connected (here on my Mac: /dev/cu.usbserial-A7006RWQ, on PCs something like COM5, on Linux /dev/ttyUSB0).

The following command flashes the firmware:

> cd server
> make prog_arduino2009 LDR_PORT=<serial port>

or without Makefile call (for Arduino 2009 with ATmega 168):

> avrdude -p m168 -c arduino -P <serial port> \
                  -b 19200 -U flash:w:dtv2ser-0.5a-250000-arduino2009-atmega168.hex

Or on a board with ATmega328 (Thanks to giox!):

> avrdude -p m328p -c arduino -P <serial port> \
                  -b 57600 -U flash:w:dtv2ser-0.5a-250000-arduino2009-atmega328.hex

Some bootloaders (esp. for the ATmega 328) use a higher baudrate, e.g. 38400. Adjust the -b switch accordingly.

If everything worked fine then your newly attached Green LED goes on after a reset.

5. Using dtv2sertrans Host SW

Starting from version 0.4 the dtv2sertrans SW directly supports the arduino board. See the manual for this tool for further details.

Note the following:

  • The arduino uses a baud rate of 250kB/s and not 240kB/s as set as default.
    So you have to specify the -s switch or set the DTV2SER_SPEED environment
    variable:
> ./dtv2sertrans -s 250000 ...
  • Due to its HW the Arduino is reset every time the serial port is opened from dtv2sertrans. With this behaviour it is not possible to keep parameter settings during calls of dtv2sertrans. Therefore it is advisable to perform all parameter commands on the same command line and concatenate the commands with +. Additionally. you can save changed parameters to the EEPROM to have them survive a reset.
> ./dtv2sertrans  .... + param set_byte 0 5 + ....
> ./dtv2sertrans  .... + param set_byte ... + param save

That’s it! Have fun using dtv2ser…

9 comments to dtv2ser Arduino

  • giox

    Why RTS is left nc on Arduino 2009, but connected to PD3(INT1) in DTV2SER/USB?

  • Arduinos use the RTS line to reset the device and trigger the bootloader when flashing the device. Therefore, the RTS signal cannot be used in RTS/CTS HW handshake without cutting PCB wires.

  • Fortunately, RTS is controlled by the PC to limit the data rate of the Arduino device. As the PC is assumed to be faster this control line is not really necessary and can be omitted.

  • giox

    This works for ATmega328p:

    avrdude -p m328p -c arduino -P com24 -b 57600 -U flash:w:dtv2ser-0.5-250000-arduino2009-atmega328.hex

    btw, on my arduino 2009 “copy” board the R2 (100R) in RTS line is not fitted. So it sees to be in your ATmega168 board picture in this page…

    Anyway thank you for the great work You have done!

  • giox

    Hi
    I have a difficulties with my setup.
    Flash dumping/reading doesn’t work. flash map and id works though.

    D:\python dtv2sertrans flash dump myrom.img
    dtv2sertrans version 0.5, dtv2ser device version 0.5
    dumping flash ROM to file ‘myrom.img’
    result: 0207 Transfer: Client Timeout
    FAILED: CmdError(‘Command failed’,)

    This is the only area that can be read from flash. Other areas fail with client timeout.
    D:\python dtv2sertrans read r0x000000-0x001000 1st4kb.img
    dtv2sertrans version 0.5, dtv2ser device version 0.5
    receiving ROM memory from DTV
    speed: client=17.09 server=19.05 (kbyte/s)
    time: 00:00.375 for 4096/0x001000 bytes
    saving raw file ‘1st4kb.img’: 4096/0x001000 bytes

    RAM reading works though:

    D:\python dtv2sertrans diag testsuite
    dtv2sertrans version 0.5, dtv2ser device version 0.5
    * writing 0x010000 pattern bytes (0xff) to dtv2ser device via serial
    speed: client=24.23 server=24.24 (kbyte/s)
    time: 00:02.671 for 65536/0x010000 bytes
    * reading 0x010000 pattern bytes (0xff) from dtv2ser device via serial
    speed: client=24.23 server=24.33 (kbyte/s)
    time: 00:02.782 for 65536/0x010000 bytes
    * writing 0x010000 pattern bytes (0xff) from dtv2ser device to DTV only
    speed: client=17.21 server=17.39 (kbyte/s)
    time: 00:03.733 for 65536/0x010000 bytes
    * reading 0x010000 pattern bytes (0xff) from DTV to dtv2ser device only
    speed: client=18.79 server=19.05 (kbyte/s)
    time: 00:03.421 for 65536/0x010000 bytes
    * dummy write 0x010000 pattern bytes (0xff) to DTV
    speed: client=17.35 server=17.25 (kbyte/s)
    time: 00:03.703 for 65536/0x010000 bytes
    * dummy read 0x010000 pattern bytes (0xff) from DTV
    speed: client=18.96 server=19.10 (kbyte/s)
    time: 00:03.421 for 65536/0x010000 bytes
    * ALL TESTS PASSED OK! *

  • Indeed the 328 Firmware compile was broken :( It uploaded a fixed version 0.5a.
    For the 328 compile I had to upgrade the toolchain as my old avr-gcc 3.x doesn’t know the 328 device. With the new avr-gcc 4.x and its more agressive inlining some core transfer routines were inlined and the dtvtrans timing was broken. As a quick workaround I disabled inlining.
    For the next version I’ll fix the timing critical parts so that the compiler can’t break it 😉

    Thanks for pointing out that RTS is also available on the Arduino 2009 board!
    The R2 is unpopulated on my board, too. I just soldered a small wire to the left solder pad of R2 and connected the RTS line to DIGITAL 3. I’ll play around with the RTS support soon…

  • giox

    Awesome work!
    0.5B version now tested and found to be OK.
    Again thanks for both “quick and dirty fix” and the properly fixed one.
    Cheers
    Giox

  • Magnus

    Is the Arduino powered by USB or does it need separate power?
    I have ordered one and hope I can solve this and reflash my DTV.

    I failed to flash it from PC the last time so I had to flash it via a original 1541.
    That took a little while 😉
    Now I´m adding a uIEC to it and will build it into a new case and I am not satisfied with all the games
    flashed to it plus I wan´t to add CBM Filebrowser in the flash file.

  • Magnus

    Is this blog active?

    Why do I need to connect pin9 on the DB9?
    It has no connection on the DTV.

Leave a Reply