PIC18F97J60+mrf24wb WIFI API

2019-04-15 16:07发布

Unlike Ethernet, a WiFi application needs to initiate a connection to an access point or an ad hoc network) before data communications can commence. In order to initiate an connection there is a sequence of steps that should be followed.    1) A connection profile must be created (see WF_CPCreate()). The connection profile contains information directing the WiFi driver about the nature of the connection that will be established. The connection profile defines:  a. SSID (name of Access Point)  b. Security (open, WEP, WPA, etc.)  c. Network type (infrastructure or ad hoc).    The Connection Profile functions are used to create and define an connection profile. These functions all begin with WF_CP…    2) The connection algorithm must be defined, and applies to all connection profiles. For most applications the defaults will be sufficient. For example, the default connection algorithm channel list for scanning is 1, 6, and 11. However, if, in your application you know the Access Point will always be on channel 6 you could change this setting, thus making the scan process more efficient. Functions pertaining to the connection algorithm all begin with WF_CA…    3) Once a connection profile and the connection algorithm are customized for an application, the WF_CMConnect() function must be called to initiate the connection process.    4) After WF_Connect() is called the host application will be notified when the MRF24WB0M has succeeded (or failed) in establishing a connection via the event mechanism. The WF_Config.c file has a function, WF_ProcessEvent(), that is a template for processing MRF24WB0M events. In the WiFi demos it simply prints to the console (if the UART is enabled) that the event occurred. This file can be modified to suit the needs of an application – for example, an application could pend on a global flag that would be set in WF_ProcessEvent() when the connection succeeded. Please refer to WF_ProcessEvent for more information on WiFi event handling.    The MRF2WB0M demos (under the Demo App, WiFi Console, and WiFi EZ Config demo directories) contain a function, WF_Connect(), in MainDemo.c that executes the above steps and can be referred to as an example of how to initiate a WiFi connection. The WF_Config.h file has several compile-time constants that can be customized (e.g. MY_DEFAULT_SSID_NAME) as needed.    This help file book describes the host API to the MRF24WB0M on-chip connection manager which creates and maintains Wi-Fi connections. The API is divided into these major sections: API Section  Description  Initialization  Functions to initialize the host API and MRF24WB0M  Connection Profile  Functions to create and maintain one or more connection profiles  Connection Algorithm  Functions to fine tune the connection algorithm  Connection Manager  Functions to start and stop an 802.11 connection  Scan  Functions to scan for wireless networks  Tx Power Control  Functions to control the MRF24WB0M Tx power  Power Save  Functions to save power consumption by the MRF24WB0M  Multicast  Functions to create multicast filters  Miscellaneous  Functions to set a custom MAC address, get device information, etc.  MRF24WB0M Events  Functions to handle events from the MRF24WB0M    SPI The WF_Spi.c file contains functions that the Wi-Fi Driver will use to initialize, send, and receive SPI messages between the host CPU and the MRF24WB0M. To communicate with the MRF24WB0M, which is always an SPI slave, the host CPU SPI controller needs to be configured as follows:
  • Mode = 0
  • CPOL (clock polarity) = 0
  • CPHA (clock phase) = 0
  • Host CPU set as master
  • Clock idles high
  • 8-bit transfer length
  • Data changes on falling edge
  • Data sampled on rising edge
  Below is a list of functions in WF_Spi.c that must be customized for the specific host CPU architecture: Function  Description  WF_SpiInit()  Initializes the host CPU SPI controller for usage by the Wi-Fi driver. Called by the Wi-Fi driver during initialization.  WF_SpiTxRx()  Transmits and/or receives SPI data from the MRF24WB0M.  WF_SpiEnableChipSelect()  Set slave select line on MRF24WB0M low (start SPI transfer).

If SPI bus is shared with any other devices then this function also needs to save the current SPI context and then configure the MRF24WB0M SPI context.  WF_SpiDisableChipSelect()  Set slave select line on MRF24WB0M high (end SPI transfer).

