Trying to program Razor IMU over TTL serial using an Arduino Uno - Software only

Hey guys. I'm trying to program a Razor Imu using an Arduino Uno. I have a few constraints. Firstly, I can't use SPI, as all of the PWM pins on the Uno are needed for other stuff. I have digital pins 5 and 6 open on the Uno, and I have all of the analog pins open on the Uno. I know that there are ways that you can do this by making small hardware modifications to the Uno, but unfortunately, I can't do this either.

To clarify what's going on here, we're going to attach the Razor IMU to a shield for the Uno, and the box it all goes into will be sealed, meaning that field programming of the Razor will be impossible UNLESS, we can pass a sketch from the Arduino Uno, to the Razor over serial. Ideally, this would be done by first re-programming the Uno with a sketch similar to the ArduinoISP sketch, and then using the Upload Using Programmer function of the Arduino IDE to re-program the Rasor with whatever firmware we wanted. Does anybody know if this is possible? I've tried writing a sketch for the Uno which simply reads in data over its serial port, and shoots it out over a software serial port to the Razor's Tx and Rx pins, but that didn't work. I always get an error that says "stk500_getsync(): not in sync: resp=0x00"

I can post code and or hardware schematics if necessary. I'm incredibly sorry if this is in the wrong place.

Any help you guys can provide would be awesome. Thanks so much!

In this case you use software SPI. See the SPI lib for details and remember that the analog pins are also digital I/O pins.

Mark

So just to be clear, you're saying use shiftOut and shiftIn to emulate the hardware implementation of SPI, and re-work the ArduinoISP code to work with this change, right?

The first hit in Google for Razor IMU shows this and it already contains a Atmega328 with arduino bootloader installed so using a 3.3V FTDI Breakout you will be able to program it over serial.

No I'm saying that if you read the spi lib you will find that it supports both hardware and software spi!. (or at lest the adafruit version does).

Mark

Riva:
The first hit in Google for Razor IMU shows this and it already contains a Atmega328 with arduino bootloader installed so using a 3.3V FTDI Breakout you will be able to program it over serial.

I can't use a breakout board. This must be done with an Arduino Uno, as this is all going to be integrated into a single product. I need a way to pass serial data from the USB port on the Uno, to the FTDI input of the Razor. Trust me, I've been searching my bum off. It's not a simple matter of programming the Razor, I can do that easily. The problem is that I need some way for both boards to be programmable over the same USB port without having to mod hardware, as they'll be sealed in a container, and breaking it open is impractical for the simple purpose of updating firmware when we ship updates for it. Hence, I need something like the ArduinoISP sketch, which I can temporarily upload to the UNO to program the Razor. I would use that, it works a treat, except that I can't use hard SPI for the reasons I explained in my first post. I think the soft SPI solution will work though, I'm going to try it. Thanks guys.

EDIT: Of course, if someone else has a different suggestion, I'd be glad to hear it. :slight_smile:

There may be away to use the Uno's HW SPI if you have 2 spare Digital pins and are willing to add 2 quad AND gates to your design.

Basically take the signal pin to two AND gates the 2 spare pins are used to select which of the AND gates will pass on the signal.

There are also other chips which will allow to select witch way the signal is sent. (mux/de mux?).

Mark

holmes4:
There may be away to use the Uno's HW SPI if you have 2 spare Digital pins and are willing to add 2 quad AND gates to your design.

Basically take the signal pin to two AND gates the 2 spare pins are used to select which of the AND gates will pass on the signal.

There are also other chips which will allow to select witch way the signal is sent. (mux/de mux?).

Mark

I suggested a hardware modification earlier involving a quad 2-1 demux chip, which would have done exactly what you're talking about here. Personally, I think that's the right way to go in this instance; just tie one of the analog pins to the control bit on the demux, and that's it. But the project manager says the board is full, and that we can't add anything else to it, so it has to be software. Oh well. I tried re-implementing the ArduinoISP code using shiftIn and shiftOut, but I ended up bricking my Razor in testing (oops... :P). I figured this would be no big deal, I've done it before, and I just have to reflash the bootloader over the Razor's SPI pins using our external ICSP (I could also use the original Arduino ISP code to do this). However, I had some difficulty reflashing the bootloader, so I might have done some real damage this time. We'll see. I still think the software SPI solution will work out, but if it doesn't, I'll insist on the hardware mod, I suppose.

Take a look at using DDL diode / diode logic. A very small footprint!.

Mark

I did write some software spi code which works on the avr's and the sam (due) micros but at best I'd say it was 20 times slower than hardware SPI and my version which is hardware independent is about 100x slower but does work on the avr Arduinos and the Due, and would work on any furture Arduino (it uses digitalRead/Write) so maybe even a Pi.

Mark

