Toymaker Television

Daily content for the geek and DIYer



0 notes &

XBee: Remote to Base Code Analysis

So we’ve shown that this works, but now we need to know HOW it works.

The CON section has up until now been primarily used as a location for putting the settings of the crystal:

  • _clkmode = xtal1 + pll16x (Clock Mode is using crystal Xtal1 and increasing its frequency by 16x, pll style)
  • _xinfreq = 5_000_000 (The crystal installed is 5MHz)

But now it is setting a few other constants.

  • XB_Rx = 0 (Pin 0 is going to receive data from the Xbee via the Xbee’s DOUT pin)
  • XB_Tx = 1 (Pin 1 is going to send data to the XBee via the Xbee’s DIN pin)
  • XB_Baud = 9600 (Transfers will be 9600bits per second)
  • CR = 13 (No idea why it’s set to 13 of all numbers but that’s a carriage return!)

Again in the VAR Section we have space set aside for a new cog’s workings - this time though, instead of longs, they’re using words.  And we’re using the FullDuplexSerial Object again.

Alrighty, so we have our first part of the program starting communications for the XBee where we have to set: start(rxpin, txpin, mode, baudrate)

XB.start(XB_Rx, XB_Tx, 0, XB_Baud) - simple enough!

Then we wait for 1000ms, or 1second, and we’ll have a counter going from 1 to 20.  We send a string to the XBee saying “Count is:” and then give the decimal counter going from 1 to 20.  Then we finish with a carriage return.

Note, delay is set in another sub routine known as Pub Delay (ms) - it essentially equals the current clock cycle plus clkfreq (which is 1second), divided by 1000, making it milliseconds).

Simple!  (And if there’s any portion that’s confusing, let me know so I can explain it in a different way!)

@atdiy/@tymkrs

Filed under remote to base node xbee communication tymkrs xbee wireless kit xbee and parallax xbee and propeller electronics fullduplexserial how to make xbees work