Pages: [1] 2 3   Go Down
Author Topic: Standalone USB communications  (Read 3787 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm about to migrate a project to standalone, but wish to be able to communicate with my new, own design, by USB to update code. I'm planning to use an Atmega1280 in a DIP package so I don't have the option of putting it on a 'normal' Arduino board.

I don't want to use a pre made board for comms, so any advice would be great. For example, could I program a 328 to do the USB to serial comms?
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 443
Posts: 23837
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

You need a chip that has USB connectivity - such as FTDI FT232RL, CP2102, ATMega8U2, ATMega16U2, ATMega32U4 (Leonardo).
Those are all small surface mount parts that can be difficult to solder.
This is the least expensive FT232 module that I have found.
http://www.mouser.com/ProductDetail/mikroElektronika/MIKROE-483/?qs=%2fha2pyFadugsEwyLV5fFyIWdPbushEDhRSvnBE0ODG8%3d

CP2102  modules on e-bay also cheap.

You can also program via USB Programmer to an ICSP header, vs USB Serial to Rx/Tx pins.

I wasn't aware 1280's came in a DIP. They are not shown on Atmel's 640/1280/2560 data sheet.

Perhaps you were thinking 1284?  Here's my Duemilanove style '1284 board, with a spot for MIKROE 483, or pins to connect FTDI Basic or similar.
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.

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

EDITED POST

So, I've reworded this reply to get to the point quicker. After taking a look around at boot loading 2560s etc, it seems it is all well beyond my knowledge. What I intend to do is use a 1284 DIP as you have done.

However, I'm not trying to build a dev board here - but rather use the 1284 in a project, while retaining connectivity with the Arduino IDE by USB. So, thanks for the reply - it seems the easiest way around this would be to use a small Atmega to do the conversion between USB & serial, 16U2 or earlier. Is the code to do this conversion publicly available?

Alternatively, are you implying I can simply get rid of onboard USB to Serial conversion and use a cable like this, that connects to ICSP pins to program the chip from the Arduino IDE?

http://www.ebay.co.uk/itm/1x-USB-2-0-TO-RS232-Converter-UART-TTL-Serial-CP2102-For-Arduino-UNO-ATMEGA-PIC-/221067324467?pt=UK_BOI_Electrical_Components_Supplies_ET&hash=item3378a3ac33

I'll list my questions;

1) The 1284 isn't listed as a board in the IDE, does this mean I cannot put the Arduino boot loader on the 1284 and program using the IDE? Same goes for the 16U2 - how would I program the required code into it to do the conversion? If however an FTDI chip would be easier, please advise

2) How do I go about boot loading the 1284?

3) I've read lots that most standalone boards like this need the reset button pressed during upload, how do I design in auto reset like normal boards, so I just have to press the upload button?

Many thanks in advance!!!
« Last Edit: October 14, 2012, 08:23:48 am by jtw11 » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 443
Posts: 23837
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

pre-question 1 - part like 16U2 that needs other parts & a ICSP header & programming is one way to go - or you can simplify design & assembly some and use a module like the one you showed, or use one like I showed. Here's an example of mine on a board that could easily have used a '1284 vs a '328.
I believe the 16U2 code is available, likely on github somewhere.  The FTDI/CP2102 parts do not need programming.



pre-question 2 -  If the final project does not need USB connectivity, but only programmability, then an offboard module is certainly an acceptable way to go.
Most of my projects are embedded into something and do not need USB interfacing, because there is no PC to connect to.  You can connect an AVR ISP such as
http://www.mdfly.com/index.php?main_page=product_info&cPath=5&products_id=415 (and there are many others) and program via an ICSP header on your board, or use a USB/Serial adapter and program via Rx/Tx interface - you can see I have headers for both on this little '1284 card intended to be embedded into a project. The ICSP is needed for sure to install a bootloader so the USB/Serial interface can be used.  But see question 2 below.


question 1 - the core files and pin definition files for the '1284 can added using maniacbug's files here
https://github.com/maniacbug/mighty-1284p
A couple of pin definitions are provided - the Bobuino attempts to follow the Uno pin usage, with Serial (0) on D0/D1, SPI on D10-11-12-13, and I2C on D18/D19 still. The others sort of start at one corner and work around the chip.
16U2 - add the other hardware to support it, and ICSP header, and program.
FTDI -same thing, add some addition hardware to support it, no programming needed.

