RN4870 Operating Modes
Data Mode In Data mode, any serial data sent into the RN4870's Universal Asynchronous Receiver/Transmitter (UART) will be transferred to the connected peer device via Transparent UART Bluetooth® service.
Command Mode In Command mode, the American Standard Code for Information Interchange (ASCII) commands sent over the UART are used to control and configure the RN4870 module.
Scripting Mode The script capability enables the RN4870 module to run relatively simple operations without a host microcontroller unit (MCU).
Remote Command Mode Remote Command mode allows a remote device to access Command mode remotely via Bluetooth link.
DataCommand.png

Data Mode (Default)

The RN4870 introduces a private Generic Attribute Protocol (GATT) service named “Transparent UART”. This service simplifies serial data transfers over Bluetooth Low Energy (BLE) devices. When the RN4870 is in Data mode and it is connected to another BLE device, the RN4870 acts as a data pipe. This means that any serial data sent into the RN4870 UART will be transferred to the connected peer device via Transparent UART Bluetooth service. When data is received from the peer device over the air via Transparent UART connection, this data outputs directly to the UART as well. Data mode is the default mode of the RN4870.

Procedure For Connecting Two Modules Via Transparent UART

Module #1
SS,C0                // Command to enable Device Information Profile and 
                     // Transparent UART services
R,1                  // Reboot. Needed for all Set commands to take effect

Module #2
SS,C0
R,1
F                    // Starts scanning for peripheral devices and also
                     // returns the MAC address along with other relevant data
C,0,<MAC Address>    // Command to attempt a connection with the desired remote device

Command Mode

In a typical use case, a host MCU uses ASCII commands over UART to control and exchange data with the RN4870 BLE module. The RN4870 could be set into Command mode for configuration and/or control operations. In Command mode, all UART data are treated as ASCII commands sent into the module's UART interface. The ASCII commands can control functions such as connection setup/teardown, accessing GATT characteristics, changing configuration settings, and reading status.

To enter Command mode from Data mode, type $ into a terminal emulator with the following settings:

UART Setting Default value
Baud Rate 115200
Data Bits 8
Parity None
Stop Bits 1
Flow Control Disabled

Once the RN4870 enters Command mode, you will see a CMD> prompt sent to the UART to indicate the start of the Command mode session.

The list of commands available on the RN4870 can be classified into the following groups:

  • Action commands - used to start a process or functionality or display information.
  • Set/Get commands - used to configure or read the configuration of the various functions of the module.
  • List commands - used to list critical information in multiple lines.
  • Service definition - used to define services and their characteristics.
  • Characteristic access - used to access and write the server/client characteristics.
  • Script control - used for the scripting process of the module.

All commands must end with a carriage return ('\r'). The RN4870 will send responses to all commands sent by the host MCU. In most cases, Set or Action commands sent by the host MCU get the response AOK. However, there are many command-specific responses. By default, when the RN4870 is ready to receive the next command, the command prompt CMD> is sent to UART. It is strongly recommended that the host MCU wait until responses are received for commands sent before sending the next command.

If you wish to return to Data mode, enter --- at the command prompt; you will then see a END message indicating the command session has been terminated.

Script Mode

The scripting capability enables the RN4870 module to run relatively simple operations without a host MCU. Script mode enables the user to write ASCII based script into the RN4870's Non-Volatile Memory (NVM) and execute the application logic automatically through the script. A script consists of ASCII commands that do not need to be compiled or processed, it remains in the RN4870's NVM and does not alter the core firmware in any way.

To enter Script Input mode, enter the WW command. When in Script Input mode, the script can be input through the UART line by line, terminated by either a Carriage Return (\r) or a Line Feed (\n). Once all script lines are input, press the Esc (\x1b) key to exit the Script Input mode.

The RN4870 scripting is event-driven. All event scripts start with an event label followed by one or more logic operations or ASCII commands. If an event label is defined, once that event is triggered, control is passed over to the script engine. The script engine starts executing the commands that are listed below the event label until the end of the script or until encountering another event label. There are currently 12 defined events:

Power On Timer 1 Expired
Timer 2 Expired Timer 3 Expired
Connected Disconnected
Trigger Pin 1 Rising Edge Trigger Pin 1 Falling Edge
Trigger Pin 2 Rising Edge Trigger Pin 2 Falling Edge
Trigger Pin 3 Rising Edge Trigger Pin 3 Falling Edge

More details can be found in Chapter 3 of the RN4870/71 Bluetooth Low-Energy Module User's Guide.

Remote Command Mode

RN4870 has the capability of Remote Command mode over the UART transparent connection. This feature enables the user to execute commands on a connected peer device. The command is sent to the connected remote device, executed at the remote device, and the result is sent back to the local device.

Remote Command mode provides a method to enable stand-alone implementation without a host MCU for the remote device. A local device can use Remote Command mode to get access to the remote device (module) and control of all its analog or digital I/O ports. All application logic can be performed locally without the remote device's interference. Therefore, there is no required programming or application logic to run on the remote device, making the remote device extremely easy to implement at a low cost.

Before using the Remote Command mode, the UART Transparent service should be enabled using the SS command, (specifically SS,C0 to support device info and UART Transparent services).

Certain conditions must be met to use the Remote Command mode. Ensure that:

  • both local and remote devices support UART Transparent feature.
  • the two devices are already connected and secured.

To enter Remote Command mode, use the command !,1.

Upon receiving the request to start the Remote command session, the RN4870 will accept the request if the following conditions are met:

  • the BLE link between devices is secured.
  • both local and remote devices must share the same pin code (SP command).

If the above conditions are not met, BLE link will be disconnected immediately. Once you are in Remote Command mode, the command prompt CMD> will be changed to RMT>.

To exit Remote Command mode, the local device needs to get back to Command mode by typing $, followed by command !,0.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.