Monday, April 22, 2013

TryFi 3

In the past post, I did the easy work of getting the XbeeWifi code running on the Arduino. This time, I'm looking at pinouts to connect the Xbee into a Wifi program. This is the last major puzzle piece I haven't yet had.

Tryfi 3 - Try and try again

More specifically, I'm trying to fill in these 4 variables with the numbers of the correct pins:  

  bool result = xbee.init(XBEE_SELECT, XBEE_ATN, XBEE_RESET, XBEE_DOUT);

Higher in the code, we see the actual pinout values in use:

  #define XBEE_RESET 20

  #define XBEE_ATN 2
  #define XBEE_SELECT SS
  #define XBEE_DOUT 23

After re-reading the Xbee Spec and the Introduction to SPI on Xbee, I have some slightly clearer understanding of SPI as a hardware protocol, a way for 2 processors to communicate. Basically, we're setting the right pins so the Xbee's processor and the Arduino's processor can hear each other. 

From the Xbee Spec, we can see the pins on the Xbee that we're looking for -- Reset = 5, ATN looks like ATTN = 13 (ignore the n), and Select could be SSEL = 17. DOUT looks like 2, but I'll come back to that later.

Well, I'm getting lots of info on what pins the Xbee uses, and lots of this SPI stuff is supposed to be universal -- basically a small but fairly complex universal language which all processors can speak. It's like UART, (universal asynchronous receive & transmit) which is basically a much simpler language that all processors can speak. There are lots of these "universal" languages, but SPI is the one we're interested in.

Here is one of the diagrams from 
the Xbee Spec. Note the highlight.

Something to note is 2 different naming methods for the connections -- DIN & DOUT vs MOSI & MISO. 'Master Out Slave In' matching to 'Data In' -- since the Xbee will be 'slaved' to the Arduino's clock frequency, the way ancient sea slaves rowed to the drummer's beat. 'Master In Slave Out' connections are also named the Data Out connections from the Xbee. So one of the 4 variables we're looking to fill is the Xbee DOUT, which is also the SPI MISO connection (which is actually pin 4 on the Xbee, not pin 2 -- pin 2 is the UART DOUT).

Maybe I'm looking at this the wrong way -- I have lots of info about how Xbee uses SPI, but what I need to is the pins the *Arduino* uses. Well, Google directs us to a gold mine! Aha! Looking down the page, we finally get our answers:



So this gives us 1 of the variables, and confirms another -- We know that Xbee DOUT should change from 23 to 12, and we know Xbee Select is correct in being set to SS, as SS is a variable for 10. Now, we just need the Xbee Atn and Xbee Reset pins.



No comments:

Post a Comment