Society of Robots - Robot Forum
Electronics => Electronics => Topic started by: jonagik on August 10, 2011, 12:57:29 AM
-
Hi,
I'm sorry, I believe I've already asked this but I can't find my original thread and don't believe it yielded an answer.
Is there a C++ API for communicating at runtime with the ATMega8 family of microcontrollers via the AVR ISP MKII from an application on my computer? I can't find anything on the Atmel website (however, there is a lot of information there so I could have missed something).
Cheers,
Jonagik
-
Please read these on how to program the ATMega8, but all are in C not C++
http://www.raphnet.net/divers/avrprog/index_en.php (http://www.raphnet.net/divers/avrprog/index_en.php)
These are the Documents from Atmel
http://www.atmel.com/dyn/general/advanced_search_results.asp?device=1&tools=1&faqs=1&datasheets=1&appNotes=1&userGuides=1&software=1&target=AVR%20Studio (http://www.atmel.com/dyn/general/advanced_search_results.asp?device=1&tools=1&faqs=1&datasheets=1&appNotes=1&userGuides=1&software=1&target=AVR%20Studio)
read these two App Notes:
AVR068: STK500 Communication Protocol (http://www.atmel.com/dyn/resources/prod_documents/doc2591.pdf)
AVR069: AVRISP mkII Communication Protocol (http://www.atmel.com/dyn/resources/prod_documents/doc8015.pdf)
These are some source on how to communicating at runtime with the ATMega8 family of microcontrollers
http://www.bsdhome.com/avrdude/ (http://www.bsdhome.com/avrdude/)
http://sourceforge.net/projects/avrprog/ (http://sourceforge.net/projects/avrprog/)
-
Thanks for that but, from what I can see, these are mostly about programming a microcontroller via the AVRISP. What I'm looking for is runtime serial communication between my PC and my microcontroller. For example, I might want to have an application on my PC which has a button on it which, when pressed, toggles an LED between On and Off with my microcontroller.
Are there USB devices one can buy which allow my application to send binary data to a microcontroller (i.e. a device one can plug into one's computer and have an application tell it when to set an output port high/low and tells the application when an input port it high/low)?
Thanks
-
You need to learn about UART/USART, then you can do everything you said with hyperterminal on the PC (I think you can use terminal on the mac, but I have no idea how... off to google). You'd also need a level adapter like this...
http://www.amazon.com/MAX232-RS232-Converter-Adapter-Board/dp/B00471S6MC (http://www.amazon.com/MAX232-RS232-Converter-Adapter-Board/dp/B00471S6MC)
Then you can program your microcontroller to input data from the computer, and if it receives an 'a' then it'll turn the LED on and off.
Make sense? It's not communication through the programmer, but rather through a serial cable.
As for an application on the PC... you'd probably have to make one yourself... but I'm just guessing there. In all honesty, you could just use hyperterminal and use the arrow keys ;)
-
I'm in New Zealand and these adapters tend to be rediculously expensive compared to in the U.S.
Is there a way to, for example, get my computer to read/write from/to a specific USB port (without all that USB handshaking stuff)? The reason for this being i) that I don't have a serial port, and ii) to avoid expense on adapters.
Thanks again.
-
Hmmm, I don't really know about the USB communication, I'm sure it's possible though. Admin's Axon II has USB.
If the adapters are expensive, you could just buy the chip and make the adapter yourself. (Could be cheaper) It's a pretty simple circuit actually. I believe the chip is a MAX232 or some variant.
-
Their are versions of the Arduino that don't use the UART to communicate to the at-mega.
http://arduino.cc/en/Main/ArduinoBoardSerial (http://arduino.cc/en/Main/ArduinoBoardSerial) //This is the current UNO that uses a at-mega-8u2 instead of a UART
http://arduino.cc/en/Main/ArduinoBoardUno (http://arduino.cc/en/Main/ArduinoBoardUno) //This uses level shifting resistors to connect to an old school serial port.
http://metalab.at/wiki/Metaboard (http://metalab.at/wiki/Metaboard) //This one has a Bootloader that handles the UARTs job in software.
-
Making the adapter could be a good option. I've read through the datasheets on some of the chips for this but can't establish how to make the circuit. Can someone please point me in the right direction?
Thanks
-
Hi,
I think I've got the solution. Please let me know if there are any errors.
I get a USB to COM (serial) adapter. Then I create this device (http://www.sparkfun.com/datasheets/Prototyping/RS232-Shifter-v2.pdf (http://www.sparkfun.com/datasheets/Prototyping/RS232-Shifter-v2.pdf)). I connect the Rx and Tx to two I/O ports on my uC. I then write software on my computer to send/receive via COM1 and on my uC to send/receive via the two ports to be used for I/O.
Any problems?
Thanks
-
Yes, that is exactly what I was saying you should do. :P
Except it's not "Tx, Rx, and two other i/o pins". You need to hook up Tx, Rx, and you need to provide power and ground to the chip. No other i/o pins.
Just be forewarned, I know sometimes those usb to serial cables don't work exactly like a serial port. I believe admin uses one for his stuff, but I've also heard other people on the forum say they've had trouble getting stuff to work with them.
-
I dont understand what you mean in your second paragraph. I thought I could connect Serial Rx to an output port and Tx to an input port. What do you suggest?
Yes, that is exactly what I was saying you should do. :P
Except it's not "Tx, Rx, and two other i/o pins". You need to hook up Tx, Rx, and you need to provide power and ground to the chip. No other i/o pins.
Just be forewarned, I know sometimes those usb to serial cables don't work exactly like a serial port. I believe admin uses one for his stuff, but I've also heard other people on the forum say they've had trouble getting stuff to work with them.
-
I dont understand what you mean in your second paragraph. I thought I could connect Serial Rx to an output port and Tx to an input port. What do you suggest?
No you are correct, although I recommend some kind of protection in case you hook it up backwards (some people use 2.2k resistors, some use 1k resistors etc). You'd hook the serial Rx and Tx and stuff up to the max chip then hook the tx and rx of the chip to the rx and tx of the atmega. Just follow the schematic. You can't hook up the serial cable direction to the atmega. You need the schematic you posted if you want it to work, and not destroy your chip.
-
Cool, thanks.
Won't such a high resistance drop the voltage too low to be detected? Also, how do I know the voltage coming off the converter chip so I can hook up an appropriate resistor if necessary?