Moteino dead after upload?

Started by Jacco, October 07, 2013, 02:12:56 PM

Jacco

Hi,

For a week now I have my Moteino R3 up and running as a controller for my air refreshing system.
I'm still tweaking the software and since it's build into a wall socket that's a bit of a problem.
So I decided to experiment with wireless programming. I changed my code to make wireless programming possible and uploaded it to a Moteino (by FTDI to the only R3 I have with a flash chip). After the upload my mote isn't working anymore. It is also impossible to upload any sketch.

What could be wrong? Is it possible to kill an AVR by uploading wrong code?

Should/can I fix it by burning the bootloader again onto it?

I already tried this but I get stuck when I compile the DualOptiboot. I get the following error(s) on my Windows 8 box:

C:\Program Files (x86)\Arduino\hardware\arduino\bootloaders\optiboot>..\..\..\tools\avr\utils\bin\make OS=windows ENV=arduino atmega328
../../../tools/avr/bin/avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls -mmcu=atmega328p -DF_CPU=16000000L  '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DLED_DATA_FLASH=1'   -c -o optiboot.o optiboot.c
optiboot.c: In function 'CheckFlashImage':
optiboot.c:367: error: 'PB3' undeclared (first use in this function)
optiboot.c:367: error: (Each undeclared identifier is reported only once
optiboot.c:367: error: for each function it appears in.)
optiboot.c:367: error: 'PB5' undeclared (first use in this function)
make: *** [optiboot.o] Error 1

On my iMac I get the following message:

