Tag Archives: avrdude

ReadyAVR-64 – A board without documentation

I recently purchased a Atmel ATmega128 breaout board designed by LogiFind, called the ReadyAVR-64. The company seems to be imitating Mikroelektronika with their naming conventions and produce intermediately priced educational boards. They provide some examples and software, oriented around Windows as a host platform for most of their boards. I have a couple of examples for there wares, from the giant “EasyAVR128” to the more basic “ReadyAVR-28” (which I plan to swap a ATmega328 into – they do a board with one pre-installed, but it costs more). Currently, the documentation download link on their website for their ReadyAVR-64 board seems to be broken.

Despite being a blue PCB in all adverts etc. the board I received in the post was green. I had some minor postage issues, with my package been returned to sender for an unknown reason, but the seller was very honest and quick responding and the item arrived by airmail a few days after I reported my concerns.

ReadyAVR-64
ReadyAVR-64

Upon getting my board in the post, the first thing I did was swap out the crystal oscillator for a turned pin socket. There are two reasons for this – firstly the pre-installed crystal was an odd speed (7.3728mhz – I prefer 16mhz), and secondly, a socket means I can change the speed as I wish. Making this change requires your usual component desoldering – I used some flux, an iron and some solderwick – once the crystal was out of the board I finished clearing the holes with a solder sucker. Break off a 3 long piece of turned pin female header and solder it in. You don’t even need to remove the middle pin as there is an unconnected hole already on the PCB.

The next thing I did was replace the pre-installed bootloader with a variant of optiboot. I can’t remember exactly where I got it, but the hex file is here. This USB bootloader uses the PE1, PE0 serial port and so I had to switch the jumpers on JP2 for it to work. Loading in the new bootloader is done through the ISP6 or ISP10 ports. I used my STK500 with AVRdude, as I’ve had some difficulties programming AVR128s with my usbasp in the past. It should be possible to follow “Arduino as ISP” instructions to reflash the board. I wont go into depth here. At some point I’ll write a guide to reflashing bootloaders onto AVRs, but there are already a lot of guides out there. For reference, I used the following two AVRdude commands to setup the bootloader and fuses on my board :

avrdude -p m128 -c STK500 -P /dev/ttyUSB0 -u -U flash:w:optiboot_atmega128.hex
avrdude -c STK500 -p m128 -P /dev/ttyUSB0 -U lfuse:w:0xff:m -U hfuse:w:0xc6:m -U efuse:w:0xff:m

At this point, if you wish to program the board using the Arduino IDE, you will need to install MegaCore. This adds extra microcontrollers, including the ATmega128 to the boards menu in the Arduino IDE. Installation is described in the “How to Install” section of the linked github page.

As I couldn’t find any documentation on the board due to the broken download link, I experimented and followed traces on the board until I worked out the following. Note that the LEDs are Active Low (setting the connected pin on the microcontroller to High turns them off).

  • LED0 = Arduino Pin 28 (PC0)
  • LED1 = Arduino Pin 29 (PC1)
  • LED2 = Arduino Pin 30 (PC2)
  • LED3 = Arduino Pin 31 (PC3)
  • BOOT = Arduino Pin 37 (PA7)

The Joystick is connected to Port B, but required the chip’s internal pullups to be enabled before it works correctly. One way this can be done in the Arduino IDE is by using digitalWrite to set the pin HIGH after having set it to be an input. Connections are as follows :

  • Joystick Up = Arduino Pin 9 (PB1)
  • Joystick Down = Arduino Pin 11 (PB3)
  • Joystick Left = Arduino Pin 10 (PB2)
  • Joystick Right = Arduino Pin 8 (PB0)
  • Joystick Click = Arduino Pin 12 (PB4)

Note that when you trigger two options at once, say for up and right, or left and click, all 5 pins trigger. The joystick connections are also Active Low, meaning the input goes low when the joystick is triggered.

The following Arduino example shows the functionality of both the LEDs and the joystick.

int LEDS[] = {28,29,30,31,37};
int Inputs[] = {8,9,10,11,12};

void setup() {
  for(int x = 0; x<5; x++){
    pinMode(LEDS[x], OUTPUT);
    digitalWrite(LEDS[x], HIGH);
  }
  for(int x = 0; x<5; x++){
    pinMode(Inputs[x], INPUT);
    digitalWrite(Inputs[x], HIGH); // enable pullup
  }

  int LED = 0;
  while(LED<5){
    pinMode(LEDS[LED%5], OUTPUT);
    digitalWrite(LEDS[LED%5], LOW);
    delay(250);
    digitalWrite(LEDS[LED%5], HIGH);
    delay(250);

    LED++;
  }
}

void loop() {
  for(int x = 0; x<5; x++){
    if(digitalRead(Inputs[x])==LOW){
      digitalWrite(LEDS[x], LOW);
    }else{
      digitalWrite(LEDS[x], HIGH);
    }
  }
}

Using AVRprog2 and an EasyAVR5A with the Arduino IDE

Using AVRprog2 and an EasyAVR5A with the Arduino IDE

A few years back I bought myself a mikroe EasyAVR5A from the discount bin of an online store. Sadly, at the time, there was no way to use the built in USB programmer from any OS other than Windows, so I resorted to programming the board through a USBasp.

The mikroe EasyAVR5A
The mikroe EasyAVR5A

Jump forwards a while and a helpful university produced a Linux (and Mac) program compatible with the built in USB programmer. This can be found here. I have been using this software for a while and am very happy that it exists. To use it with the Arduino IDE, you need to add the MCUs you’re using (if you use an ATMega328p you can skip this as it is the standard chip in an Arduino Uno, although you will need to add it to the list of xml files which describe chips for the AVRprog2 software, described later for the ATMega32), build the project with “verbose” turned on in preferences, copy the path to the final mentioned .hex file, and paste it into the command line with the command to program the board. A little bit of a faff.

The mikroe AVRprog2
The mikroe AVRprog2

Messing about today I set myself a little challenge to see if I could add the avrprog2 program as a programmer within the Arduino IDE – I managed to get it working, so here are the directions on how. This should apply to other boards that use the mikroe AVRprog2 interface (labelled as AVRprog on the board, which causes confusion as there is a parallel interface programmer called the same).

1. Download, compile and install the github avrprog2 project. You can mostly follow their instructions, except you have to run autogen.sh before anything else (otherwise the configure script doesn’t exist). The listed dependencies are not helpfully named (some aren’t the package names), but a bit of googling gets it working. For reference, I ran the following commands to install :

sudo apt-get install libusb-1.0-0-dev
sudo apt-get install binutils-dev
sudo apt-get install libboost-all-dev
sudo apt-get install doxygen
sudo apt-get install graphviz-dev
sudo apt-get install graphviz
./autogen.sh
./configure
make
sudo make install

2. Open the folder called “config”. Copy, then edit the file “atmega16.xml” to a file called “atmega32.xml” and then replace the contents with the following :

<device>
	<name>ATmega 32</name>
	<signature>0x1e9502</signature>
	<flashSize>32768</flashSize>
	<flashPageSize>128</flashPageSize>
	<eepromSize>1024</eepromSize>
	<numOfFuses>2</numOfFuses>
</device>

You don’t need to do this if you don’t plan to use the ATMega32A part, but I did and might as well include it. Once edited, save and copy to the folder “/usr/local/share/avrprog2/”. You’ll need super user permissions to do this.

I’ve uploaded a few more config files in this post. Note that I’ve included the default ones for reference. I’ll add more with time as I test more chips.

3. Install MightyCore as per the instructions on the github page.

4. Add the following to the MightyCore platform.txt file (mine was located in “~/.arduino15/packages/MightyCore/hardware/avr/1.0.8” – you can find the correct folder by going to Preferences in the IDE, then clicking on the link under “More preferences can be edited directly in the file…”, then navigating through ./packages/MightyCore/hardware/avr/1.0.8) :

# avrprog2 entry
tools.avrprog2.cmd.path=/usr/local/bin/avrprog2
tools.avrprog2.cmd.path.linux=/usr/local/bin/avrprog2

tools.avrprog2.upload.params.verbose=-d
tools.avrprog2.upload.params.quiet=
tools.avrprog2.upload.pattern="{cmd.path}" -m {build.mcu} -f {build.f_cpu} --flash w:{build.path}/{build.project_name}.hex

tools.avrprog2.program.params.verbose=-d
tools.avrprog2.program.params.quiet=
tools.avrprog2.program.pattern="{cmd.path}" -m {build.mcu} -f {build.f_cpu} --flash w:{build.path}/{build.project_name}.hex

I placed it above the line “# USB Default Flags”.

5. Add the following to the top of the MightyCore programmers.txt file :

# avrprog2 entry
avrprog2.name=avrprog2
avrprog2.communication=usb
avrprog2.protocol=avrprog2
avrprog2.program.protocol=avrprog2
avrprog2.program.tool=avrprog2

6. Save both modified files, restart the Arduino IDE and… you should see a new entry called “avrprog2” in the Tools>Programmer menu.

7. Load your program, select the correct MightyCore chip (the board comes with an ATMega16), select the avrprog2 and other various settings for the MCU then…

8. Shift click the Upload button. If all goes well you should see the compile and then your program loading into the chip. I find I can’t program the board twice without powercycling between, and sometimes it doesn’t find the board for some reason (but that is the same when using the programming software from the command line.

Hope someone finds these instructions useful – they have been written at speed because I have somewhere to be. I may return to clean them up and add some pictures at a later date!

Note that I’ve not currently made modifications which allow you to flash the bootloader (I’ve not done anything that writes the fuses). The following two commands seem to work for Internal 8mhz and external crystal respectively :

8mhz Internal Clock :
avrprog2 -m atmega32 --fuses w:f4,d6

16mhz External Crystal :
avrprog2 -m atmega32 --fuses w:c0,d6

Good luck!

I found this page useful while making this modification : https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification

As well as looking at the Digistump platform.txt and programmer.txt files (started by making a copy of their platform.txt contents).

I’m also thankful for a point in the right direction from blathijs on the Arduino IRC.