Bringing Up and Enabling the BLE Interface

Top  Previous  Next

In order to enable the BLE portion of the WA2000, you need to bring up the wln. object first. This involves:

Configuring the GPIO lines used to interface with the WA2000.

Resetting the WA2000.

Booting up the WA2000 using the wln.boot method.


Extensive info on the boot process is provided in Bringing up Wi-Fi interface so we will refrain from explaining the basics of the module initialization here.

Here is the code, with comments, that will bring up the WA2000. This code only touches on things that are necessary for making the BLE interface operational.


Tibbo BASIC:







declare sub delay_ms(delay as integer)




sub on_sys_init()

 'configure the GPIO lines















 'reset the WA2000






 '----- set MAC address (optional) -----



 wln.boot(0)"EM2000 node 1" 'all spaces will be deleted, so the name will be "EM2000node1"

 bt.emulation=PL_WLN_BT_EMULATION_MODE_MICROCHIP 'added for clarity, this is the defaul value


 'allocate TX and RX buffers





 'enable the BLE interface and wait for it to become enabled

 '(blocking version)


 while bt.enabled=NO



 bt.advertise=YES 'allow the device to be discoverable


 sys.debugprint("BLE is now ready. MAC= "+bt.mac+".\r\n") 'notice how the MAC address is reported here

end sub


sub delay_ms(delay as integer)


 while sys.timercountms<delay


end sub


As you can see, after the module is booted using wln.boot, you need to take several additional steps:

Set the advertising name in the property. This is the name that will be seen on your central device (an iOS or Android smartphone, etc.).

Select the emulation mode (Nordic or Microchip) using the bt.emulation property (can be omitted if you want to stick to default Microchip emulation).

Allocate TX and RX buffers (assign at least one buffer page for each). More on this in Allocating TX and RX buffers.

Enable the BLE with ble.enable.

Enable advertising through bt.advertise. This step is only necessary if you want your device to be discoverable, and this is not always true.


The BLE interface has its own MAC address. A unique BT MAC is already hardcoded into the WA2000 during the manufacturing. If needed, you can also set your own MAC.


Since ble.enable is aynchronous, your app will need to detect when the BLE actually turns on. Example above polls the state of wln.enabled — this is a blocking way. The non-blocking way relies on on_bt_event:


Tibbo BASIC:


 'enable the BLE interface and wait for it to become enabled

 '(blocking version)


end sub


sub on_bt_event(bt_event as enum pl_bt_events)

 select case bt_event






         bt.advertise=YES 'allow the device to be discoverable                

         sys.debugprint("BLE is now ready\r\n")




 end select

end sub