make: Nothing to be done for `atmega328'.

Is this the way to go to get my Mote working again? If so, what I'm doing wrong.
If not, what then?

Thanks for any help,
Jacco

Felix

Jacco,
Really hard to tell what exactly happened without knowing what code you uploaded. But no ... I've never seen an AVR die after an upload. Just stop working yes, I've seen that plenty.
BUT ... it's possible that you uploaded a very large sketch and perhaps that overwrote the bootloader?

You could always use "Arduino UNO" as target, so long as your sketch does not exceed 31744 bytes (31Kb). I've had another user actually upload a larger sketch than that and ended up having to reflash the bootloader. I didn't release my own board version for the IDE because that would just add confusion and more steps, and really ... I've never ever had a sketch exceed 30K, actually I can't think of any sketch I wrote recently that exceeded 20K... even with several libraries running on it. But .. it's possible.

Anyway, I'm sure your hardware is OK. Maybe something got corrupted or the sketch was larger and overwrote part of the bootloader and just needs reflashing.

You could reflash the bootloader but you will need to use a pullup resistor on D10, and perhaps a pulldown on the MISO line. There's a prebuilt bootloader at github so you don't need to rebuild it: https://github.com/LowPowerLab/DualOptiboot/blob/master/DualOtiboot_atmega328_1k_d9LED_debugOFF.hex

Jacco

Thanks Felix,

I'm pretty sure I didn't exceed the 31KB. I've took your advise and put a hard limit in boards.txt. But maybe I only did that on my iMac and not on Windows and I was using Windows when this happend. I'l have check. Anyway...

I will give it a try this evening.

Eventually I succeeded to compile the bootloader. I had to change PB3 in PORTB3 and PB5 in PORTB5. Is this plausible?
But this is all new stuff for me so I think I will use the prebuilt bootloader.
Should I rename to DualOtiboot_atmega328_1k_d9LED_debugOFF.hex to optiboot_atmega328.hex?

Do you know if it is possible to burn the bootloader with the bitbang method? See http://learn.adafruit.com/ftdi-friend/programming-the-arduino-bootloader
I used the ArduinoISP before but my UNO is 5V and the Moteino is 3.3V. This won't work, right?

As plan B I ordered a set of new Moteino R3. But it take so long before they arrive :)

Felix

Hm, I think PB3/5 should be the same as PORTB3/5.
The prebuilt one should work. It won't matter what the HEX name is.

I have once tried to use another Arduino as ISP programmer and I can't remember if it worked in the end, but I remember that it was very frustrating, tons of errors and there was an issue getting the target to reset (had to use a 10uF cap on the RST line etc) and I just decided to get an AVR ISP mkII programmer. Good choice. I'm still using that programmer to flash all Moteinos after I bake them.

Moteinos can run at 3.3v or 5v, BUT the transceivers from HopeRF cannot take 5V!
So if you power the Moteino through the VIN pin, you are safe, the onboard regulator will supply only 3.3V to the atmega and radio.
However, the AVR programmer will never power the target  board, that's nice, because I can power the board independently and just hook up the programmer and it will always work, without any other circuitry.

So after looking at the adafruit "bitbang" link it's quickly obvious that you don't want to sit there for 2 hours programming 1K of bootloader. We're not in 1946 anymore. Doh.
But they do share this other link: http://arduino.cc/en/Tutorial/ArduinoISP
Looks a bit different than what I tried before getting my AVR programmer. But maybe it's worth a shot.

I think some of the most useful tools I ever got were the AVR programmer ($35) and a logic analyzer ($150?). Without the AVR programmer, you're always going to scratch your head trying to figure out what you did last time when you were able to program your 'duino with another 'duino, lookup the links, etc. Without a logic analyzer, you will scratch your head in disbelief when your atmega won't do what you thought/hoped it would. These 2 tools saved my day many times. Without the logic analyzer the RFM69lib would not exist today.

jbeale

On the the subject of logic analyzers, I really like the Saleae Logic, it is very nicely engineered, I also use the carry case it comes in to keep a bunch of other stuff at hand, going between home and work (wires, connectors, PicKit2 programmer, Teensy2/3, and maybe now a few moteinos.)

Jacco

Well tried the ArduinoISP method as I did before.
I wasn't sure if I could use this method because of the different voltage levels for SPI communication.
But, it worked...my Moteino is working again. :D

For answer on later problems I will buy a AVR programmer but that was no option for now since my new Moteino will arrive the same time as the programmer. This method was instant available. And I just spent €50 at your shop, I can spent my money only once ;)

I have a question about the HEX file though. How is it determined what HEX file is used since there is more than one HEX file? Also the original one named optiboot_atmega328.hex.

Thanks,
Jacco

Jacco

Hi JBeale,

I took a look at the Saleae Logic.
It looks and seems great.  Made a bookmark for later reference.

Jacco

anthonywebb

@felix, you mentioned some of the tools that were essential to you as you developed moteino.  As one looking to build up a little home lab, are there other hardware you can recommend (spectrum analyzer?), and /or pitfalls to avoid?

@JBeale, nice tip on Saleae, as a total newb I had never run into them.

I actually had my eye on this: http://www.bitscope.com/product/BS10/ but I dont know how to make a real comparison between that an the saleae, it appears that the bitscope is more full featured, but I dont know all what is handy as you get into this stuff or if you even need all the bloat? Care to give me your 2 cents?

Jacco

Never mind Felix. I figured out how to upload the correct HEX file.
I was using the IDE but had to use the avrdude commandline tool.

Felix

Ok.

I got the Saleae 8 channel analyzer in the early days and worked well for me so far. I haven't used it many times, but was essential in debugging some nasty situations. Their software is really nice. But I do reckon there's other comparable or even more feature rich analyzers out there. Someone shared another link in the forum somewhere, can't remember who/when..

Pitfalls to avoid ... avoid getting a cheap DMM, this is the corner stone of your lab.
I also got a rigol ds1102e 100mhz scope, pretty handy to look at AC and analog stuff.
And RF ... I'm a newb to it actually. I am trying to learn from the gurus sharing their RF know-how in this forum :)

jbeale

#10
Quote from: anthonywebb on October 08, 2013, 03:31:15 PM
@JBeale, nice tip on Saleae, as a total newb I had never run into them.

I actually had my eye on this: http://www.bitscope.com/product/BS10/ but I dont know how to make a real comparison between that an the saleae, it appears that the bitscope is more full featured, but I dont know all what is handy as you get into this stuff or if you even need all the bloat?
All I can say is the Saleae (original 8 channel) has been a good match for the problems I've needed to solve.  The bitscope looks interesting, I am not familiar with it, although apparently it's been around since 1998 (?) My take on oscilloscopes is that for any serious work you want a separate standalone unit, with real knobs you can turn, although that will cost you more. I got my 2-channel 60 MHz Tek TDS-210 over a decade ago and its served me well. Now you can get a comparable Rigol scope (with more features) for around $350. I thought this was a good post: http://jeelabs.org/2011/12/20/getting-an-oscilloscope/ ...You can find lots of opinions on test equipment at http://www.eevblog.com/forum/index.php and I also enjoy reading http://dangerousprototypes.com/ for lots of hobby electronics info.
(sorry for the thread drift, maybe this should be a separate topic)

anthonywebb