Pages: [1]   Go Down
Author Topic: Programming options for standalone ATMEGA328p project  (Read 1019 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello all:

I am building a project, and there is very limited physical space in it.  As a result, I am planning on using a standalone ATMEGA328p microcontroller.  Also, in my project, there is no room for a socketed ATMEGA328p, so I will be soldering it in directly, so this needs to be considered (thus, I cannot pull the chip out to program it).  I would like to be able to reprogram the chip after building it into my project.  I also need as many GPIOs as possible. 

My question is about my programming options. 

From what I have researched, I have the following options:

1) If I use the bootloader, then I can program the chip using RX/TX (D0 and D1), thus leaving all other GPIOs free.  I then, however, will need to be able to program the chip using a serial cable or something similar (which sounds like a big pain).

2) If I program using an ISP (I have a USBASP), I will tie up D11, D12, and D13 and thus lose those as GPIOs, right?  Or can I use them to program the chip and then use them as GPIOs in the sketch?  Also, can I use D0 and D1 as GPIO in this option?  I am leaning towards this option, just because it seems much easier to program the chip, but I hate losing 3 GPIO pins D11, D12, and D13.  Being able to use D0 and D1 (as outputs) would help a lot.

Can anyone help, or give me other things I have not considered?  Or, correct me on any misunderstandings I have?

Thanks!
Logged

Wahiawa, Hawaii
Offline Offline
God Member
*****
Karma: 29
Posts: 582
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can use the ISP pins for general i/o.  That's how the Arduino boards are designed.  You will need to follow some design guidelines for multiple uses.  Check out http://www.kanda.com/avr-isp-circuits.html

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, thank you!  That's just what I was looking for.  I tried many internet searches, but couldn't find anything related.

Based on the info on the site, it looks like I can do it, but should install 4k7 resistors to protect the rest of my circuitry.  It also states that I can use the D0 and D1 pins (RX and TX), especially since I'm not using them for serial connections anyway.

There's one problem, though.  If I plan on using one of the ISP programming pins to drive an LED (with a 100 ohm resistor), then I can't use a 4k7 resistor, since that will affect the LED brightness, and this is important for my application.  In this case, will the 100 ohm resistor be "good enough" to protect my device circuitry?
Logged

Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

According to Atmel's design guidelines, protecting the programmer is only an issue if you have something else on the SPI lines that is trying to actually drive those lines.  If the AVR is the only device driving the lines, then the resistors aren't needed.  I run LED strings driven by the SPI bus like that, no resistors needed because the strings themselves aren't driving the lines, only the AVR does.  And when it resets, those lines go in tri-state mode anyway.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Great, thank you!  Just what I needed.
Logged

0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 394
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just a quick comment.  You said:
"1) If I use the bootloader, then I can program the chip using RX/TX (D0 and D1), thus leaving all other GPIOs free.  I then, however, will need to be able to program the chip using a serial cable or something similar (which sounds like a big pain)."

On the contrary,  this method works extremely well, assuming you wish to write & debug Arduino code.  I have yet to discern any "pain".  Vendors such as Sparkfun sell these as usb/serial adapters for a modest price.  You do need to provide the 6-pin header on your 'homemade' Arduino.  I do this all the time.

Joe
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Joe:

I researched that I could about the serial method, and it seems complicated to me for the following reasons, which maybe you can clear up for me:

1) microcontroller needs to be bootloaded (but with what version of bootloader?)
2) I need something like an FTDI breakout board
3) I have found websites that show how to hook up the connections, but none (that I can find), actually show how to program from there using the IDE.  In my Arduino IDE there's an menu option for "Upload using programmer", which I assumed I could not use if using the FTDI breakout board, since it's not a programmer.  In the Tools->Programmer sub-menu, there's USBasp (which I have), but I cannot find what I would set this to if using the FTDI breakout board.  This whole part seems fuzzy to me.

If you can clear some of this up for me, I would appreciate it!
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 519
Posts: 26387
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this

http://www.gammon.com.au/forum/?id=11635
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Wahiawa, Hawaii
Offline Offline
God Member
*****
Karma: 29
Posts: 582
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For Serial upload programming (the Arduino bootloader method):
1) Yes you will need a bootloader.  Optiboot would be recommended.
2) Yes, you will need some type of FTDI device.  You can use a FTDI cable.
3) Connections will be similar to how the Arduino Ethernet board works.  It has a 6-pin header for VCC, GND, TxD, RxD, RTS, and CTS (not used).  The RTS signal will tie into the auto-reset for the m328P.
This is exactly how the Arduino Duemilanove uploads, except you have separated out the FDTI interface from the board.  The Uno is similar except they use a different type of USB to Serial chip.  So it is the normal Upload from the IDE.