If SPI bus is shared with any other devices then this function also needs to restore the SPI context (saved during WF_SpiEnableChipSelect()).    External Interrupt The WF_Eint.c file contains functions that the Wi-Fi Driver will use to enable and disable the MRF24WB0M external interrupt as well as get interrupt status. The functions in this module need to be customized for the specific host CPU architecture.  The MRF24WB0M asserts its EXINT (external interrupt) line (active low) when specific events occur, such as a data message being received. Note that the host CPU has a choice to either configure the EXINT line to generate an actual interrupt, or, it can be polled. Below is a list of the Wi-Fi Driver functions within WF_Eint.c that must be customized for the specific Host CPU architecture. Function  Description  WF_EintInit()  Configures the interrupt for use and leaves it in a disabled state. Will be called by the Wi-Fi driver during initialization. If polling the EXINT pin then this function won’t have any work to do except leave the interrupt in a logically disabled state.  WF_EintEnable()  Enables the MRF24WB0M external interrupt. If using real interrupts then enable the interrupt. If polling the EXINT pin then this function enables polling of the pin.  WF_EintDisable()  Disables the MRF24WB0M external interrupt. If using real interrupts then disable the interrupt. If polling the EXINT pin then this function disables polling of the pin.  WF_EintIsr()  This is the interrupt service routine invoked when the EXINT line goes low. It should perform any necessary housekeeping , such as clearing the interrupt. The interrupt must remain disabled until the Wi-Fi Driver calls WF_EintEnable(). The Wi-Fi driver function, WFEintHandler() must be called.  WF_EintIsDisabled()  Returns true if the external interrupt is disabled, else returns false.  WFEintHandler()  This function does not need to be customized – it is part of the Wi-Fi driver. However, it is added to this list because it must be called each time the MRF24WB0M interrupt service routine (ISR) occurs.  WF_Config The WF_Config module (WF_Config.h/WF_Config.c) is used to control several aspects of the WiFi Driver behavior. Most of the customization of the Wi-Fi module is done from the context of this module. Removal of Unused Driver Functions In WF_Customize.h there is a block of defines that can be commented out to remove those sections of the Wi-Fi host driver that are not needed by the application. This allows the saving of code and data space. #define  Controlling Functions  WF_USE_SCAN_FUNCTIONS  Scan API  WF_USE_TX_POWER_CONTROL_FUNCTIONS  Tx power control API  WF_USE_POWER_SAVE_FUNCTIONS  Power save API  WF_USE_MULTICAST_FUNCTIONS  Multicast API  WF_USE_INDIVIDUAL_SET_GETS  Affects all get and set functions, except the following:
WF_CPSetElements()
WF_CPGetElements()
WF_CASetElements()
WF_CAGetElements()  WF_USE_GROUP_SET_GETS  Affects the following functions:
WF_CPSetElements()
WF_CPGetElements()
WF_CASetElements()
WF_CAGetElements()  WF_DEBUG This define enables the WF_ASSERT macro in the Wi-Fi driver. Customer code is free to use this macro. The WF_ASSERT macro can be compiled in or out via the WF_DEBUG define. See the comment above the WF_DEBUG define in WF_Customize.h for details. WF_CONSOLE The Wi-Fi driver has a UART console application built in that allows one to type in command lines and has them parsed. If this functionality is not needed than it can be compiled out by commenting out the WF_CONSOLE define. WF_ProcessEvent() This function is called by the Wi-Fi Driver when an event occurs that the host CPU needs to be notified of. There are several Wi-Fi connection related events that the application can choose whether to be notified or not. And, there are several events the application will always be notified of.  The function WF_ProcessEvent() can be customized to support desired handling of events. Modules Name  Description  Wi-Fi Connection Profile  Functions to setup, use, and teardown connection profiles  Wi-Fi Connection Algorithm  Functions to alter the behavior of the connection process  Wi-Fi Connection Manager  Functions to manage the connection process  Wi-Fi Scan  Functions to direct the MRF24WB0M to initiate a site survey  Wi-Fi Tx Power Control  API to control the Tx power of the MRF24WB0M  Wi-Fi Power Save  Functions to alter the power savings features of the MRF24WB0M  Wi-Fi Miscellaneous  Functions for controlling miscellaneous features of the MRF24WB0M  Topics Name  Description  WF_ProcessEvent  Describes how to receive and act on events from the MRF24WB0M  Access Point Compatibility    WiFi Tips and Tricks  Describes some basic tips for setting up and configuring a WiFi network.  Hot Topics  Lists some answers to some common WiFi questions.