Go Down

Topic: Using a Bus Pirate as an Arduino programmer? (Read 19474 times) previous topic - next topic

CoytHV

I am only 16, but I have a lot of experience with microcontrollers. I need an Arduino for a project. I have never used one before, but I have a couple friends who highly recommend them. It does need to be embedded. I want to get two ATmega328's with the Arduino Bootloader to use in my project. I know that I also need a USB to Serial converter to program the chips with the Arduino Software. I was originally going to get the FTDI basic breakout board from Sparkfun, but I then started looking at the Bus Pirate. Can you use the Bus pirate in Transparent UART mode to program the plain ATmega328 chip with the Arduino Bootloader? The Bus Pirate is more expensive than the plain FTDI breakout board, but I could use it for many other projects as well. The only problem that I see is that the FTDI breakout board has TX, RX, CTS, DTR, PWR, and GND, where the Bus Pirate only has TX, RX, PWR, and GND. Does the Arduino really need the CTS and DTR to function?

Thank you!

mowcius

the DTR is the digital reset, can't remember what the CTS is...

You don't need either. You will just have to press the reset button before you upload the sketch this way.

Mowcius

intermelt

I just created a breakout board that programs an Arduino from the Bus Pirate.

First make sure you have the latest firmware on the Bus
Pirate and the latest version of AVRDude.

You connect the MISO and MOSI pins to the MISO and MOSI pins on the Atmega328.  

The SCL/CLK of the Bus Pirate connects to the SCK pin of the Atmega328.

Then connect GND and 3V or 5V to the Atmega328 GND and VCC.  Connect VCC of Atmega328 to AVCC.

Connect CS of Bus Pirate to reset pin of Atmega.  Add a 10K ohm resistor from reset to VCC on Atmega.

This will allow you to program it as long as it is running with the internal oscillator. Add a 16MHz crystal if you need to program one that has the internal oscillator disabled.

Then when using AVRDude, specify buspirate as the programmer.  Or edit boards.txt for Arduino IDE.
Jeff K - JKDevices.com - home of the MegaMini

intermelt

Jeff K - JKDevices.com - home of the MegaMini

CoytHV

#4
Jun 04, 2010, 03:47 am Last Edit: Jun 04, 2010, 03:54 am by CoytHV Reason: 1
Thanks Guys,

That is exactly what I needed. I just ordered the chips and Bus Pirate today.

@ Jeff K, I love the breakout board; I will definitely be recreating it for my Arduinos. I am not sure what you mean by editing boards.txt for the Arduino IDE. I will be using the Arduino IDE, so can you explain what I need to do to this file? I also noticed your amateur radio call sign under your username: KB9SXU. I am an amateur radio operator as well: KJ4AWM.

intermelt

Essentially you need to tell the Arduino environment that you are not using the normal bootloader in the Arduino to load the program into the chip.  The boards.txt file is a configuration that tells what parameters need to be passed to AVRDude for programming.

I haven't actually tried it yet, but I will play with it tonight or tomorrow and let you know how it needs to be setup.
Jeff K - JKDevices.com - home of the MegaMini

CoytHV

I am still not sure if I understand.

I bought two ATmega328 chips with the Arduino Bootloader already installed as well as the matching external 16mhz oscillators.

I thought that all I needed was a simple USB to TTL Serial connection to program the chips with the Arduino IDE. I was going to put the Bus Pirate in Transparent UART bridge mode with open collector output and pull up resistors in place for 5 volt operation.  I thought that the bus pirate would then become a virtual com port or something, and all I would have to do is set the correct com programming port in the Arduino IDE before I loaded a new program to the Arduino chip. Is this correct?

Your advice about the hardware setup was great; I was unsure about how to setup the (SCL/CLK -> SCK) and the CS to Reset pin. I am assuming that this solves the automatic reset problem that the CTS and DTR normally take care of on normal USB to Serial converters.

Basically I am just trying to convert the Bus Pirate into a USB to TTL Serial converter for programing the Arduino just like this:

http://www.sparkfun.com/commerce/product_info.php?products_id=9115

Will this work, or do I still need to edit some config files and use AVRDude?  



intermelt

The way I have the Bus Pirate setup you don't really need the bootloader.  It will flash the Atmega directly.  I am not using it the way you described.

The way you describe, I don't think you would need to change any configuration settings.

The way I am doing it requires adding some configuration settings that tell avrdude you are using a different programmer and no bootloader.

This has some advantages over doing it the way you originally described.

1. You don't need a bootloader which in turn allows you to have 2K of extra program space.
2. You can always put the bootloader back if need be.
3. You can change the fuse settings if need be.

I did experiment with the settings in boards.txt and did get it to function correctly.  It is very simple to setup.  I will have a tutorial up tomorrow with detailed instructions.

