The MPLAB® Code Configurator RN4870 | RN4871 BLE Modules Library allows quick and easy configuration of the C code generated software driver based upont the user’s selected API features available from the MCC Library. Generated Driver code supports use of either BLE Module with use of a PIC or AVR device. The library module uses a Graphic User Interface (GUI) presented by MCC within MPLABX which allows for selection of desired configuration, and custom configurations of the protocol. Customized C code is generated within the MPLABX project, in a foldernamed "MCC Generated Files". This Library uses (1) UART, (1) GPIO, and DELAY support at minimal.
Refer to the /images folder for source files & max resolution.
- MPLAB® X IDE 5.40 or newer (microchip.com/mplab/mplab-x-ide)
- MPLAB® XC8 2.20 or a newer compiler (microchip.com/mplab/compilers)
- MPLAB® Code Configurator (MCC) 3.95.0 or newer (microchip.com/mplab/mplab-code-configurator)
- MPLAB® Code Configurator (MCC) Device Libraries PIC10 / PIC12 / PIC16 / PIC18 MCUs (microchip.com/mplab/mplab-code-configurator)
- MPLAB® Code Configurator (MCC) Device Libraries AVR® MCUs (microchip.com/mplab/mplab-code-configurator)
- Microchip ATmega_DFP Series Device Support (2.2.108) or newer (packs.download.microchip.com/)
- Microchip PIC16F1xxxx_DFP Series Device Support (1.4.119) or newer (packs.download.microchip.com/)
- AVR-BLE Development Board (DT100111)
- PIC-BLE Development Board (DT100112)
To install the MPLAB® Code Configurator Plugin:
- In MPLAB X IDE, select Plugins from the Tools menu.
- Select the Available Plugins tab.
- Check the box for the MPLAB® Code Configurator v3, and click on Install.
To install the RN4870 | RN4871 BLE Module Library:
- Open the MPLAB Code Configurator page: https://www.microchip.com/mcc
- Scroll to the bottom of the page and select the Current Downloads tabs.
- Download the RN4870 | RN4871 BLE Module Library (rn487x_ble_module-1.0.0.mc3lib).
- In the MPLAB® X IDE click on Tools → Options.
- This may also be found unnder: In the MPLAB® X IDE click on MPLAB® X IDE → Preferences.
- Click on Plugins tab.
- Click on Install Library.
- Browse to the location where you saved rn487x_ble_module-1.0.0.mc3lib, select and click Open.
-
The Process described below is reflective of the Validation Hardware used: LightBlue. Microcontrollers used for reference are the PIC16LF18456 and ATmega3208 8-bit devices.
-
Open MCC by clicking Tools → Embedded → MPLAB® Code Configurator OR click on the MCC icon.
-
If MCC is not available; it is required to be installed. Navigate to Tools→ Plugins. Under Available Plugins select MPLAB® Code Configurator, ensure the checkbox is selected and press Install. Once this installation is completed, MCC will be available.
-
On launching MCC; it will request saving MyConfig.mc3. This file may be renamed if desired; and contains the MCC Configuration information related to the project.
-
From the In the Device Resources panel under Libraries dropdown select: RN4870 | RN4871 BLE Module.
-
The Notifications [MCC] tab will appear after library addition to describe required actions. These reflect the need for Reset Pin connected to the Module to be assigned to a pin; this is required by the library. ‘Read Message’ API is required to be generated if specific driver supporting features are selected; by default, all driver API(s) are selected for generation.
-
If an example is selected for generation; only the required supporting API(s) will be selected for generation. Both the Transparent, and Basic Data examples require the same API(s). These minimal required supporting API(s) are shown below.
- Enable the desired APIs. Basic description of API(s) can be found by hovering mouse over the ToolTip icon.
Note: For both example use cases, Mode Control and Read Message support are required and cannot be deselected.
- Through Foundation Services, select the UART(s) instances used for communication with the Module; or for supporting the generated example.
- Set the Baud rate for the module.
- The default baud for the RN4870 and RN4871 modules is 115200.
- Hint: The pre-programed baud rate for the AVR-BLE & PIC-BLE development boards is 9600.
BASIC DATA EXCHANGE (1) UART & (1) GPIO
TRANSPARENT SERIAL (2) UART & (1) GPIO
-
The notification related to BT_RST should be resolved by claiming the desired pin. Make sure this pin is configured as an output, and is in the HIGH state by default.
-
Connect the development board your choice.
-
Include the header mcc_generated_files/examples/rn487x_example.h in main.c
-
Call the function RN487X_Example_Initialized() in main(), after SYSTEM_Initialize().
-
Build and program the board.
-
Download a Phone Application for demostration: (either)
- Bluetooth Smart Discover by Microchip from the App Store or from Google Play.
- LightBlue by PunchThrough from the App Store or from Google Play.
-
The Application will automatically scan the area for Bluetooth devices within a range.
-
By default, the device should appear as "PIC-BLE", "AVR-BLE", "RN487X".
-
On selecting the "PIC-BLE", "AVR-BLE", "RN487X" device from the list; the application will interrogate the RN Module.
-
Once connected; the device information is shown on the view.
Note: The custom LightBlue configuration screen will be grayed out unless using the LightBlue example project.
- To enable the functionality again, program your board with the latest source code available:
-
Select the Properties Option: Write Notify Indicate Running the Example.
-
Select "Listen for notifications" on the application.
This is the END of the Basic Data Exchange Example
-
For Transparent Serial only: Open a "Serial Terminal" Program such as Tera Term, Realterm, PuTTY, Serial; or similar. Baud Rate will be configured as: 9600
-
Connection information is shown on the Terminal if there is one connected.
-
Captures Characters will be shown on the application in Hex formate.
-
Data will appear beneath the Notify/Listen Toggle Option area.
-
To issue data from the Phone Application to the RN Module. Select "Write new value".
This driver contains, at its' core, the inherent code capability of distinguishing between Message exchange and Data exchange between the connected MCU and Module devices. The library supplies all required Application Programming Interfaces (APIs) required to create functional implementation of operation a BLE connected end-device.
Through the MCC configuration the physical connection of the (3) required pins can be selected through the GUI. These are the (2) UART pins used for communication, and control of the RST_N connected to the RN487X Module.
Additionally; this Library allows for extension of Module pin behaviors through the simple RN487X Module object interface; where any device/project specific instantiations exist. rn487x_interface.c/h
A brief description of the Interface, and object extension is described below:
iRN487X_FunctionPtrs_t is a typedef struct which can be found in rn487x_interface.h and consist of (9) function pointers. In the rn487x_interface.c, the concrete creation of RN487X as an object is instantiated. Within rn487x_interface.c are the private static implementations of desired behavior. In some cases, such as DELAY or UART, the supporting behavior is supplied through another supporting library module. When applicable ‘inline’ has been used to reduce stack depth overhead.
The driver library itself should not require any modifications or injections by the user; unless to expand upon the supported command implementations. rn487x_driver.c/h
A single UART instance used for communication between MCU and Module:
The Library allows for configuration of (3) Pins associated with support features extended through the Driver Interface. Only (1) Pin is required by the RN487X Modules for operation; this is the modules RESET pin.
Library Name: Output(s) | Module: Input(s) | Description | Module Physical Defaults |
---|---|---|---|
BT_MODE | P2_0 | 1 : Application Mode 0 : Test Mode/Flash Update/EEPROM Cofiguration |
Active-Low, Internal Pull-High |
BT_RST | RST_N | Module Reset | Active-Low, Internal Pull-High |
BT_RX_IND | P3_3 | Configured as UART RX Indication pin | Active-Low |
This Driver Library also include select command implementations for advanced command usage in association with the BLE Module. These are described within the RN4870/71® Bluetooth Low Energy Module User’s Guide. The Driver Library does NOT support all commands described within the User’s Guide. API(s) will be generated to supported behaviors described below:
Allowed Behavior from Library | Refer to User Guide |
---|---|
Disconnect from Module | 2.6.25 |
Reboot Module | 2.6.28 |
Restore Factory Reset Default Settings | 2.4.14 - 2.4.15 |
Allowed Behavior from Library | Processing Action |
---|---|
Read Message | API used to Parse a Response Message |
Wait For Message | Response Effectively a BLOCKING method which will read continuously from the RN487X Module until a specific expected Message is received. |
Support 'Mode' Control | Supporting API(s) required for advanced usage of Modules capabilities. |
Allowed Behavior from Library | Refer to User Guide |
---|---|
Device Name | 2.4.18 |
Baud Rate | 2.4.5 |
Service Bit Map | 2.4.22 |
Features Bit Map | 2.4.21 |
Set I/O Capability | 2.4.4 |
PIN Code | 2.4.20 |
Status Message Delimiter | 2.4.3 |
Output | 2.6.7 |
Allowed Behavior from Library | Refer to User Guide |
---|---|
Input Values | 2.6.6 |
Receive Signal Strength Indicator (RSSI) Value | 2.6.26 |
The Driver Library include (2) example implementations for demonstration of use of the generated code.
Upon selecting an example, only the required API(s) will be selected by default. Minimal implementation of the capabilities of the driver library are used to allow for minimal baseline of size requirements.
Note:*
CONNECTION indicator driven by the RN487X Module (typically connected to an LED) relates only to if a device is CONNECTED but may not be yet exchanging Data.
The generated examples are:
This example shows how an MCU can be programmed to transmit data to a smart phone over BLE. Here the MCU device will send Periodic Transmission of a single character when STREAM_OPEN is processed through the Message Handler. This indicates to the MCU & RN487X Module that the application is in a DATA STREAMING mode of operation; and can expect to hear data over the BLE connection.
#define DEMO_PERIODIC_TRANSMIT_COUNT (10000)
#define DEMO_PERIODIC_CHARACTER (‘.’)
Are used in the example can be found #defined at the top of rn487x_example.c.
This example will demostrat data transmitted from a PC serial terminal is written to a smart phone app and vice versa. The MCU device will act as a bridge, and pass data between RN487X Module ← MCU → Serial Terminal. This action will occur when STREAM_OPEN is processed through the Message Handler. For this example, data typed into the Serial Terminal will appear on the BLE Phone Application, and Data sent from the Application will appear on the Serial Terminal.