Shop OBEX P1 Docs P2 Docs Learn Events
Upload Prop programs via XBee — Parallax Forums

Upload Prop programs via XBee

Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
edited 2012-11-26 22:21 in Propeller 1
It's been my goal for awhile to be able to upload programs to the Propeller via an XBee module. I finally got a chance to work out the details. Attached is the result.

The XBee module makes this task difficult, since the sending XBee can't directly stimulate handshaking pins on the receiving XBee, nor can it send a BREAK character or alter the receiving XBee's baud rate. So you're pretty much left with monitoring and interpreting character streams in order to trigger the bootload process.This carries a slight cost, since it's no longer possible to send just anything to the XBee without some special formatting considerations.

In order to pull this off with a minimum of special formatting, I decided to use the data link escape character (DLE = $10) as the trigger for commands to the XBee driver. Any time the XBee driver receives a DLE, it's hairs stand on end, ready for something special. If it receives a second DLE in sequence, it just queues both of them and stands down. This is the singular fly in the ointment. Any PC host program sending a $10 byte to the Prop as data has to send it twice for it to be recognized as such.

Otherwise, a DLE can trigger two built-in functions:

1. A DLE followed by an ATTN (DC1 = $11) and an ID byte tells the driver to accept further data if and only if the other byte matches the driver's unit ID ("A" to "Z", as presently configured). This permits simple master/slave networking using the XBee's transparent I/O mode.

2. A DLE followed by a SYSREQ (DC2 = $12), an ID byte, and ### forces the driver to enter monitor mode, where program uploads are handled. In this mode, a two-second period of inactivity forces a chip reset, in order to avoid a hang situation due to bad or incomplete communication from the host.

I've included the entire bootloader within the XBee serial receiver, so no funny games would have to be played with overlaying user EEPROM code with a resident bootloader. As long as the user program starts the XBee object for serial I/O, the boot loader will be ready to jump in when necessary. When monitor mode is entered, all cogs except the one hosting the XBee receive driver are stopped immediately. From there, special monitor commands (such as "upload to RAM") can be accepted and interpreted.

Included in the attached zip are the xbee.spin object and a PC-resident loader, LoadXB.exe. Give them a try. Feedback is welcome!

-Phil

Edit: 'Forgot to mention: the xbee.spin file is formatted for self-documenting via my documenter at:

Addendum: In this post, I've added a new version of this program that uses a completely different (and simpler) addressing scheme. Check it out!