Also I will experiment with Transparent UART bridge mode tomorrow and let you know if I can get the reset to somehow work or not.

Personally I would use the way I describe to program the chip and then the UART Bridge for any serial monitoring you need.
Jeff K - JKDevices.com - home of the MegaMini

CoytHV

Ok I am starting to understand, but I am still lost in a couple areas.

It seems that you are using ATmega328 Chips with NO Arduino Bootloader in them. Then you are using the Bus Pirate as a hardware programmer to interface the ATmega328 with AVRDude software programmer. Like This? : http://hintshop.ludvig.co.nz/show/buspirate-avr-programming/

Is this correct?

What I still don't understand is how you can use the Arduino IDE to program the ATmega328 chips that don't have the Arduino bootloader. I thought that the Arduino bootloader was a piece of code (a type of compiler) factory programed into the ATmega328 chip to turn it into an Arduino. I thought that this bootloader interpreted the simple basic code from the Arduino IDE  and let the ATmega328 chip carry out the commands correctly. If you do not have this Bootloader, how does the Arduino IDE work with the regular ATmega328 chips?

Is this why you have to use AVRDude? If so, I thought AVRDude was just a programmer system; how does it convert the code from the Arduino IDE into the code that the plain ATmega328 chip needs?

My overall question is now how are you interfacing the Arduino IDE with AVRDude to allow for programing plain ATmega328 Chips that lack the Arduino Bootloader?  

Thank you for all the help :)

intermelt

Yes it is similar to the link you sent.

The bootloader doesn't interpret the code... it is a simple program on the chip that allows it to load a program over it's serial port.

The Arduino IDE compiles the code into a hex file(using avrgcc I think) that is native to the processor it is loaded on.  It then runs AVRDude in the background to load that hex file onto the chip.  The Arduino IDE doesn't care how it gets to the chip as long as AVRDude has the capability of putting it there.  

This is where the configuration change is required.  The bootloader on the chip looks like a type of programmer to AVRDude.  We need to tell the Arduino IDE that we are using a different programmer so it can tell AVRDude that we are using a different programmer.

So you can think of the Arduino IDE just an interface to multiple programs that take care of compiling your code and loading it onto the chip. That is a simple explanation leaving out a lot of details.  And the booloader is just a programmer built into the chip. (but requires the correct serial port to talk to the computer)

It will make more sense when I get my tutorial up tonight.
Jeff K - JKDevices.com - home of the MegaMini

CoytHV

Great! I get it now. You explained exactly what I didn't understand.

So the Arduino IDE is just an interface to the avrgcc tool chain in a very simplified way. I can't wait to see your tutorial. Please post a link when it is complete.

Thanks!


intermelt

OK... The first half of the tutorial is done...
http://www.jeffkarney.com/2010/06/how-to-program-atmega328p-with-bus.html

I will try and get screenshots and the rest of the tutorial up tonight or sometime tomorrow. But let me know if you have any questions or anything seems unclear so far.
Jeff K - JKDevices.com - home of the MegaMini

CoytHV

Looks great so far. I am currently on vacation so I cannot try it, but I will once I get home. I read it over, and it seems very clear. I already purchased two ATmega328's with the Arduino bootloader, so If I want to use your programming method, what is the easiest way to delete the bootloader off of the chips?  

intermelt

Thanks.

I'm not sure what will happen to the bootloader if you try and write to a chip with one.  It will either leave the bootloader and write to the rest of the chip like normal or write over the bootloader.

I think it may depend on the fuse settings in the chip.  I will have to do some research on that.  Either way, you can always reload the bootloader with this method if need be.
Jeff K - JKDevices.com - home of the MegaMini

CoytHV

#14
Jun 05, 2010, 10:58 pm Last Edit: Jun 05, 2010, 11:29 pm by CoytHV Reason: 1
Ok that makes sense. I will test it too and see what happens.

I had another idea about how to use the programming configuration we have been discussing.

If you can program the ATmega328 without the Arduino Bootloader, what prevents the programming of almost any AVR MCU with the Arduino IDE using the Bus Pirate as the programmer?

For example, the ATmega2560 is the same chip that the Arduino Mega uses, but it has twice the memory. A while ago I was working on a project that was going to use this chip. I was planning to use the AVR-GCC tool chain to program it, but using the Arduino IDE would have been much easier (I think?). Anyway, would I have to change config files in the Arduino IDE to allow the Extra program memory in the ATmega2560 to be used?

Also, if this could work, wouldn't I be able to program small chips such as ATtiny series and just make sure I didn't load them past their memory capability?

I am guessing that it is more complicated than I would like it to be, but it would be very cool if you could program all AVR chips with the Arduino IDE. Do you have any idea how this could be configured to work? I guess I am asking how hard is it to make other chips compatible with the Arduino IDE?

Go Up