Skip to content

microchip-pic-avr-examples/rn4870-rn4871-examples-mplab-mcc

Repository files navigation

MCHP

RN4870 | RN4871 BLE Module v1.0.0 Library

Getting Started Guide

What is the RN4870 | RN4871 BLE Module Library?

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.


Driver Information


EcoSystem


HostMCU


ExampleHookUp


RN487X_MCC


Related Documentation

Software Used

Hardware Used

Setup

To install the MPLAB® Code Configurator Plugin:

  1. In MPLAB X IDE, select Plugins from the Tools menu.
  2. Select the Available Plugins tab.
  3. Check the box for the MPLAB® Code Configurator v3, and click on Install.

To install the RN4870 | RN4871 BLE Module Library:

  1. Open the MPLAB Code Configurator page: https://www.microchip.com/mcc
  2. Scroll to the bottom of the page and select the Current Downloads tabs.
  3. Download the RN4870 | RN4871 BLE Module Library (rn487x_ble_module-1.0.0.mc3lib).
  4. 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.
  5. Click on Plugins tab.
  6. Click on Install Library.
  7. Browse to the location where you saved rn487x_ble_module-1.0.0.mc3lib, select and click Open.

Operation

Part 1: Setup and Generation

  1. Create a New Project in MPLAB® X IDE.
    mplabIcon

  2. The Process described below is reflective of the Validation Hardware used: LightBlue. Microcontrollers used for reference are the PIC16LF18456 and ATmega3208 8-bit devices.
    selectMCC

  3. Open MCC by clicking ToolsEmbeddedMPLAB® Code Configurator OR click on the MCC icon.
    mccIcon

  4. 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.
    installPlugin

  5. 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.
    configurationMccSetup

  6. From the In the Device Resources panel under Libraries dropdown select: RN4870 | RN4871 BLE Module.
    selectRnLibrary

  7. 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.
    alertMessages

  8. 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.
    guiViewUsingExampleMarked


selectExample

  1. 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.

  1. 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.


9600_screenshot


115200_screenshot


BASIC DATA EXCHANGE (1) UART & (1) GPIO


PIC16LF18456 MCC Configuration - Basic Data Exchange Example


libUartBasicPIC
setupUartBasicPIC
setupPinModuleBasicPIC
setupDefaultBasicPIC


ATMega3208 MCC Configuration - Basic Data Exchange Example


libUartBasicAVR
setupUartAVR_Basic
setupPinModuleBasicAVR
setupUartAVR_Basic


TRANSPARENT SERIAL (2) UART & (1) GPIO


PIC16LF18456 MCC Configuration - Transparent Serial Example


libUartSerialPIC
setupUartBasicPIC
setupPinModuleTransparentPIC
setupDefaultTransparentPIC


ATMega3208 MCC Configuration - Transparent Serial Example


libUartSerialAVR
setupUartAVR
setupPinModuleTransparentAVR
setupDefaultTransparentAVR


  1. 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.

  2. Click the Generate button.
    generateCode

  3. Connect the development board your choice.

  4. Include the header mcc_generated_files/examples/rn487x_example.h in main.c

  5. Call the function RN487X_Example_Initialized() in main(), after SYSTEM_Initialize().

  6. Build and program the board.


PIC Implementation:
implementExamplePIC


AVR Implementation:
implementExampleAVR


Running the Example


Part 2: How to use the Generated Example(s)

  1. Download a Phone Application for demostration: (either)

  2. Launch the Phone Application
    SmartDiscoverlightBlue


OpenScreen lightBlueSplash

  1. The Application will automatically scan the area for Bluetooth devices within a range.

    • Use of the Filter (LightBlue only) will limit the Signal strength of devices populating the "Peripherals Nearby".
      filter
  2. By default, the device should appear as "PIC-BLE", "AVR-BLE", "RN487X".
    FoundDeviceFoundDeviceLB

  3. On selecting the "PIC-BLE", "AVR-BLE", "RN487X" device from the list; the application will interrogate the RN Module.
    InterrogateLBViewLB

  4. 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.

  1. Select the Properties Option: Write Notify Indicate Running the Example.
    Connected2selectNotify

  2. Select "Listen for notifications" on the application.

    • It may be required to "enable notification" access to the app on the phone.
    • Data will begin to Send at a Periodic Rate to the device.
    • Data will become visible beneath the Notify/Listen Toggle Option.
      NotifyDataData

This is the END of the Basic Data Exchange Example


ONLY Transparent Serial steps remain below:

  1. 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
    terminalOpenterminalSettings

  2. Connection information is shown on the Terminal if there is one connected.
    terminalStreamOpen

  3. Captures Characters will be shown on the application in Hex formate.
    terminalCharacter

  4. Data will appear beneath the Notify/Listen Toggle Option area.
    NotifyDataLog
    showDataLightBlue

  5. To issue data from the Phone Application to the RN Module. Select "Write new value".

    • Captures Characters will be shown on the application in Hex formate.
    • Enter a hex value; and press the "Write" or "Done" to issue data exchange.
    • The character sent will be shown on the terminal screen.
    • Depending upon Terminal settings; it may be displayed in ACII format.
      Write
      terminalHello
      WriteLBwriteHexLight
      terminalCharacter
      SelectHex

Summary

Command, Data Communication with Asynchronized Message Processing:

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.


Interface

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

Configurable Module Hardware Requirement(s):

A single UART instance used for communication between MCU and Module:


uartInstance

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.


rnPinSetup

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

Basic Application Ready API(s):

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:


mccCommands

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


mccData

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.


mccSet

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


mccGet

Allowed Behavior from Library Refer to User Guide
Input Values 2.6.6
Receive Signal Strength Indicator (RSSI) Value 2.6.26

Simple Example(s):

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:

Basic Data Exchange:

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.

Transparent Serial:

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.

About

Out of Box Generated Examples supporting RN4870 | RN4871 BLE Modules MCC Library. Examples used existing BLE-Development Boards as a platform.

Resources

Stars

Watchers

Forks

Packages

No packages published