question 2 -  an AVR ISP is needed to bootload the part. I've done enough that I found it really convenient to have an Atmel AVR ISP Mkii ($34 at mouser.com) for bootloading, or sketch downloading without a bootloader.  Nick Gammon has also developed a means to use an Arduino as an ISP programmer for the larger chips - many (all?) of the smaller ones do not support the whole programming space of the larger chips, while the MKii does.
See "program bootloader" and "upload/download .hex files" here:
http://www.gammon.com.au/scripts/forum.php?bbtopic_id=123
There have also been some very recent discussion threads suggesting the '1284 might be supported already and just the pin definitions file might be needed.
See #509 and onwards here
http://arduino.cc/forum/index.php/topic,80483.msg954816.html#msg954816

question 3 - if you install a cap between the serial downloader's DTR pin and the 1284's Reset pin then the download software can create the needed reset.
The reset pin will also have a 10K pullup to +5, and a diode in parallel (cathode to reset, anode to +5).  The CP2102 module can be modified with one trace cut and one jumper addition to bring the DTR signal out - make sure to use one that has DTR available at a breakout hole on the side. The FTDI parts have DTR available without a mod.
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.

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
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

Alternatively, are you implying I can simply get rid of onboard USB to Serial conversion and use a cable like this, that connects to ICSP pins to program the chip from the Arduino IDE?

Yes, if your project does not need USB connectivity, you can upload your sketch using ICSP. You don't need a bootloader. This is what I always do when I migrate projects to dedicated hardware. Put a 6-pin ICSP header on your board. You need either an ISP (e.g. the AVRISP MkII), or you can configure an Arduino to be an ISP by uploading the ArduinoISP sketch to it.
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.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 443
Posts: 23837
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

dc42 - since you seem to be online - offtopic: can you point me to something where main(){} is discussed, how its hidden? Trying to find it, not having luck with forum searches, and I know its been discussed here.
Thanks
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.

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
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

Hi Crossroads,

I've not see main() discussed in the forum, however the source code is in C:\arduino-1.0.1\hardware\arduino\cores\arduino\main.cpp under Windows. The Arduino IDE causes it to be linked (along with the rest of the core library) when the sketch is compiled.

I've found that if I modify the core source files, they automatically get recompiled.
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.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 443
Posts: 23837
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

Cool, thanks for the location. This stuff really gets buried!
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.

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, it seems my understanding is growing a little.

It would also seem I've been a little confused by my own wording of "I need to retain USB communication" - what I really need to retain, is a method of reprogramming the 1284, and it just so happens that the cable used to do so may connect to a USB port on my laptop. Correct?

Which should also mean, if I understand correctly, that I do not need any onboard FTDI chips or other AVR chips to do a USB to Serial conversion, but rather I just need an ICSP header that goes to the correct pins on the 1284, and I just connect to this using an external converter cable like the one I already posted, this one?

http://www.ebay.co.uk/itm/1x-USB-2-0-TO-RS232-Converter-UART-TTL-Serial-CP2102-For-Arduino-UNO-ATMEGA-PIC-/221067324467?pt=UK_BOI_Electrical_Components_Supplies_ET&hash=item3378a3ac33

...and the above is known as in circuit serial programming, or ICSP? Correct?

So what then is the ISP module? ISP used to burn the bootloader, ICSP used to flash sketches to the 1284?

I hope the above is correct! Many thanks again for all help so far.

EDIT: The mighty pages say only IDE 1 is supported, this may be a stupid question - but does this mean 1.0.1 IDE works, as it is newer than 1?
« Last Edit: October 14, 2012, 05:15:48 pm by jtw11 » Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16548
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, it seems my understanding is growing a little.

It would also seem I've been a little confused by my own wording of "I need to retain USB communication" - what I really need to retain, is a method of reprogramming the 1284, and it just so happens that the cable used to do so may connect to a USB port on my laptop. Correct?

