Bringing Up the Wi-Fi Interface

The easiest way to make the Wi-Fi interface work is by calling the wln_start() function of the WLN library. This will save you a ton of effort, seriously!

If you can't or won't use the library, here is the sequence of steps that you have to take in order to bring up the Wi-Fi interface:


The following is simplified sample code that demonstrates the process. Typically, it would be called from the on_sys_init event handler, but you can actually call it from anywhere in your application. We call the code "simplified" because it does not check for any error conditions.

This code will work for both the GA1000 or WA2000, and on all platforms that support one or both of these devices:  

Tibbo BASIC
'BRINGING UP THE WI-FI MODULE (SIMPLIFIED)

#If PLATFORM_ID=EM500W
   #define WLN_RESET_MODE 1 'reset is controlled by the combination of CS and CLK
   'there is no need to map CS, DI, DO, and CLK lines because they are fixed
#elif PLATFORM_ID=EM1206W
   #define WLN_RESET_MODE 0 'there is a dedicated reset line
   #define WLN_RST PL_IO_NUM_11
   #define WLN_CS PL_IO_NUM_15
   #define WLN_DI PL_IO_NUM_12
   #define WLN_DO PL_IO_NUM_13
   #define WLN_CLK PL_IO_NUM_14
#else
   #define WLN_RESET_MODE 0 'there is a dedicated reset line
   #define WLN_RST PL_IO_NUM_51
   #define WLN_CS PL_IO_NUM_49
   #define WLN_DI PL_IO_NUM_52
   #define WLN_DO PL_IO_NUM_50
   #define WLN_CLK PL_IO_NUM_53
#endif

'----------------------------------------------------------------------------
sub on_sys_init   
   '----- configure interface lines -----
   '(on platforms with fixed mapping this will have no effect)
   wln.csmap=WLN_CS
   io.num=WLN_CS
   io.enabled=YES
   wln.dimap=WLN_DI
   wln.domap=WLN_DO
   io.num=WLN_DO
   io.enabled=YES
   wln.clkmap=WLN_CLK
   io.num=WLN_CLK
   io.enabled=YES
   io.num=WLN_RST
   io.enabled=YES

   '----- reset Wi-Fi module -----
   #If WLN_RESET_MODE 
      'reset is controlled by the combination of CS and CLK      
      io.lineset(wln.csmap,HIGH)
      io.lineset(wln.clkmap,LOW)
      io.lineset(wln.clkmap,HIGH)
   #Else   
      'there is a dedicated reset line      
      io.num=WLN_RST
      io.state=LOW
         'The WA2000 requires a longer reset pulse (1ms), and the GA1000 will not mind it
         '32-bit platforms offers a convenient sys.timercountms method
         'Since the WA2000 only works on 32-bit platforms, let's write the code like this:
         #if PLATFORM_TYPE_32
            sys.timercountms=0
            while sys.timercountms<1
            wend
         #endif
      io.state=HIGH
   #endif
   
   'in case we called wln_init() after it has already been up and running
   While wln.enabled=YES
   Wend
   
   '----- set the domain -----
   wln.domain=PL_WLN_DOMAIN_FCC 'for illustrative purpose only, this is the default value

   '----- set allowed bands -----
   wln.band=WIFI_PHY_11ABGN_MIXED 'for illustrative purpose only, this is the default value

   '----- allocate the buffer -----
   wln.buffrq(5)
   sys.buffalloc 

   '----- set MAC address (optional) -----
   wln.mac="0.100.110.120.130.140" '

   '----- detect the module type

   dim module_type as pl_wln_module_types=wln.getmoduletype


   '----- boot up the module -----
   if module_type=PL_WLN_MODULE_TYPE_GA1000 then 
      romfile.open("ga1000fw.bin")
      wln.boot(romfile.offset) 'supply the pointer to the GA1000 firmware file
   else
      wln.boot(0) 'no need to upload the WA2000 firmware every time
   end if

   '----- setup the IP, gateway, netmask -----
   wln.ip="192.168.1.86" 'can be delegated to our DHCP library
   wln.gatewayip="192.168.1.1" 'optional
   wln.netmask="255.255.255.0" 'optional
end sub