holmes4:
I did write some software spi code which works on the avr's and the sam (due) micros but at best I'd say it was 20 times slower than hardware SPI and my version which is hardware independent is about 100x slower but does work on the avr Arduinos and the Due, and would work on any furture Arduino (it uses digitalRead/Write) so maybe even a Pi.

Mark

Well, at least I know it's possible now, which was the whole point of this tread. I guess I'll keep trying to develop a software SPI solution as you've suggested. :slight_smile: I've ordered a new Razor just to have on hand. I've accidentally over written the signature bits in my current one. Before someone says it, yes, I did use a continuity tester to make sure the connections were good, so it's not that, and I know everything is hooked up to the right pins as I've flashed it before successfully. If by chance somebody happens to know how to use compiler flags with the Arduino environment so that I can use the -F flag, then that would be fantastic. The error I'm getting when I try to burn the bootloader is as follows if people are interested:

avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

If anybody's wondering about the progress in this project, I'll tell you that it isn't good.

I've bricked three boards, using three different approaches. One was a modification of the ArduinoISP code which I did myself, another was an attempt to accomplish the same functionality from scratch, and one was a project I found online using digital reads and writes. All three bricked my Razors badly with that "Yikes! Invalid device signature" error. Does anybody have a better way, or maybe a working piece of code they'd be willing to part with? Maybe someone who has done this before can give me a gentle nudge. I'm desperate at this point. I just need some way to use the ISP code on different pins than the SPI pins, apparently that's not a very easy task. :frowning: Oh well. I'll keep trying.

Can you flesh out some more details please.
What SPI device and IDE settings are you using to program the Razor. This page (bottom of page) shows a couple of possible causes for Yikes!
AFAIK you cannot change the device signature but amongst other things maybe you have burnt the wrong fuses settings and need to reset them using a high voltage programmer. Once the fuses are set correctly you can then continue to use the SPI interface to program normally.

As to the original problem of programming the Razor could you have some form of TTL latch to steer the TX pin from both Arduino's (UNO & Razor). By default (after power cycle) it connects the UNO TX pin to USB.
You upload a sketch to the UNO that switches this latch so the Razor TX pin is connected to USB and then you upload the Razor Sketch to the Razor. Then when you power cycle the device the latch switches back to default of connecting UNO TX to USB.

I'm in the process of constructing the high-voltage programmer. Hopefully it will work well. :slight_smile:
Everybody seems to think that the hardware solution is the way to go, eh? Well, I guess we'll go with that. :slight_smile: Fantastic.

I am still curious as to if there's a way to have an Arduino Uno function as a serial pass-through for FTDI using any of the programmer options and the "Upload using programmer" function of the arduino IDE; or if there was some other viable software-only solution. To clarify, we have two daisy-chained Arduinos, you can think of it that way, and they can't be removed from one another. The Razor's DTR pin is wired to an A0 on the Uno, TX on the Razor is pin 5 on the Uno, RX on the Razor is pin 6 on the Uno, CTS is tired to ground (although this can be changed), and voltage and ground on the Razor are tied to 3.3V voltage and ground on the Uno. We have one USB port, the one on the Uno, and we need to be able to use it to program both boards. By using only a sketch uploaded to the Uno, and the "Upload using programmer" functionality of the IDE, I need a way to program the attached Razor. I don't know if this is possible. If a proposed solution calls for it, I can afford to hook up the SPI pins of the Razor to the ANALOG pins of the Uno, but ONLY the Analog pins. The actual SPI pins of the Uno are being used for something else, not related to SPI, but can't be changed. If this is impossible, by all means let me know. :stuck_out_tongue: In any case, for the initial prototypes at least, we'll use a hardware solution.

In any case, thanks very much for all the help. You've all been wonderful.

and voltage and ground on the Razor are tied to 3.3V voltage and ground on the Uno.

You may have damaged your Razor if it's powered by 3.3V and your sending 5V from UNO pins to Razor pins.

Riva:
You may have damaged your Razor if it's powered by 3.3V and your sending 5V from UNO pins to Razor pins.

This is not the case. The razor has always been powered exclusively by the 3.3 Volts from the Uno, not from the SPI header on the Uno or any other source. Since the bricking happened directly after an unsuccessful SPI sketch uploading using an attempted software-SPI solution, I'm willing to bet you were right, and that the fuse bits just got messed up.

roybrus:

Riva:
You may have damaged your Razor if it's powered by 3.3V and your sending 5V from UNO pins to Razor pins.

This is not the case. The razor has always been powered exclusively by the 3.3 Volts from the Uno, not from the SPI header on the Uno or any other source. Since the bricking happened directly after an unsuccessful SPI sketch uploading using an attempted software-SPI solution, I'm willing to bet you were right, and that the fuse bits just got messed up.

But were the SPI pins from a 5V UNO?

I don't believe that was the problem. I had programmed it using the hardware SPI ArduinoISP sketch several times before it failed.