User Guide RN4020 (Microchip) - 67

ManufacturerMicrochip
DescriptionBluetooth Low Energy Module
Pages / Page104 / 67 — RN4020 Command Interface. 2.3.8. RN4020 Scripting Commands. TABLE 2-15:. …
File Format / SizePDF / 945 Kb
Document LanguageEnglish

RN4020 Command Interface. 2.3.8. RN4020 Scripting Commands. TABLE 2-15:. LIST OF EVENTS AND EVENT LABELS. Event. Event Label

RN4020 Command Interface 2.3.8 RN4020 Scripting Commands TABLE 2-15: LIST OF EVENTS AND EVENT LABELS Event Event Label

Model Line for this Datasheet

Text Version of Document

link to page 67
RN4020 Command Interface 2.3.8 RN4020 Scripting Commands
2.3.8.1 RN4020 SCRIPTING CAPABILITIES In a typical setup, a host MCU via ASCII commands drives the RN4020 BLE module over the UART interface. However, for simple applications that do not require the I/O and computing functions of a host MCU, the RN4020 on-board I/O and scripting capabilities can be used. These scripts are ASCII commands that do not need to be compiled or processed before writing to the RN4020. The RN4020 firmware is not changed by writing, reading or executing the scripts. Scripts are written into the NVM of the RN4020 module, so a power cycle does not affect the script contents. The scripting capability on the RN4020 module may be useful under the following circumstances: • Reduced cost of the host MCU • The user application uses proprietary service and characteristics • The user application lends itself to the analog or digital ports that are available on the RN4020 • The user application logic is simple; instead of the RN4020, a peer device can perform interpolation of data • A script cannot exceed 1000 bytes and be less than 100 lines • The scripting capability can also be used to lower the load of the host MCU and can be used to initialize settings and perform operations once a certain event is triggered • User-defined functions (only available in Firmware Version 1.20 or later) 2.3.8.1.1 RN4020 Script Fundamentals The main functionalities of scripting are achieved by executing ASCII commands, which are the same as those via the UART interface. 2.3.8.2 EVENT DRIVEN A script is driven by events. Currently, there are 11 events defined. Table 2-15 lists the supported events and their labels. 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.
TABLE 2-15: LIST OF EVENTS AND EVENT LABELS Event Event Label
Power On @PW_ON Timer1 expired @TMR1 Timer2 expired @TMR2 Timer3 expired @TMR3 Connected @CONN Disconnected @DISCON 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  2014 Microchip Technology Inc. DS70005191B-page 67 Document Outline Preface Introduction Document Layout Conventions Used in this Guide Recommended Reading The Microchip Web Site Development Systems Customer Change Notification Service Customer Support Document Revision History Chapter 1. Introduction 1.1 Bluetooth Low Energy Fundamentals Table 1-1: Characteristic Properties Chapter 2. RN4020 Command Interface 2.1 RN4020 Control Lines Figure 2-1: RN4020 Module Pin Diagram Table 2-1: RN4020 Module Pin Description 2.2 GAP Role Switching Table 2-2: Role Switch Commands 2.3 RN4020 UART-ASCII Command and Responses Table 2-3: RN4020 UART Configuration Table 2-4: Command Descriptions 2.3.1 Set/Get Commands Example 2-1: Set Command Format Table 2-5: UART Baud Rate Settings Table 2-6: SP Level/TX Power Out Table 2-7: Bitmap Features Table 2-8: Bitmap Services Table 2-9: Connection Parameters 2.3.2 Action Commands Table 2-10: Bitmap of “|O” and “|I” Commands 2.3.3 I2C™ Commands Table 2-11: I2C™ Commands 2.3.3.1 Enable I2C 2.3.3.2 Disable I2C 2.3.3.3 I2C EEPROM Access 2.3.3.4 I2C Basic Operations Table 2-12: I2C™ Events 2.3.3.5 Example of Accessing the Microchip I2C EEPROM 24LC512 Figure 2-2: Writing Data via the I2C™ Interface Figure 2-3: Reading Data via the I2C™ Interface 2.3.4 PWM Commands Figure 2-4: PWM Waveform Table 2-13: PWM Parameters 2.3.5 Characteristic Access Commands 2.3.5.1 Definition of Characteristic Access Commands Example 2-2: Listing Client Service and Characteristics 2.3.6 Private Service Configuration Commands Table 2-14: Security flags of characteristic 2.3.7 Microchip MLDP Commands 2.3.7.1 Microchip Low-Energy Data Profile (MLDP) 2.3.7.2 MLDPv2 2.3.8 RN4020 Scripting Commands 2.3.8.1 RN4020 Scripting Capabilities 2.3.8.2 Event Driven Table 2-15: List of Events and Event Labels 2.3.8.3 Comments 2.3.8.4 Variables 2.3.8.5 Remote Function Call Example 2-3: Function Example 2.3.9 RN4020 Script Commands Table 2-16: “WR” Command Input Parameters and Associated Events 2.3.10 Remote Command 2.4 Summary of RN4020 UART Outputs 2.4.1 ASCII Commands with Non-Standard Response Table 2-17: Non-Standard Response for ASCII Commands 2.4.2 UART Response to PIO Switches Table 2-18: UART Response to PIO Events 2.4.3 UART Notifications Table 2-19: UART Notification 2.5 Device Firmware Upgrade 2.5.1 DFU Commands Chapter 3. Application Examples 3.1 Demonstration with a Smart Device 3.1.1 Setup 3.1.2 Running the Demonstration Figure 3-1: Discovering the RN4020 Module Figure 3-2: Reading the Model Number String From the Device Information Service Figure 3-3: Reading Battery Level in Battery Service Figure 3-4: Notification Result of Battery Level Example 3-1: User-Defined Private Services Figure 3-5: Private Services Discovered After Power Cycle Figure 3-6: Reading the Private Characteristic Figure 3-7: Writing Values to Private Characteristics Figure 3-8: Notification to Private Characteristic 3.2 Connecting Two RN4020 Modules 3.2.1 Configure the First Device (Module A) 3.2.2 Configure the Second Device (Module B) 3.2.3 Connecting the Two Devices 3.2.4 Checking Server and Client Services Table 3-1: Module A Server and Client Services Table 3-2: Module B Server and Client Services 3.2.5 Setting the Battery Service 3.3 MLDP Demonstration 3.4 RN4020 Scripting Demonstration 3.4.1 Setting Up Private Service and Characteristics 3.4.2 Script Input 3.4.3 Running the Script Appendix A. PICtail™ Daughter Board Schematics Figure A-1: RN4020 Module Figure A-2: PIC18LF25K50-I/ML Device Figure A-3: 28-pin and 30-pin PICtail™ Connectors Figure A-4: RN4020 Module Breakout Pins Figure A-5: Status LEDs Figure A-6: Voltage Regulator Figure A-7: Decoupling Capacitor for the PIC18LF25K50-I/ML Device Figure A-8: Test Switch Figure A-9: ICSP™ Connector Corporate Office Atlanta Austin, TX Boston Chicago Cleveland Fax: 216-447-0643 Dallas Detroit Houston, TX Indianapolis New York, NY San Jose, CA Canada - Toronto Fax: 852-2401-3431 Australia - Sydney China - Beijing China - Shanghai India - Bangalore Korea - Daegu Korea - Seoul Singapore Taiwan - Taipei Fax: 43-7242-2244-393 Denmark - Copenhagen France - Paris Germany - Dusseldorf Germany - Pforzheim Italy - Milan Italy - Venice Spain - Madrid Worldwide Sales and Service