Go Down

Topic: Programming Atmega328 on pcb (Read 1 time) previous topic - next topic

paulsoulsby

Hi,
I'm successfully using an Atmega328 with arduino boot loader on a pcb as documented in various tutorials (crystal, 22pf caps etc).
I need to be able to reprogramme the atmega from the Arduino IDE. However my circuit already uses the reset pin (for an external reset button) and rx/tx pins  (for MIDI in/out).  I can't move the midi to other digital pins as I've already got something attached to every pin!
What's the best way to reprogramme it without removing it from the dil socket and putting it in an arduino?
Would it be a 2 pole 2 way switch on tx/rx lines? Do I also need control of the reset pin for programming? In which case would it need a 3 pole 2 way switch? I'm imagining one side of the switch would go to my circuit and the other would go to a pcb header socket which could connect to my arduino via a lead.  Are there any other pins on the atmega that would need switching?

PeterH

You do need to provide a reset capability. This could be as crude as you pressing the reset button at the right time, but that would be pretty tedious. All you need is some way to pull the reset pin low. I assume that the reset switch you have connected is a simple normally-open switch. In that case there's nothing to prevent you from connecting another wire to the same pin and use that to trigger a reset - no need to isolate the other reset switch.

If you have another Arduino then you can program your chip via the ICSP interface instead of the Rx/Tx pins. There is a standard 'Arduino as ISP' sketch to support this. Because it involves using two Arduinos it's a little bit more complex than straight forward programming via a serial connection, but only a little bit - once you've figured out how to do it, it's not difficult.

mr_electric

PeterH is exactly right. You would absolutely need the reset pin, but you could get away programming the atmega using icsp. You'd need to use some kind of header to connect it to the programming arduino and I'd recommend soldering a 3 pin jumper (something like what you'd find on a of motherboard) to toggle the reset between your board and the programmer (if you need to isolate it, that is). Programming it is a breeze, just make sure the ArduinoISP sketch is on your arduino (Examples>ArduinoISP), the target board is connected via icsp and all you need to do is make sure atmega328 (arduino UNO) is selected under the boards menu and hit "Upload using a Programmer" (File>Upload using a programmer)

Hope this helps!
Cheers!
Mr_E

paulsoulsby

Great thanks for the info. Yes of course there's no need to switch the reset, can't believe I didn't work that one out!! Love the idea of the 3 pin motherboard style header.  I have a suspicion that I can't use the icsp header but will check. I've got rotary encoders, 16 output expansion ICs etc etc connected and I think one of these things stops me using the icsp. But I will double check.
Paul

mr_electric

Yeah, you should go ahead and check. Alternatively, you can add a couple more headers for the rx and tx lines and scrap the icsp alltogether. Then something like a 3 pin connector could be used to transmit data.

Cheers!
Mr_E

Go Up