Sunday, September 27, 2009

Bootloading the Arduino over XBee ZB, Part II

Right, so I got the Arduino to load over XBee with the default bootloader. But I am still stuck with having to manually hit the reset-button on the Arduino.

So here is my plan. (I've seen various variations on this on the 'net, but not exactly what I want. Someone has probably done it, before, though. I don't care.) I wonder if that whole CTS hardwired to Reset can work for us his time. What I want is for the DTR, when received over the USB-connection by the XBee Coordinator, to magically reset the Arduino. This should in theory be very simple with the XBee shield.
  • On the XBee EndDevice, set DIO7 to mode 4, which is "Digital Out, Low". (ATD7=4, if you're doing it by hand)
  • Then, on the XBee Coordinator, set DIO7=Input (ATD7=3), and IC=80 (IC is a bitmap of which inputs to monitor, 40h is a bitmap with only the 8th bit set, counting from IO0)
  • Finally, solder a jumper on your XBee explorer, tying DTR and CTS together. (Actually, this should probably be a resistor.. I'm guessing CTS is an input on the FTDI. And Maybe it should be possible to revert this somehow, I think X-CTU depends on CTS and DTR for firmware-loading. Minor details!)
  • Done!
Looks good, no? This should work because the XBee's are quite intelligent little things. Because we set DIO7 on the Coordinator to Input, the XBee should automagically send this information to whichever XBee is addressed in the Coordinators DH/DL-registers (you did program those, didn't you?). And since we hardwired DIO7 to DTR, whenever AVRdude asserts DTR, the remote XBee will assert DIO7. And, as we know from bitter experience, DIO7 is hardwired to Reset on the XBee shield.

Sounds simple, doesn't it. Perhaps too simple.. I've struggled with this for a few hours, but no matter what I do, no matter what config, no matter what firmware, I can not get the target XBee to change its outputs.

I've concluded that this functionality ("transporting" Digital IO-lines) only works on Series 1 XBee's. Something that is not clear in the documentation. (As a sidebar, I would like to note that the XBee documentation in general is not all that great..)

Anyway, I've opened a case with Digi on this, hopefully they will come back with a clear answer. I'll update if they do!

Update! I've heard back from a very pleasant support-person at Digi, and he confirmed my suspicion. This is not supported on the XBee ZB, and it probably never will be. They also confirmed that this does work on their series 1 radios, the XBee 802.15.4.

So, what would the workaround be?? Well, I've verified that asserting DIO7 will reset the arduino. So I guess I'll write a small wrapper for AVRdude, which sends a package to the remote XBee instructing it to set DIO7 high, then low, and then fires up AVRdude. Might work. The bad news is that it will require the API firmware, at least on the Coordinator. Don't yet know if API Coordinator with AT EndDevice will have the desired effect. I do not yet know if I can make this work, if the EndDevice needs to have the API firmware in order to support remote commands, I don't think it will send the data straight out on the serial, but rather in a frame-structure. Meaning I'd need a custom bootloader in order to decode the data.. Hm.

So I suppose there will be a "Bootloading the Arduino over XBee, Part III". Sometime.

2 comments:

  1. Hey, did you ever get the bootloading working over the ZB XBees? Somehow I doubt simply wrapping avrdude will work, because you need API mode to work the reset, and AT to send the data.

    It looks like the only solution is to patch (or rewrite) avrdude so that it can wrap its data in API packets and also send the reset command. You could still run the end device in AT mode this way, and the API Coordinator will be able set the baud rate and destination for the return packets remotely.

    This is what I'm facing now, unless you managed to find another way?

    daniel@danielhall.me

    ReplyDelete
  2. I managed to get this working, with a special bootloader that understands API mode: https://github.com/davidsainty/xbeeboot

    ReplyDelete