|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, 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 (MCU).|
|Remote Command Mode||Remote command mode allows a remote device to access Command mode remotely via Bluetooth link.|
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 connect to the MAC address specified in parameter #2
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|
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 start a process or a functionality or display information.
- Set/Get commands - used to configure or read the configuration of the various functions of the module.
- List commands - 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 microcontroller. In most cases, Set or Action commands sent by the host microcontroller 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 microcontroller 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 and END message indicating the command session has been terminated.
The script 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 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 Script Input.
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 12 currently defined events:
|Power On||Timer 1 Expired|
|Timer 2 Expired||Timer 3 Expired|
|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 on 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 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), as well as access and control to all its analog or digital I/O ports. All application logics 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 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).
There are certain conditions that must be met in order to use Remote Command mode, they include:
- 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.