For ICSP programming (direct ISP method):
The "Upload Using Programmer" is only for ICSP programming.  Requiring a ISP programmer (USBasp, USBtinyISP, AVRISPMKII, ArduinioISP, ...).  Which you could also easily breakout a 6-pin header for ICSP programming without needing the bootloader.

So you could do either method, both are doing some kind of USB to serial conversion.  One talking to the bootloader, the other talking directly to the AVR chip.  Either method still requires at least a 6-pin header, your choice.


Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 223
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

ICSP is the standard way to program a standalone atmega328pm, and what I always use. My only gripe is that the standard 6-pin ICSP header is rather large, in fact for ATtiny designs it is sometimes the largest component on the board. Anyone got any ideas for a smaller 6-pin connector that I could standardize on?

As has already been said, you can use the 3 ICSP i/o pins for normal I/O. The considerations are:

- Whatever they are connected to must not interfere with the signal from the programmer. So you could one to connect a push button (as long as you don't press it during programming), but not to most sorts of sensor that will drive the pin high or low; and not to an output device that places too much load on the pin.
- Whatever they are connected to must not be adversely affected by the signal from the programmer. So using those pins to drive an LCD display would be OK, but using them to drive a motor is probably a bad idea.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK.  Thanks to everyone for the additional information.

I will probably go the ISP way since I already have that equipment. 

Again, thanks to everyone.  I definitely learned a lot more, but I'm sure there's many details I don't understand yet and won't until I actually build it. 
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 519
Posts: 26387
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

For a smaller connector, use a JST 1.5mm 6 pin connector and make a programming adapter cable.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 394
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I researched that I could about the serial method, and it seems complicated to me for the following reasons, which maybe you can clear up for me:

1) microcontroller needs to be bootloaded (but with what version of bootloader?)
2) I need something like an FTDI breakout board
3) I have found websites that show how to hook up the connections, but none (that I can find), actually show how to program from there using the IDE.  In my Arduino IDE there's an menu option for "Upload using programmer", which I assumed I could not use if using the FTDI breakout board, since it's not a programmer.  In the Tools->Programmer sub-menu, there's USBasp (which I have), but I cannot find what I would set this to if using the FTDI breakout board.  This whole part seems fuzzy to me.


Yes you should install Optiboot on the 328. Several methods are well described using an UNO board. 
The FTDI breakout board and similar devices are simply moving the usb-->serial hardware off the Arduino board which makes it smaller and cheaper.  Upload programs the same way you program your UNO.  In fact I usually tell the IDE that my homebrew circuit is an UNO and it works AOK.  This method is used by the Arduino Pro mini 328 and similar small boards which have no USB intefrace.

I have the USBTiny fro Adafruit for burning bootloaders but you can use an UNO directly for this purpose.



Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I researched that I could about the serial method, and it seems complicated to me for the following reasons, which maybe you can clear up for me:

1) microcontroller needs to be bootloaded (but with what version of bootloader?)
2) I need something like an FTDI breakout board
3) I have found websites that show how to hook up the connections, but none (that I can find), actually show how to program from there using the IDE.  In my Arduino IDE there's an menu option for "Upload using programmer", which I assumed I could not use if using the FTDI breakout board, since it's not a programmer.  In the Tools->Programmer sub-menu, there's USBasp (which I have), but I cannot find what I would set this to if using the FTDI breakout board.  This whole part seems fuzzy to me.


Yes you should install Optiboot on the 328. Several methods are well described using an UNO board. 
The FTDI breakout board and similar devices are simply moving the usb-->serial hardware off the Arduino board which makes it smaller and cheaper.  Upload programs the same way you program your UNO.  In fact I usually tell the IDE that my homebrew circuit is an UNO and it works AOK.  This method is used by the Arduino Pro mini 328 and similar small boards which have no USB intefrace.

I have the USBTiny fro Adafruit for burning bootloaders but you can use an UNO directly for this purpose.


Thank you!  I'm glad you mentioned Optiboot, because I've never heard of it before, but it looks cool, and it looks like several in this thread recommend it, so I'll give it a try.  Their website definitely makes it look like a very smooth process to use it.

I'm so glad all you guys are here.  It would have taken me 10,000 years to figure all this stuff out.
Logged

Pages: [1]   Go Up
Jump to: