Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

WiFly Shield code

netduino WiFly

  • Please log in to reply
4 replies to this topic

#1 ericcox

ericcox

    Member

  • Members
  • PipPip
  • 19 posts

Posted 17 January 2013 - 09:28 PM

Hi all, WARNING: ALPHA CODE AHEAD! For those using the Wifly Shield from Sparkfun, here is a patch against rev 21420 of the netmf toolbox that adds direct support for the WiFly Shield with it's SC16IS750 SPI-To-Uart bridge.  The idea was to utilize the WiFlyGSX class as much as possible and separate the SC16IS750 code from it, so it could be useful in other configurations.  I wanted to make sure that we didn't have two separate WiFlyGSX classes out there - one with SC16IS750 support and one for use with a standard Uart - that we'd continually have to keep in sync. There are four main classes and an interface: WiFlyGSX The original, slightly modified to use ISerialPort, and adds a couple of functions that I needed for my project.    Spi2UartBridge Controls the SC16IS750 SPI-to-Uart bridge chip.  Implements ISerialPort, so should be transparent to the WiFlyGSX code.  It's interrupt driven - no polling - and supports the few GPIO pins on the SC16IS750.  I had some code in here that allowed you to use an in-memory buffer to improve performance, but had to yank it out to simplify debugging when I ran into a data transfer problem.  Assuming that code wasn't the cause of the problem, I'll probably add it back in later. Please note that I've only implemented the members of ISerialPort in Spi2UartBridge that I needed to use the WiFlyGSX code due to time constraints.  That's the reason I'm posting this in patch form rather than giving it to Stephan for inclusion in the Toolbox at this time - it's not a problem if you're just using the WiFly Shield, because WiFlyGSX only uses the implemented SerialPort members.  But someone implementing another SerialPort-using class may need all the members of SerialPort. In other words, this class is not really useful as a generic transparent replacement SerialPort - but that is the goal.  Time-permitting I'll implement all of the ones appropriate for the SC16IS750 on the SerialPortEx class.   WiFlyShield Encapulates the two classes above, and houses functions that require *both* the SC16IS750 and the WlyFly: resetting the WiFly, and resetting to factory defaults, via hardware pins.  Will probably add a method to control the Force Awake pin later. SerialPortEx Virtualizes the SerialPort/Spi2UartBridge by wrapping a real SerialPort and implementing ISerialPort members.  Should be simple/stable enough for developers to use as a target rather than a real SerialPort, so their code could be used with a SerialPort-lookalike in the future.

 

Basic use:

1. Create an SPI port

2. Create a Spi2UartBridge and pass it the SPI port

3. Create a WiFlyShield and pass it the Spi2UartBridge

4. Reference WiFlyShield.WiFlyGsx to access the WifFlyModule

 

namespace WiFlyTest{	public class Program	{		public static void Main()		{			var configuration = new SPI.Configuration(Pins.GPIO_PIN_D10, false, 0, 0, false, true, 4000, SPI.SPI_module.SPI1);			var spi = new SPI(configuration); 			using (var bridge = new Spi2UartBridge(spi, Pins.GPIO_PIN_D7))			{				bridge.DebugMode = true;				bridge.TestPin = 2;				bridge.BaudRate = 9600;				var shield = new WiFlyShield(bridge, debugMode: true);								shield.ResetToFactoryViaHardware(); 				shield.WiFlyGsx.SetAntenna(Antenna.Internal);				shield.WiFlyGsx.EnableDHCP();				shield.WiFlyGsx.JoinNetwork("testw", Authentication: WiFlyGSX.AuthMode.WPA2_PSK, Key: "<key>"); 				while (shield.WiFlyGsx.LocalIP == "0.0.0.0")				{					Thread.Sleep(1000);				} 				Debug.Print("Success!");			}		}	} }

 

Disclaimer: This code is, of course, posted with no guarantees of any kind.  If it works for you, great!  If not, send me a detailed description of what's going on and I'll try to fix it.  (If you have the time to debug and send a patch, that would be great)  Please note that if you change any of the register-manipulation code for the SC16IS750, you're on your own  :P  

Oh, also - this was developed on a Netuino Plus.  Not sure if their are any changes necessary for the NP2.  But the NP2 is my eventual target, so if you can wait, the code will be modified as appropriate in a future release (another reason it's not quite ready to be in the Toolbox).

Attached Files



#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 18 January 2013 - 07:47 AM

Oh man! I have to test this this weekend! I like it already :D


"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 ericcox

ericcox

    Member

  • Members
  • PipPip
  • 19 posts

Posted 18 January 2013 - 09:13 PM

Thanks Stefan.  Any feedback you can give is appreciated.

 

By the way I made an easy but fairly important change already: I now create the WiFlyGSX instance at first use, rather than in the WiFlyShield constructor.  I found that by far the most problematic portion of working with the WiFly module (as with any async serial device) is baud rate mismatch. This allows you to put the WiFly module into a known state before working with it.



#4 royf007

royf007

    New Member

  • Members
  • Pip
  • 1 posts

Posted 08 March 2013 - 09:49 PM

Hey guys, thanks for the great posts and work.  I've also been struggling with trying to get WiFi working on a Netduino 2 Plus using the SparkFun WiFly shield with WiFly RN.  I can send commands to the WiFly but never get any responses.

 

Any updates on this since January..i.e. has anyone been able to get this working nicely with an NP2?  It seems that this isn't an issue using Arduino, but just having recently switched to Netduino, it seems like there is a huge demand for this.  Using a WiFi -> Ethernet bridge seems wrong.

 

I'm a newbie, so not sure how to apply this patch. Thanks.



#5 HiredMind

HiredMind

    Member

  • Members
  • PipPip
  • 25 posts

Posted 11 March 2013 - 06:03 PM

Hi royf007, 

 

I had the same baud rate mismatch problems with the WiFly shield.  That's the reason I had to add the ResetToFactoryViaHardware() method to the code above.  I have to reset and configure the WiFly each time my device powers up. It adds a few seconds delay before the device is ready to connect, but it's very reliable this way.

 

Using the code:

 

Think of a patch as a set of changes to existing code.  In this case, it applies changes to the excellent NetMF Toolbox code.

 

1. Download the zip file attached to the first post in this thread, and extract the patch file inside.

2. Install Subversion (http://subversion.tigris.org/)

3. Use Subversion to grab a copy of the NetMF toolbox source code (http://netmftoolbox....eset/view/22109 - click Connect)

4. Right click in the root of the NetMF Toolbox tree

5. Click TortoiseSVN, then Click Apply Patch

6. Find your patch file and select it.

7. Patch all

 

It should apply the changes to the NetMF toolbox code, and then you can build that in Visual Studio and add references to your project to use the code.

 







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.