Society of Robots - Robot Forum

Software => Software => Topic started by: jonagik on January 25, 2011, 10:25:20 PM

Title: Communication between computer and uC
Post by: jonagik on January 25, 2011, 10:25:20 PM
Hi,

How can I get a C++ application on my computer to send and receive digital data to/from my ATMEGA8 via either USB (not sure how to implement a USB connection) or AVRISP MKII?

The application is having my computer autonimously control a robot rather than have the control all handled by the robot's uC.

Thanks in advance.
Title: Re: Communication between computer and uC
Post by: Graynomad on January 26, 2011, 08:41:11 AM
Figure out how to talk to a serial port from C++, then get an FTDI USB-serial cable and run the RX/TX signals to the serial port on the Mega.

______
Rob
Title: Re: Communication between computer and uC
Post by: mstacho on January 26, 2011, 09:38:23 AM
I did this in C# a little while ago.  Check the posts here:

http://www.societyofrobots.com/robotforum/index.php?topic=13038.0 (http://www.societyofrobots.com/robotforum/index.php?topic=13038.0)

The communications code I posted works, but it's not the greatest.  Technically the uC code is for the Axon, which is an AVR ATMega640 or something, but it's a good starting point, unless you're stuck on using C++ (I wanted to do it in C before I learned that C# makes it a lot easier :-P).  It communicates through the UART.

MIKE
Title: Re: Communication between computer and uC
Post by: jonagik on January 26, 2011, 04:54:39 PM
I think I'll go with an ATMEGA8U2 which supports USB whereas the ATMEGA8 doesn't (correct me if I'm wrong).

In this case I need my C++ program to communicate via USB to the uC.

If I connect the USB connector's D+ and D- to ports 29 and 30 on the uC am I able to communicate via USB at run-time as well as using these ports to program the device or do I have to connect the USB connector to other I/O ports? Presumably I'll be able to communicate at run-time through ports 30 and 29 I just want to make sure.

@mstacho presumably your code is communicating via an RS232 serial port and not USB and so is not applicable for use with the ATMEGA8U2?

So how can I use C++ to send digital data via USB to my device? Is there an API or something that Atmel provides for this use?
Title: Re: Communication between computer and uC
Post by: Graynomad on January 26, 2011, 05:33:10 PM
Quote
communicate via USB at run-time as well as using these ports to program the device
I don't know much about the 8U2 but I would say that in theory you could program via the USB but you'd have to write your own boot loader.

Failing that use the normal ISP and buy a programmer.

Even if you go the bootloader path you'll need an ISP programmer to burn that.

As for communicating at run time, that's what the new Arduinos do, but does the 8U2 handle all the USB protocol as well, or just the hardware interface. If it doesn't do the software you're in for a heck of a lot of programming.

Quote
So how can I use C++ to send digital data via USB to my device?
No idea.

______
Rob

Title: Re: Communication between computer and uC
Post by: jonagik on January 26, 2011, 06:39:53 PM
My understanding is that the ATMEGA8U2 allows programming via USB using AVR STUDIO and FLIP (http://www.atmel.com/dyn/products/tools_card.asp?tool_id=3886 (http://www.atmel.com/dyn/products/tools_card.asp?tool_id=3886)) and that this is the only difference between the ATMEGA8 and the U2. Please correct me if I'm wrong.
Title: Re: Communication between computer and uC
Post by: Graynomad on January 26, 2011, 06:49:24 PM
That Atmel page says

Quote
FLIP supports in-system programming of Flash devices through RS232, USB or CAN.

Which implies that you can program the chip with USB but I can find no real details. It's possible that the bootloadeder is hardcoded into the chip, or maybe not.

Also

Quote
Two installation files (below) are available: one with Java Run-time

This presumably is not code for the chip, so once again, where is the bootloader?

The page actually says bugger all. I'll have a look at the chip data sheet, maybe that will thow some light on the subject.

______
Rob

Title: Re: Communication between computer and uC
Post by: Graynomad on January 26, 2011, 06:53:55 PM
Ok have a look at this document

http://www.atmel.com/dyn/resources/prod_documents/doc7618.pdf (http://www.atmel.com/dyn/resources/prod_documents/doc7618.pdf)

It seems that the bootloader is hardcoded into the chip.

I haven't read the whole thing but it starts by saying

Quote
The 8bits mega AVR with USB interface devices are factory configured with a
USB bootloader located in the on-chip flash boot section of the controller.

So that looks promising.

______
Rob
Title: Re: Communication between computer and uC
Post by: jonagik on January 27, 2011, 06:56:45 PM
Does anyone know if programming the ATMEGA8U2 is the same as for the ATMEGA8 (for example, would I be able to use the $50 robot code [http://www.societyofrobots.com/step_by_step_robot_step4.shtml])?