RN4020 Operating Modes

Last modified by Microchip on 2023/11/09 09:03

CMD/CommandASCII commands sent over the Univeral Asynchronous Receiver Transmitter (UART) are used to control and configure the RN4020.
MLDP/DataMicrochip Low-Energy Data Profile (MLDP) enables asynchronous Serial Data (SDA) transport over Bluetooth® Low Energy (BLE).
Scripting ("Hostless")The RN4020 internal scripting capabilities enable basic functions to be implemented without the need for external host MCU or software development tools.

Command Mode

In Command mode, control takes place through ASCII commands and their parameters. All commands and parameters are separated by commas and no spaces are allowed between them. Commands are terminated by a carriage return (\r). Generally, most valid commands return AOK, while invalid ones return ERR. However, there are various ASCII commands that return non-standard responses; they are all listed in the RN4020 BLE Module User's Guide. The following is a list of the different types of commands and a brief description of what they are used for:

  • Set/Get Commands: Used to configure specific functions of the RN4020 module. These commands start with the letter S and are followed by one or two letters as the command identifier.
  • Action Commands: Used to initiate functionality, as well as display critical information.
  • I²C Commands: Used to provide access to the I²C Master interface on pins 21 (SDA) and 22 (Serial Clock (SCL)) on Firmware Version 1.20 or later.
  • PWM Commands: Used to support up to four HIGH/LOW Pulse Width Modulation (PWM) patterns on Firmware Version 1.20 or later.
  • Characteristic Access Commands: Used to provide access to the values and configurations of characteristics.
  • Private Service Configuration: Used to define the private service and its private characteristics.
  • MLDP Commands: Used for MLDP service on RN4020.
  • RN4020 Scripting Commands: Used for scripting functionality of RN4020.
  • Remote Command: Used for executing ASCII commands remotely from connected devices.
  • Device Firmware Upgrade (DFU) Commands: Used to upgrade the firmware on RN4020.

To enter Command mode, set the WAKE_SW pin high. (This is the default state for the RN4020 PICTail.)

The default UART port configuration is shown in the following table:

Baud Rate115200
Data Bits8
Stop Bits1
Flow ControlNone

To exit Command mode, set WAKE_SW low. The module exits Command mode by outputting END to the UART.

Back to Top


The MLDP is a private BLE service that allows applications to move SDA over BLE; it basically turns the interface into a simple UART. MLDP provides a 50 kbps SDA transport over BLE on the RN4020. The throughput of MLDP communication highly depends on the connection parameters, which decide the frequency of communication between central and peripheral devices. Higher throughput requires more frequent communication between the two devices, and therefore consumes more power and shortens battery life. If battery life is the priority of the application, the expectation of MLDP throughput can be lowered.

Built on top of the BLE Generic Attribute Profile (GATT), Microchip developed the private service MLDP to simulate the operation of Classic Bluetooth Serial Port Profile (SPP). To enable MLDP, the MLDP bit has to be set; this can be done using the SR,10000000 command. Once MLDP is enabled, connection parameters are decided and an active link has been established between a central and peripheral device, we enter MLDP mode by setting CMD/MLDP high. All data input from the UART module of the RN4020 is sent to the peer device as a data stream while using MLDP. Remember, however, that to run MLDP between two RN4020 modules, both devices must have the MLDP feature enabled.

To exit MLDP mode, CMD/MLDP (pin 8) must be set low. The RN4020 module will then immediately go back to Command mode by outputting CMD to the UART.

Back to Top

Scripting Mode

The scripting capabilities of the RN4020 can be used for simple applications that do not require the I/O and computing functions of a host MCU. Scripts are ASCII commands that do not need to be compiled or processed before writing to the RN4020. They do not change the RN4020 firmware and are written into the Non-Volatile Memory (NVM) of the RN4020 module which means that a power cycle does not affect script contents.

The main functionalities of scripting are achieved by executing ASCII commands (the same ones we use in Command mode); however, a script is driven by events. Currently, there are 11 events defined. All event scripts start with an event label, which is then followed by one or more logic operations or ASCII commands. Once an event is triggered, if an event label is defined, control is passed over to the script engine. The script engine begins executing the commands that are listed following the event label until the end of the script or until another event label is encountered.

EventEvent Label
Power ON@PW_ON
Timer1 expired@TMR1
Timer2 expired@TMR2
Timer3 expired@TMR3
PIO4 (pin 13) Input Change to Low@PIOL
PIO4 (pin 13) Input Change to High@PIOH
High Priority Alert@ALERTH
Low Priority Alert@ALERTL
Alert Off@ALERTO

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 END status message is returned to indicate Script Input is completed and Command mode is resumed.

Back to Top