Comments

  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-12-10 08:02
    Thanks, I have been wanting this.

    John Abshier
  • Ken GraceyKen Gracey Posts: 7,386
    edited 2010-12-10 08:19
    Excellent work, Phil. We'll be trying it out this weekend. - Ken
  • VernVern Posts: 75
    edited 2010-12-10 08:42
    I might have some use for this very soon. Well as soon as I can get a couple xbee's and start playing.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-12-10 09:26
    Phil, this is totally cool. Thanks for sharing it. Really, you deserve one of those gold star VIP crowns like Mike Green has. :)
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-12-10 14:13
    This is great Phil.

    I want to effectively do the same thing using the SI/SO (P31/P30) pins directly connected to a USB connector to the PC using one of the prop USB drivers. This would remove the requirement for a propplug. No time at present, but everything you do here should also work using the prop USB driver. All my new pcbs will have a mini-USB-AB (or B) connector for both 5V power and optional 47R/47K resistors to the D+ & D- pins. (I have discussed this previously). Now this will be another step closer :)
  • csfan10csfan10 Posts: 2
    edited 2010-12-11 08:18
    Phil - this works perfectly! Now to add XBees to all my projects!

    This thread should be added to the Propeller / Hydra: Key Thread Index Sticky. Will you be adding the Spin and exe files to OBEX? I'm sure this addition will get a lot of mileage out of it.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-12-11 08:56
    Thanks, I'm glad you got it to work! After some consultation with Parallax, I'm developing a separate version that dispenses with the DLE protocol altogether by taking advantage of the XBee's native addressing capability. When it's finished, I'll announce it in this thread.

    -Phil
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-12-12 22:07
    Attached is a version that uses an entirely different approach. XBee modules are addressed by serial number, instead of by user-assigned IDs:

    attachment.php?attachmentid=76290&d=1292219998

    The loader program uses the PC-connected XBee to scan for and locate remote XBees, any one of which can be selected for uploading. As a consequence, all communication is transparent, without the necessity of including DLEs with special command codes, thus greatly simplifying data I/O.

    Due to its comparative simplicity, this will likely become the supported version of the XBee object and loader. I do want to work on the loader some more, however, to provide the option of forcing inclusion of the XBee object when it's not included in the Spin source. This will ensure that all uploaded programs are capable of fostering further uploads.

    Anyway, those of you who have XBees, give it a try. Feedback, as always, is welcome!

    -Phil
  • Mike CookMike Cook Posts: 829
    edited 2010-12-13 06:59
    I have not had a chance to try the xbee.spin, but the LoadPropXB.exe program was able to find a XBEE equipped Propeller Project sitting on my bench.

    Looking forward to trying the ‘remote programming’ of the propeller.

    Thanks Phil!
  • csfan10csfan10 Posts: 2
    edited 2010-12-17 18:05
    Phil,

    The new version works great!


    Steve
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-12-17 18:56
    Thanks, Steve! I still have some work to do on it, though. The replies back from the remote unit are currently done in broadcast mode, which could affect other remote XBees that are listening. I began working on the additional needed code earlier this week, but "Santa's workshop" stuff has intruded. Hopefully, I'll be back on task soon.

    -Phil
  • kf4ixmkf4ixm Posts: 529
    edited 2010-12-18 19:12
    @ Phil,
    When i try to load a .spin file with the loadpropXB.exe, it asks me for the location of the propellant.exe file. i thought i had it at once but it cant find it. im using prop tool v1.2.7r2

    Nevermind, found it in propbasic, still playing with it.
  • JohnR2010JohnR2010 Posts: 431
    edited 2011-03-05 13:38
    Phil, this is absolutely what I have been waiting for. I have several xBee projects both in final testing phase and under development. I finally got time this weekend to work with it and I'm seeing some problems. First problem was not being able to communicate with my xBee with the xBee_loader.Spin replacing my FullDuplexSerial.Spin object. I didn’t troubleshoot this much since most of the methods are missing out of xBee_loader.Spin that I use. So instead I load your xBee_loader.spin when I'm ready to receive a program upload. This worked okay at first I was able to stop the Cog that is running FullDuplexSerial for my xBee and then start your xBee_loader.SPIN. I then would use your EXE to load my code into eeProm and reboot. This worked until my binary got to around 4k in size. What happens is very strange. Everything appears to work just fine your EXE says it loads into ram and writes to eeProm and then reboots like normal. But the code in the eeProm is corrupt?? I have to connect to the propeller with the USB and reload the exact same code and everything runs fine. I'm going to spend more time troubleshooting tomorrow but thought I would see if you ever made a newer version of your EXE or the SPIN file. Im using the exe and spin dated 12/12/2010 9:37pm. I hope I can get this to work it is going to be huge time saver for us!!

    Thank you very much for posting this!!!
  • fstanovichfstanovich Posts: 14
    edited 2011-04-01 13:16
    HI,
    I am new here and am interested if anything new is happening with this project? I was going to buy the new USB wireless HUB from Parallax but called them and it will not work with Windows 7 64 bit. So I talked to Kevin at Parallax and he send me some files and info on this XBee project. I spent time on reading documentation and tried to load test program (xbee_loader_test.spin), but the process failed with the message from Xbee loader V1.0, "No response from Propeller, or upload failed".
    The Xbee is setup with default factory settings.
    I can do a loop back test on remote Xbee OK.
    Xbee Loader finds a unit ID.
    Test button works OK.
    Load RAM and ROM button displays the "No response..." message.
    Propeller XBEE Loader V1.0 used.
    XBee_loader.spin V1.0
    I think that about covers it. I will try again later.

    Thanks Frank
  • fstanovichfstanovich Posts: 14
    edited 2011-04-01 15:13
    OK, got it to work! I don't know if I missed something in the documentation. But, before running the XBee loader I ran the Propeller.exe program and got the XBee cog running.
    Then, ran XBee Loader and it loaded the test program and ran it which blinked the LED.
    So, I will continue along and test my Robot program without cables and test.
  • john_sjohn_s Posts: 369
    edited 2011-09-20 09:43
    Phil,

    As I keep gathering some info around over the air (OTA) multi node re-programming scenario I came up with the following question...

    Is your program capable of hopping between say 2 or more xbee modules and delivering a packet to that n-th node over the mesh network and finally to re-program that particular Prop?

    Thanks,
    John

    p.s. I am not xbee or Prop user (not yet) so forgive me my ignorance
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-09-20 10:42
    The program works only with a point-to-point configuration, not with a mesh network.

    -Phil
  • john_sjohn_s Posts: 369
    edited 2011-09-20 10:49
    Thanks
    -John
  • Brian RileyBrian Riley Posts: 626
    edited 2011-09-20 18:03
    XBee's can be made to toggle the Reset line without all this software hack. This is a hack for Arduino but the concept is the same. Just a simple two wire mod and a setup change in in X-CTU.

    http://www.ladyada.net/make/xbee/arduino.html
  • john_sjohn_s Posts: 369
    edited 2011-09-22 12:23
    Brian,

    Thanks for the very fine link and your amazing wulfden.org. You (plus PhiPhi and Tracy Allen of course) certainly got my interest renewed in XBee for my next wireless project around.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-05-08 11:36
    During experimentation with my S2 XBee adapter, I discovered that LoadPropXB.exe was not compatible with the Propeller Tool v1.3. The reason is that the Spin library has been moved to a separate library folder and that LoadPropXB didn't give Propellent the right directions to find it. This has been corrected with the attached v1.1 of LoadPropXB, such that if the home folder of the Propeller Tool contains a folder named "Library", it uses that; otherwise it uses the home folder, as it did before.

    -Phil
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-05-08 14:15
    One more update. The load to RAM from LoadPropXB was not working because the bootloader in xbee.spin forgot to kill itself after starting the interpreter. This has now been fixed in the attached.

    -Phil
  • simonlsimonl Posts: 866
    edited 2012-05-09 08:30
    What a coincidence - no update since last September, then two updates the day before I come looking for this! Many thanks Phil :)
  • average joeaverage joe Posts: 795
    edited 2012-11-26 22:21
    Phil, this works great! It took some trial and error, including replacing a bad prop and downloading the LATEST version. I have not had a chance to test with an ACTUAL serial port. Rigged the xbee to the propPlug and loaded right up. I just wish it would work with my USB -> Serial adapter / development board. Anyway, keep up the good work!

    *edit*

    Could you elaborate a bit more about why this method wouldn't work with a mesh network? I have a feeling it has more to do with the EXE than the bootloader, but I could be wrong.
Sign In or Register to comment.