Added a MMC2IEC to my DTV64

Easter time is project time 😉 I spent the free days with working on some of my C64 hardware projects… This time I added a SD-Card based virtual 1541 Floppy emulator to my DTV mod. I integrated Lars’s MMC2IEC Project that implements this HW floppy with an Atmel ATmega32 microcontroller and just a few more parts (available for a few bucks).

Here is how I built it and how to use the Mac as a development system for the AVR controller…

Hardware

My DTV mod uses a small plastic box as a housing and I wanted to integrate the MM2IEC board inside this case. I came up with the idea to set up the circuit board on the top (and free) side of the case. I use a prototype circuit board and a DIP version of the AVR to build the board:

The SD/MMC-Card connector is a surface mounted version from my local electronics store that I simply glued to the top case. On the left are the two status LEDs, also glued to the top case. Both the SD Card and the LEDs are wired with a 10-pin circuit board connector to the MMC2IEC board.

On the top left side of the board is a 10-pin connector wired up as an ISP port, used to program the flash ROM of the AVR controller. The connector fits directly to the USB ISP programmer called mySmartUSB I use to program the chip directly via USB from my Mac (see below).

On the bottom right side of the AVR is a 10-pin connector that is used as connection to the DTV on the other side of the case. It includes 2 pins for 3.3V power supply and ground, a reset pin to reset the IEC emulation and the 3 control lines for the IEC bus.

Here you can see the full DTV mod with both case sides side-by-side and alread connected:

On the rear side of the DTV box I added two new components: a IEC reset button and a power switch for the MMC2IEC. Both components are wired on the bottom case side and connected to my I/O board already found there. The connector from the MMC2IEC board uses the reset trigger from there. The 3.3V is taken from the DTV main board and passed to a connector array on the I/O board (on the left side) where it is switched by the back power switch. The switched voltage is then fed to the MMC2IEC by the connector. The IEC power switch allows me to disable the MMC2IEC virtual floppy and to use a real 1541 connected to the IEC connector.

Here is a snapshot of the new front side with new the SD slot and the two status LEDs of MMC2IEC:

This is the new flipside with the IEC reset and MMC2IEC power button:

Software

The MMC2IEC requires a firmware in the flash ROM of the ATmega32 to run. Here is a summary of the steps required to cross-compile the c-source for the board and how to transfer it.

The source of the MMC2IEC is available on Lar’s MMC2IEC Download Page. Download and unpack it. The included Makefile requires a gcc cross compiler called avr-gcc.

Till Harbaum has written a nice tutorial MacAVR development on Mac OS X on how to set up a AVR gcc environment on your Mac. With his tutorial all the required tools are built and installed in a few minutes.

With the AVR tools now in your PATH, a simple make in your shell will build the final firmware hex file. I had to comment out the DEBUG=dwarf-2 in the makefile because my compiler did not support this format.

To burn the firmware into your ATmega you need the following set up: Disconnect the MMC2IEC from the DTV board and also disconnect the SD-Connector with the LEDs. Now the MMC2IEC board is powerless and has no connection to peripherals. Hook up your ISP-USB adapter (mySmartUSB) in the ISP port and configure the adapter to supply power for the ATmega (see the adapter manual). Now connect the ISP-USB to your Mac via USB and you are ready to burn the firmware…

For ISP programming I use the great avrdude. Just compile and install it. The makefile already has a make program rule. You only need to adjust some parameters (your mileage may vary):

AVRDUDE_PROGRAMMER = avr910
AVRDUDE_PORT = /dev/cu.SLAB_USBtoUART

make program runs avrdude to program the flash:

avrdude -p atmega32 -P /dev/cu.SLAB_USBtoUART -c avr910 -U flash:w:mmc2iec.hex

I use the following UART Driver to access the mySmartUSB programmer on my Mac.

If you successfully flashed the ATmega you are almost ready to go… Almost, as you need to set the FUSE bits in your AVR correctly otherwise the whole thing won’t run! Setting these bits is a bit tricky, but AndyDTV showed it nicely on a Forum 64 Post:

[ ] OCDEN
[ ] JTAGEN // disable JTag
[x] SPIEN
[ ] CKOPT
[ ] EESAVE
[x] BOOTSZ1
[x] BOOTSZ0
[ ] BOOTRST

[ ] BODLEVEL
[x] BODEN // enable Brown-out-detector
[x] SUT1 [ ] SUT0
[x] CKSEL3 [ ] CKSEL2 [x]CKSEL1 [x]CKSEL0 // 8 Mhz internal

These values can be converted into an avrdude call for the first time initialization of the device:

avrdude -p atmega32 -P /dev/cu.SLAB_USBtoUART -c avr910 -U lfuse:w:0x94:m -U hfuse:w:0xd9:m -U flash:w:mmc2iec.hex

If the FUSE bits are set up correctly then you are ready to go: Power on and cross your fingers 😀 If everything went well the two LEDs blink shortly and from now on the inserted SD-Card responds to device 8 in your DTV. Copy your favorite programs onto it and enjoy them on your DTV. (Have a look at the MMC2IEC manual for a description how to use D64 images…)

Now I will enjoy my new virtual drive, check out some games and later on will have a look on the MMC2IEC source to see what can be hacked there 😉

2 thoughts on “Added a MMC2IEC to my DTV64

  1. Hi, on my setup (Mac Snow Leopard + mySmartUSB MK2) I always have to disconnect the programmer from the USB after running avrdude. If I try running avrdude two times in a row the serial connection times out. Looks like avrdude isn’t resetting the port correctly when it exits. Have you experienced similar issues?

Leave a Reply