link to page 7 link to page 8 link to page 13 link to page 9 link to page 10 link to page 10 link to page 10 link to page 11 link to page 15 link to page 83 link to page 99 RN4020 BLUETOOTH LOW ENERGYMODULE USER’S GUIDEPrefaceNOTICE TO CUSTOMERSAll documentation becomes dated, and this manual is no exception. Microchip tools and documentation are constantly evolving to meet customer needs, so some actual dialogs and/or tool descriptions may differ from those in this document. Please refer to our web site (www.microchip.com) to obtain the latest documentation available.Documents are identified with a “DS” number. This number is located on the bottom of each page, in front of the page number. The numbering convention for the DS number is “DSXXXXXXXXA”, where “XXXXXXXX” is the document number and “A” is the revision level of the document.For the most up-to-date information on development tools, see the MPLAB® IDE online help. Select the Help menu, and then Topics to open a list of available online help files.INTRODUCTION This chapter contains general information that will be useful to know before using the RN4020 Bluetooth® Low Energy Module. Items discussed in this chapter include: • Document Layout • Conventions Used in this Guide • Recommended Reading • The Microchip Web Site • Development Systems Customer Change Notification Service • Customer Support • Document Revision History DOCUMENT LAYOUT This document describes how to use the RN4020 Bluetooth® Low Energy Module as a development tool to emulate and debug firmware on a target board. This document includes the following chapters: • Chapter 1. “Introduction” provides a brief overview of the RN4020, highlighting its features and uses. • Chapter 2. “RN4020 Command Interface” provides information on the module interface. • Chapter 3. “Application Examples” provides application examples that emphasize the features of the RN4020. • Appendix A. “PICtail™ Daughter Board Schematics” provides schematic diagram information for the PICtail Daughter Board. 2014 Microchip Technology Inc. DS70005191B-page 7 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