Uploading to 328p via Raspberry Pi TX/RX?

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
borisj054
 
Posts: 6
Joined: Sun Nov 25, 2012 12:04 am

Uploading to 328p via Raspberry Pi TX/RX?

Post by borisj054 »

Hi, first time poster here. I have been searching in vain and experimenting for several weeks, looking to the answer to this question...

Is it possible to load sketches on a bootloaded Atmega328P with just the TXD and RXD lines of a Raspberry Pi? I'm drawing the conclusion that this is possible from the fact that most tutorials (including this one http://itp.nyu.edu/physcomp/Tutorials/ArduinoBreadboard) say that you can program the AVR via USB to serial adapter. Since the TXD and RXD pins on the Raspberry Pi are already serial, and I have successfully loaded sketches on the 328P and communicated with them via Pi over serial, shouldn't it be possible to load sketches via TXD and RXD?

I have several Atmega328P AVR's loaded with the Adafruit bootloader and a Raspberry Pi with Pi Cobbler.

I was able to successfully load a sketch onto one of the 328p's using homemade logic converters referenced here:
https://wiki.wsartori.com/wiki/Logic_Level_Converter
and a the Gordon@Dragon GPIO bitbang scheme for SPI programming.
http://blog.stevemarple.co.uk/2012/07/a ... using.html

However, using those same logic converters configured with the TXD of the RPi connected to pin D01 and RXD connected to D02 on a fresh 328p yields nothing.

When I short the reset pin to ground and then run this command on my RPi:
avrdude -p m328p -P /dev/ttyAMA0 -c arduino
I get this error after about 5 seconds:
avrdude: stk500_recv(): programmer is not responding

If I run the same command and then quickly short the pin to ground, I get this message:
avrdude: stk500_getsync(): not in sync: resp=0x00

I'm guessing that since AVRDude is using the stk500 in this circumstance, it is expecting to program the AVR over ISP.
If that's not right, what programmer should I be using? I tried all the ones available with my version of AVRDude but none of them appeared to work. Do you know how this can be done, or an article that can help me find my way to the finish line on this?

User avatar
borisj054
 
Posts: 6
Joined: Sun Nov 25, 2012 12:04 am

Re: Uploading to 328p via Raspberry Pi TX/RX?

Post by borisj054 »

I forgot to note a few basics of my setup:

1. The AVR and Pi are hooked up on a breadboard and the AVR is powered by 5v from the Raspberry Pi.
2. The AVR is being externally clocked at 16MHz by a crystal and 2 capacitors.
3. I did mention this but It's worth clarifying. The TXD of the Pi is hooked to a logic converter taking the output to 5v. The output of that goes to pin D01 of the AVR. RXD of the Pi is hooked to a voltage divider splitting the voltage from pin D02 of the AVR to 3.3V.
4. I tested the effectiveness of the whole setup by loading a serial communicating sketch on a different AVR and found that serial communication is working correctly.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Uploading to 328p via Raspberry Pi TX/RX?

Post by adafruit_support_mike »

For the sake of clarity, I want to confirm that you're using the RasPi-ICSP reference for information about level shifting, not programming the microcontroller through the ICSP/SPI interface.

As far as sending sketches to the Arduino through the RX/TX pins, that should work. This page from the Arduino website has some other options for avrdude that you might try: http://playground.arduino.cc/Code/ArduinoUpload

User avatar
borisj054
 
Posts: 6
Joined: Sun Nov 25, 2012 12:04 am

Re: Uploading to 328p via Raspberry Pi TX/RX?

Post by borisj054 »

Thank you for the reply.
I'll spend some time looking into the link you sent me.

You are correct in your point of clarification. I am setup for ICSP and not SPI.
My breadboard actually looks a lot like the image below, except I am not using a regulator (just 5v from the RasPi for power), no LEDs and no sparkfun board. Just the raspi's TXD and RXD ports connected to the AVR through level shifters.

It's quite a quandary to me. I just don't understand why this isn't working. It seems so easy when you have a USB to serial converter…

Sorry for the huge picture.
Image

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Uploading to 328p via Raspberry Pi TX/RX?

Post by adafruit_support_mike »

Go ahead and post a photo of your own setup. I'm not looking for a general idea of how things are connected so much as potential noise and/or wiring issues that might not be obvious to you.

A couple of points do cross my mind: first, try giving the Arduino its own 5v supply. The RasPi doesn't have a lot of current to spare. Second, double check your TX/RX connections. For most symmetric protocols, TX means "data comes out" and RX means "data goes in", so you have to connect the TX line of one device to the RX line of the other. There are exceptions to that rule though, and I haven't verified the polarity with my own hardware, so do check around to make sure your RasPi isn't holding the phone upside down, as 'twere.

User avatar
borisj054
 
Posts: 6
Joined: Sun Nov 25, 2012 12:04 am

Re: Uploading to 328p via Raspberry Pi TX/RX?

Post by borisj054 »

Thanks again!
I'm looking into getting external power for the ARM. In the meantime, here's a pic of my setup.

http://www.flickr.com/photos/95732860@N03/8737303677/
Image

User avatar
borisj054
 
Posts: 6
Joined: Sun Nov 25, 2012 12:04 am

Re: Uploading to 328p via Raspberry Pi TX/RX?

Post by borisj054 »

The bus on the left is 5v and the bus on the right is 3.3v.
I tested all power points with a multimeter and verified that the reset pin drops to 0v when I press the reset button.

I verified that the logic "up-converter" (transistor circuit) is working by removing the output connection from the AVR, turning on the GPIO associated with TXD and observing the voltage spike from 0 to 4.5v.
I also verified the logic "down-converter" (voltage divider) is working by plugging the input to the 5v bus and observing the output go from 0v to 3.2v.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Uploading to 328p via Raspberry Pi TX/RX?

Post by adafruit_support_mike »

Those connections look right, and the up/down shifters look reasonable.

Have you checked to make sure the oscillator is running? Crystal oscillators are touchy, and breadboards are notorious for being flaky when high-speed signals are involved.

Also, for the sake of testing, do you happen to have an Arduino sitting around? If so, hook up your 5v, GND, TX and RX connections to that and see what happens. If you can program that, you'll know the basic idea works, and that the problem is somewhere on the breadboard. If it doesn't work, you can focus on the connections and software issues.

User avatar
borisj054
 
Posts: 6
Joined: Sun Nov 25, 2012 12:04 am

Re: Uploading to 328p via Raspberry Pi TX/RX?

Post by borisj054 »

Thanks for looking it over. It's good to get a second set of eyes on the circuit.

I, unfortunately, do not have an arduino. I was kinda hoping this would be a good surrogate that I could use for more compact and customized development. I think I'll spring for a USB to serial adapter as it may come in handy for a lot of other things and its application in this context seems to be proven.


Thanks again for the help!

minerva
 
Posts: 58
Joined: Sun Dec 06, 2009 11:12 pm

Re: Uploading to 328p via Raspberry Pi TX/RX?

Post by minerva »

- You will need a common ground connection between the AVR and the RP as well as your TX and RX lines.

- Avoid injecting 5V-level signals from the AVR into the RP's RXD if your AVR is running at 5V. You can do a basic level shifter with a couple of resistors and it should work fine.

- Remember that the Arduino-style bootloader is looking for a reset before it transfers the sketch, and Arduino-type hardware normally uses one of the handshaking lines such as DTR or CTS to perform that reset.

- Try a manual pushbutton reset on the AVR just before telling the software running on the RP to upload code to the AVR.

- Check you haven't crossed over TX and RX. Everybody does it!

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”