Which should also mean, if I understand correctly, that I do not need any onboard FTDI chips or other AVR chips to do a USB to Serial conversion, but rather I just need an ICSP header that goes to the correct pins on the 1284, and I just connect to this using an external converter cable like the one I already posted, this one?

http://www.ebay.co.uk/itm/1x-USB-2-0-TO-RS232-Converter-UART-TTL-Serial-CP2102-For-Arduino-UNO-ATMEGA-PIC-/221067324467?pt=UK_BOI_Electrical_Components_Supplies_ET&hash=item3378a3ac33

...and the above is known as in circuit serial programming, or ICSP? Correct?

So what then is the ISP module? ISP used to burn the bootloader, ICSP used to flash sketches to the 1284?

I hope the above is correct! Many thanks again for all help so far.

No not correct. The module you linked to is a external USB to serial converter module, so it acts just like the on board serial converter on a Uno. A USB serial converter chip allows one to upload sketches from the arduino IDE if the AVR chip has a bootloader program already installed into the chip. You might call this serial programming.

ICSP is another different method to program a AVR chip on a arduino board. This requires a hardware programmer (that can also be a second arduino board running a ICSP sketch). The IDE can use some specific ICSP programmers (selected choice from the IDE tools menu) to burn sketches and also burn bootloaders onto AVR chips supported by the IDE.

So serial programming via a bootloader installed on the target chip, and programming via a ICSP to a target chip are two different methods, requiring different hardware components.

Lefty
Logged

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So looking in the IDE, under programming is the AVR ISP mkII, as Crossroads recommended. So, using one of these and the IDE - you simple open up your sketch in the IDE, connect to the ICSP header using the ISP and flash away?

...and flashing sketches in this way means no bootloader correct, thus freeing up more space for the sketch? As there is no bootloader, do any changes need to be made to the sketch, or does the compiler still add in all the bits you miss out in the IDE.

Now correct? :-)
« Last Edit: October 14, 2012, 05:43:19 pm by jtw11 » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 443
Posts: 23837
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

If the chip had a bootloader installed at some point, then all fuses will have been programmed for correct operation.

File: Upload Using Programmer does not change those.
This is evidenced by loading a sketch into a brand new chip using File: Upload Using Programmer,  at which point the sketch doesn't run well at all.
Burning a bootloader, and then loading a sketch via File: Upload Using Programmer, everything runs normally.
This wipes out the bootloader code, and the sketch starts immediately after a reset.
The same .hex file for the sketch is uploaded either way.
 
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.

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I assume by not being corrected on my last post I was correct in terms of connecting things up? Please confirm, just so I'm going through this step by step in my mind and not building on incorrect knowledge,

Im afraid I'm not with you on your last post... Fuses and .hex files are not things I've ever changed or worked with, I can't say I know what they are.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 443
Posts: 23837
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

Yes, the normal sketch is loaded, no change is needed.  Bootloader is not loaded, you gain a little Flash memory.
MKii connects the ICSP header. Board must be powered - MKiid does not provide power.
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.

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, good - look's like I understand up to where we are. My board will be externally powered anyhow, so it's not a problem - thanks for the heads up!

1) Now, just taken a look on the RS site to go and collect some 1284s, however - there is a 1284P-PU model, and a 1284-PU model. In your picture it seems you're using a 1284P-PU, is there however a difference that will matter in this application?

2) Also, back on the subject of fuses and .hex files - i've done a little reading, it seems that fuses are just bits of data stored on the chip, used to define certain configurations, internal vs external oscillator, clock scalars etc. Fuses seems to be a time from the black and white days when one time programmable chips were used, and these were indeed little strips inside the chip that must be burned out by applying current to them etc. Correct?

As for .hex files, is this the binary code file that the compiler writes and flashes to the chip? So what you're saying is, whether there is a bootloader or not, the .hex file remains the same - the bootloader is there simply to support USB.

3) Reverting back to your post that I did not, but I believe now do understand - to set these fuses correctly, I must put the bootloader on the chip? Then when I flash a sketch using the programmer, the bootloader itself is overwritten - but the fuse settings remain the same, as a sketch has no influence upon the fuse settings?

Logged

Pages: [1] 2 3   Go Up
Jump to: