WiFi Programmer for Atmega

Programming MCUs such as Atmega8 etc. is very easy thru gadgets like USBASP etc, but these have some drawbacks. I will make a general purpose programmer which can also program PIC and Attiny chips. Following are my initial requirements:

Basics: Relays

I was originally planning to use a PC power supply, but those things are very bulky and I don't need that much power for the programmer because I will have separate power supplies for the programmer and the target board. It's much easier this way.

The target board (TB) can be designed to run at any voltage. The target MCU will have its own power lines, separate from the rest of the circuit. This will let me disconnect the MCU from the TB power and connect it to the programmer power supply.

I will use two relays for this. The first one will simply switch VCC to target MCU on and off. The second one will connect the target MCU to either the programmer power lines, or the TB power lines.

Another pair of relays will connect/disconnect the RESET, SCK, MOSI and MISO lines.

For smaller Atmegas, I will make another daugtherboard and simply disconnect all lines from the target circuit.

First Attempt : 0.1

Here is the very first version. It doesn't do any programming, it's just an empty platform on which I can build the programmer.

The device stores the WiFi SSID and password on the MCU EEPROM. When you start it up with the DIP switch at PD2 in the on position (reading low), it goes into web configuration mode. In this mode, you can set the WiFi SSID and the password. In order to do that, you first need to connect to the WiFi network displayed on the screen, the ESP8266 operates in access point mode when you boot it up like this. The default SSID and password for this are "wifiprog" and "hunter2". After this, you can browse to the displayed IP address (at port 1011) and set the SSID/passwd pair for normal mode.

In normal mode (DIP switch off), the ESP8266 operates in station mode and connects to the given network just like any other device.

The accompanying host software can configure the SSID/password pair for configuration mode. This is only active when the device is in normal mode.

Second Attempt : 0.2

Here is the second iteration. This version is able to change the baud rate used between the ESP8266 module and the programmer MCU. I use a 11.0592Mhz crystal to clock the MCU. This gives me the ability to use any standard baud rate without any errors stemming from the USART clock divider.

The circuit seems to work fine at 115200bps. The Atmega328 data sheet suggests that I could go even higher to 690Kbps but I don't dare. With this crystal at 115200bps, the interrupt routine needs to run within 768 cycles, which it does with room to spare. I'm not even sure that the ESP8266 supports higher rates, this is the highest I've seen being discussed. Also, writing a 32K program to the target will take about 2.3 seconds with this rate so I'm happy with it. In any case, it seems to work fine at high rate and I could reduce it if necessary later on.

The firmware stores the last set baud rate in EEPROM. Upon reboot it tries to establish contact with the wireless module at that rate. If this fails, it goes thru a list of rates, trying to get a meaningful response to the command "AT". When this happens, the rate gets stored in the EEPROM and communication continues at this rate.

Third Attempt : 0.3

Here is the third iteration. I fixed a bug in the firmware upload function. I did an upload of the firmware thru wifi in 7.5 seconds. This number includes 10ms delays for the 24xx256 chip. These could be eliminated if it bothered me too much, but I don't really care.

It's pretty impressive compared to the usbasp result, which was 19 seconds. I think this is the final iteration of the base platform. I should get going with the programmer itself. Anyway, I can put the usbasp away for a while, the self programming seems to work fine.

Also, I made use of the second DIP switch, connected to PD3. If this switch is on, the device erases its own EEPROM (only the used parts). This is useful for when I add new variables into the EEPROM area. The addresses of the variables change when I do that and they need to be reset. When the device boots like this, it simply goes into an infinite loop without doing anything. You just need to reset it with the DIP switch off.

First Release : 1.0

Here is the first version of the package which can actually program something.

I wrote it for both Atmega8A and Atmega328P chips but tested only with the 328 so far.

The following are the things I didn't implement for it:

I really have no use for these features, but they might become necessary later, especially the EEPROM page access stuff. We'll see.

This package also includes a USB programmer. I had written it to debug the serial communications with the ESP8266 module and to develop the programming routines. There is nothing left in it to transfer over here so I will remove it in later releases.

Links