|CMD/Command||ASCII commands sent over the UART are used to control and configure the RN4020.|
|MLDP/Data||Microchip Low-Energy Data Profile enables asynchronous serial data transport over Bluetooth® Low Energy.|
|Scripting ("Hostless")||The RN4020 internal scripting capabilities enable basic functions to be implemented without the need for external host MCU or software development tools.|
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 Bluetooth® Low Energy 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.
- I2C Commands - used to provide access to the I2C master interface on pins 21 (SDA) and 22 (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.
- Microchip 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.
- DFU Commands - used to upgrade 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:
To exit Command mode, set WAKE_SW low. The module exits Command mode by outputting “END” to the UART
The Microchip Low-energy Data Profile (MLDP) is a private BTLE service that allows applications to move serial data over Bluetooth LE; it basically turns the interface into a simple UART. MLDP provides a 50 kbps serial data transport over Bluetooth Low Energy 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 BTLE 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.
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 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 script or until another event label is encountered.
|PIO4 (pin 13) Input Change to Low||@PIOL|
|PIO4 (pin 13) Input Change to High||@PIOH|
|High Priority Alert||@ALERTH|
|Low Priority Alert||@ALERTL|
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.