AN91184 RAMTRON | Alldatasheet

Document overview

  • Manufacturer or author: Provided By ALLDATASHEET.COM(FREE DATASHEET DOWNLOAD SITE)
  • PDF pages: 36

Technical content

www.cypress.com Document No. 001-91184 Rev. *B 1 AN91184 PSoC® 4 BLE – Designing BLE Applications Author: Pushek Madaan Associated Project: Yes Associated Part Family : CY 8C4XX7 -BL, CY8C4XX8 -BL, CYBL10X 6X, CYBL10X7X Software Version: PSoC Creator ™ 3.2 Related Application Notes: click here AN91184 shows how to design a Bluetooth ® Low Energy (BLE) application based on PSoC 4 BLE, using standard profiles defined by the Bluetooth SIG that are included in the BLE Component in PSoC Creator. It demonstrates how to build an application with the BLE Health Thermometer Profile on the CY8CKIT -042-BLE kit. This application note also applies to the PRoC BLE part.

Contents

1 Introduction

Bluetooth Low Energy (BLE) is an ultra -low-power wireless standard introduced by the Bluetooth Special Interest Group (SIG) for short-range communication . The BLE physical layer, protocol stack , and profile architecture are designed and optimized to minimize power consumption. Similar to Classic Bluetooth, BLE operates in the 2.4-GHz ISM band but with a lower bandwidth of 1 Mbps. Cypress’s PSoC 4 BLE is a programmable embedded system -on-chip (SoC), integrating BLE along with programmable analog and digital peripheral functions, memory, and an ARM® Cortex®-M0 microcontroller on a single chip. This application note discusses how to use the PSoC Creator BLE Component to design a BLE Health Thermometer application using the Health Thermometer standard profile, and then validate the application using the CySmart Central Emulation Tool and the CySmart mobile app. The PSoC Crea tor BLE Component has the standard profiles pre-built; this makes it very easy to use these services in BLE-enabled projects. This application note assumes that you are familiar with the basics of BLE, PSoC, the PSoC Creator IDE , and temperature measurement using a thermistor. Refer to the following links:  AN91267 – Getting Started with PSoC 4 BLE  PSoC Creator home page  AN66477 – PSoC® 3, PSoC 4, and PSoC 5LP – Temperature Measurement with a Thermistor

PSoC® 4 BLE – Designing BLE Applications www.cypress.com Document No. 001-91184 Rev. *B 2

2 PSoC Resources

Cypress provides a wealth of data at www.cypress.com to help you to select the right PSoC device and qu ickly and effectively integrate it into your design. For a comprehensive list of resources, see KBA86521, How to Design with PSoC 3, PSoC 4, and PSoC 5LP. The following is an abbreviated list for PSoC 4 BLE:  Overview: PSoC Portfolio, PSoC Roadmap  Product Selectors: PSoC 1, PSoC 3, PSoC 4, or PSoC 5LP. In addition, PSoC Creator includes a device selection tool.  Datasheets describe and provide electrical specifications for the PSoC 41XX-BL and PSoC 42XX-BL device families.  Application Notes and Code Examples cover a broad range of topics , from basic to advanced level. Many of the application notes include code examples. PSoC Creator provides additional code examples — see Code Examples.  Technical Reference Manuals (T RMs) provide detailed descriptions of the architecture and registers in each PSoC 4 BLE device family.  CapSense Design Guide : Learn how to design capacitive touch-sensing applications with the PSoC 4 BLE family of devices.  Development Tools  CY8CKIT-042-BLE Bluetooth Low Energy (BLE) Pioneer Kit includes connectors for Arduino™ compatible shields and Digilent® Pmod™ daughter cards.  CySmart BLE Host Emulation Tool for Windows, iOS, and Android is an easy -to-use GUI that enables you to test and debug your BLE Peripheral applications.

2.1 PSoC Creator

PSoC Creator is a free Windows -based Integrated Design Environment (IDE). It enables you to design hardware and firmware systems concurrently, based on PSoC 4 BLE and PRoC BLE. As Figure 1 shows, with PSoC Creator, you can: 1. Drag and drop Components to build your hardware system design in the main design workspace. 2. Co-design your app lication firmware with the PSoC hardware. 3. Configure the Components using configuration tools. 4. Explore the library of more than 100 Components. 5. Review the Component datasheets.

Figure 1. PSoC Creator Schematic Entry and Components

2.2 PSoC Creator Help

developing PSoC Creator projects. demonstrate how to configure and use PSoC Creator Components. the unique features of PSoC 4 BLE. and describes the system functions provided by PSoC Creator. Component Datasheets page for a list of all PSoC 4 BLE Component datasheets. document resources. To open the document manager, choose the menu item Help > Document Manager.

2.3 Code Examples

PSoC Creator includes a large number of code example projects. Error! Reference source not found. shows. PSoC 4, PSoC 4 BLE, PRoC BLE, and so on; category; or keyword. get started, as shown in Figure 3. Figure 2. Code Examples in

Figure 3. Code Example Projects with Sample Code

2.4 Technical Support

number: +1-800-541-4736. Select option 8 at the prompt.

3 Standard Services Versus Custom Services

Portal for the complete list of standard services. the amount of energy expended over a specified interval. as they allow you to deploy BLE devices that can have custom applications.

3.1 BLE Health Thermometer

Figure 4. BLE System Design

4 PSoC Creator Project: Health Thermometer

 A BLE Component that operates as the Peripheral at the GAP layer and as the GATT server at the GATT layer.  An ADC, which measures the voltage across a thermistor.  A thermistor calculator, which calculates the temperature using the ADC reading.  A user button, which wakes up the system from the Hibernate mode. Figure 5 shows the PSoC Creator schematic of the Health Thermometer project. Figure 5. PSoC Creator Schematic

4.1 Configure the Component

  1. Create a new PSoC 4100 BLE / PSoC 4200 BLE Design project. If you are new to PSoC Creator, refer to the
  2. Drag and drop a BLE Component (Component Catalog > Communications) into the TopDesign schematic (refer

Figure 6. BLE Component

  1. Double-click the BLE Component to configure it. The configuration window appears as shown in Figure 7.

Figure 10. Temperature Measurement Characteristic of the characteristic Measurement Interval. Table 1. Characteristic Configuration

Keep the remaining settings at their default values.

  1. Configure the Bluetooth Device Address (BD_ADDR), the Device name, and the Appearance under General

settings of the GAP Settings tab, per Table 2. Table 2. General Settings option to select one of the possible values. the Company ID of Cypress Semiconductor. You should use your 24-bit Company ID assigned by IEEE.

4.2 Configure the Firmware

Figure 25 shows the firmware flow for the Health Thermometer application. Figure 25. System Flowchart

Note: Source files for the application firmware are in the example project that is included with this application note. are nine source files for the example project which are listed in Table 5. Table 5. Example Project Source Files control, and low-power implementation.  InitializeSystem() – Initializes all the blocks of the system.  WakupFromDeepSleep() – Restores the hardware blocks for normal operation. sensor simulation option is selected. For more details, refer to the Sensor Simulation section.  ProcessTemperature() – This function measures or simulates the temperature value.  WatchdogTimer_Start() – Starts the watchdog timer (WDT0) with a 1-s period and an interrupt on match. callback from the watchdog timer.  WatchdogTimer_Stop() – Stops the watchdog timer (WDT0).  GenericEventHandler() – Handles the generic events generated by the BLE stack.  HtssEventHandler() – Handles the events generated for the Health Thermometer Service.  ProcessBLE() – Sends the temperature data as Indication to the GATT Client.  EnableBLE() – Starts the BLE Component and registers the event handler functions. project for the complete firmware. These states are discussed in detail in the following sections.

PSoC® 4 BLE – Designing BLE Applications www.cypress.com Document No. 001-91184 Rev. *B 23

4.2.1 System Initialization

When the device is reset or wakes up from the Hibernate mode, the firmware performs initialization , which includes starting the SAR ADC, enabling global interrupts , starting the opamps, and starting the watchdog timer . After the system is initialized, it initializes the BLE Component, which handles the initialization of the complete BLE subsystem. Note: As part of the B LE Component initialization, the user code must pass a pointer to the event-handler function that should be called to receive events from the BLE stack. The Generic Event Handler shown in Figure 25 is registered as a part of the BLE initialization. Code 1 shows the code to start the BLE Component and register the Generic Event Handler. Code 1. BLE Initialization apiResult = CyBle_Start(GenericEventHandler); If the BLE Component initializes successfully, the firmware registers the function that is called to receive the events for the Health Thermometer Service and switches to the normal operation mode . Code 2 shows the snippet for registering the Health Thermometer Service. Code 2. Health Thermometer Service Event Handler CyBle_HtsRegisterAttrCallback(HealthThermometetEventHandler);

4.2.2 Event Handler

In the BLE Component, results of any operation performed on the BL E stack are relayed to the application firmware via a list of events. These events provide the BLE interface status and data. Events can be categorized as follows:  Common events Operations performed at the GAP layer, the GATT layer, and the stack’s L2CAP layer generate these events. For example, a CYBLE_EVT_STACK_ON event is received when the BLE stack is initialized and turned ON, a CYBLE_EVT_GAP_DEVICE_CONNECTED event is received when a connection with a remote device is established, and a CYBLE_EVT_GATTS_WRITE_CMD_REQ event is generated when a Write Command is received from the client. For more details on common events, refer to the API documentation of the BLE Component (right-click the BLE Component in PSoC Creator and select Open API Documentation). The application firmware must include an event handler function to successfully establish and maintain the BLE link. Code 3 shows the implementation of the GenericEventHandler function, where events generated on the initialization of the BLE stack, device connection, disconnection, and timeout are handled.  Service-specific events Service-specific events are generated because of operations performed on the standard services defined by the Bluetooth SIG. For example, a CYBLE_EVT_HTSS_INDICATION_ENABLED event is received by the server when the client writes the client configuration characteristic descriptor to enable the indication for the Temperature Measurement Characteristic. For more details on service -specific events, refer to the API documentation of the BLE Component. The BLE Component can route these events to a service -specific event handler. The application firmware should include a service-specific event handler function to handle these events. If a service-specific event handler is not supported, then these events must be handled by the common event handler (GenericEventHandler). Code 4 shows the implementation of the service-specific event handler called HtssEventHandler. Code 3. Generic Event Handler void GenericEventHandler(uint32 event, void *eventParam) switch(event) /* This event is received when component is Started */ case CYBLE_EVT_STACK_ON: /* Stop watchdog to reduce power consumption during advertising */ WatchdogTimer_Stop(); /* Start Advertisement and enter Discoverable mode*/ CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);

PSoC® 4 BLE – Designing BLE Applications www.cypress.com Document No. 001-91184 Rev. *B 24 break; /* This event is received when device is disconnected or advertising times out*/ case CYBLE_EVT_GAP_DEVICE_DISCONNECTED: case CYBLE_EVT_TIMEOUT: /* Sets the ENABLE_HIBERNATE flag to put system in Hibernate mode */ SystemFlag |= ENABLE_HIBERNATE; break; /* This event is received when connection is established */ case CYBLE_EVT_GATT_CONNECT_IND: /* Start watchdog timer with 1s refresh interval */ /* Note: For this application, wakeup should be 1s because htssInterval * resolution is configured as 1s */ WatchdogTimer_Start(REFRESH_INTERVAL); /* Retrieve BLE connection handle */ connectionHandle = *(CYBLE_CONN_HANDLE_T *) eventParam; break; default: /* Error handling */ break; Code 4. Health Thermometer Service Event Handler void HtssEventHandler(uint32 event, void* eventParam) CYBLE_HTS_CHAR_VALUE_T *interval; switch(event) /* This event is received when indication are enabled by the central */ case CYBLE_EVT_HTSS_INDICATION_ENABLED: /* Set the htssIndication flag */ htssIndication = true; break; /* This event is received when indication are disabled by the central */ case CYBLE_EVT_HTSS_INDICATION_DISABLED: /* Reset the htssIndiciation flag */ htssIndication = false; break; /* This event is received when measurement interval is updated by * the central */ case CYBLE_EVT_HTSS_CHAR_WRITE: /* Retrive interval value */ interval = ((CYBLE_HTS_CHAR_VALUE_T *)eventParam); htssInterval = interval->value->val[1]; /* Update htssInterval with the updated value */ htssInterval = (htssInterval << 8) | interval->value->val[0]; break; default: /* Error handling */ break;

PSoC® 4 BLE – Designing BLE Applications www.cypress.com Document No. 001-91184 Rev. *B 25 System Normal Operation In the system normal operation state, the firmware periodically calls CyBle_ProcessEvents() to process BLE stack-related operations and checks if the connection is established. Note: Any BLE stack -related operati on such as receiving or sending data from or to the link layer and event generation to the application layer are performed as a part of the CyBle_ProcessEvents() function call. In this application, Code 1 initializes the stack , but the event s related to the stack are generated only when the CyBle_ProcessEvents() function is called. Similarly, other events related to device connection, disconnection, advertising timeout, and the Health Thermometer Service are generated only when CyBle_ProcessEvents()is called. If the co nnection is established , the firmware measures the temperature at regular intervals (configured by the Measurement Interval Characteristic of the Health Thermometer Service). After measuring the temperature, if Indications are enabled by the Central device, the firmware sends the temperature data to the BLE Central device as indications. In a BLE application, the device transmits or receives data only at periodic intervals , also known as advertising intervals or connec tion intervals, depending on the BLE connection state. Thus, when the system normal operation task is complete, to conserve power, the device enters the system low-power operation mode and wakes up at the next connection/advertisement interval.

4.2.3 System Low -Power Operation

In the system low-power operation state, the device operates in one of the three possible power modes:  Sleep This mode is entered when the CPU is free but the BLE subsystem (BLESS) is active and busy in data transmission or reception. In this scenario, the CPU is put into the Sleep mode while the remaining core, such as clocks and regulator, is kept active for normal BLE operation. To conserve power, the internal main oscillator (IMO) frequency is reduced to 3 MHz; on wakeup, it is switched back to 12 MHz.  Deep-Sleep The firmware continuously tries to put the BLESS into the Deep-Sleep mode. After the BLESS is successfully put into the Deep-Sleep mode, the remaining system also transitions to the Deep-Sleep mode. Note: Transitioning the device into the Deep-Sleep mode should happen immediately after the BLESS is put into the Deep-Sleep mode. If this cannot be guaranteed, the firmware should disable interrupt s (to avoid servicing an ISR) and recheck if the BLESS is still in the Deep-Sleep mode or the ECO_ON mode. If the BLESS is in either of these two modes, then the device can safely enter the Deep-Sleep mode; if not, the device must wait until the Rx/Tx event is complete.  Hibernate When the device is disconnected or the advertising interval times out, it enters the ultra-low-power mode called “Hibernate”. After waking up from this mode, the firmware starts to execute from the beginning of main.c, although the RAM contents are retained.

4.2.4 Sensor Simulation

If you do not have a thermistor and a reference resistor to measure the temperature, you may use the temperature simulation mode to test the application. In this mode, the temperature data is simulated and incremented by 1 0C per measurement interval (default value is 1 second). This can be done in the application code by changing the value of the constant MEASURE_TEMPERATURE_SENSOR from 1 to 0 in the Temperature.h file, as shown in Code 5. Code 5. Simulate Temperature Sensor #define MEASURE_TEMPERATURE_SENSOR (0u)

4.3 Hardware Configuration

integrated USB programmer, a program debug header, and USB-UART/I2C bridges.

  1. Place the CY8CKIT-142 PSoC 4 BLE Module (red module) on the BLE Pioneer Baseboard.

Figure 26. External Thermistor Connection Simulation section for details.

4.4 Build and Program the Device

  1. Select Build > Build AN91184 to build and compile the firmware, as shown in Figure 27. The project should

build without warnings or errors. Figure 27. Build Project

  1. Plug the PSoC 4 BLE module (red module) to the BLE Pioneer baseboard, and then connect the kit to your PC

using the USB Standard-A to Mini-B cable (see Figure 28). Allow the USB enumeration to complete on the PC. Figure 28. Connect BLE Pioneer Baseboard to PCB Using a USB Cable

  1. Select Debug > Program, as shown in Figure 29. If there is only one kit connected to the PC , the programming

Figure 29. Programming the Device Figure 30. Programming Status

5 Application Testing

5.1 CySmart Central Emulation Tool

and verify the operation of a BLE Peripheral device. Download the latest CySmart Central Emulation Tool from www.cypress.com/cysmart.

  1. Connect the BLE Dongle to the PC and start the CySmart Central Emulation Tool from Start > All Programs >

The CySmart Central Emulation Tool detects the BLE Dongle connected to the USB drive.

5.2 CySmart Mobile App

Cypress provides a mobile app to validate BLE applications. This app supports various standard and custom profiles. It also provides a user interface to be able to view the GATT database.  Apple App Store: Click here.  Google Play Store: Click here.

  1. Open the CySmart app on your device, as shown in Figure 39.

Figure 39. BLE Configuration

  1. If Bl uetooth is enabled , the mobile device scans for BLE devices and lists the m on the screen ; otherwise, it

Figure 40. Device List

  1. Connect to the device “MyThermometer” by clicking on the device name, as shown in Figure 40.
  1. Select the “Device Information” Service. It shows the device information configured as a part of the project, as

Figure 43. Device Information Service

5.3 Summary

Emulation Tool and CySmart mobile app provided by Cypress.

6 Related Application Notes

PSoC® 4 BLE – Designing BLE Applications www.cypress.com Document No. 001-91184 Rev. *B 35 Document History Document Title: AN91184 – PSoC® 4 BLE – Designing BLE Applications Document Number: 001-91184 Revision ECN Orig. of Change Submission Date Description of Change ** 4635526 PMAD 03/25/2015 New Application Note. *A 4767014 UDYG 05/15/2015 Updated to PSoC Creator 3.2 and BLE component v2.0. *B 4784134 UDYG 06/02/2015 Updated images for CySmart PC Tool and CySmart mobile app. Updated template

PSoC® 4 BLE – Designing BLE Applications www.cypress.com Document No. 001-91184 Rev. *B 36 Worldwide Sales and Design Support Cypress maintains a worldwide network of offices, solution centers, manufacturer’s representat ives, and distributors. To find the office closest to you, visit us at Cypress Locations. Products Automotive cypress.com/go/automotive Clocks & Buffers cypress.com/go/clocks Interface cypress.com/go/interface Lighting & Power Control cypress.com/go/powerpsoc Memory cypress.com/go/memory PSoC cypress.com/go/psoc Touch Sensing cypress.com/go/touch USB Controllers cypress.com/go/usb Wireless/RF cypress.com/go/wireless PSoC® Solutions psoc.cypress.com/solutions PSoC 1 | PSoC 3 | PSoC 4 | PSoC 5LP Cypress Developer Community Community | Forums | Blogs | Video | Training Technical Support cypress.com/go/support PSoC is a registered trademark and PSoC Creator is a trademark of Cypress Semiconductor Corp. All other trademarks or registered trademarks referenced herein are the property of their respective owners. Cypress Semiconductor

198 Champion Court

San Jose, CA 95134-1709 Phone : 408-943-2600 Fax : 408-943-4730 Website : www.cypress.com © Cypress Semiconductor Corporation, 201 5. The information contained herein is subject to change without notice. Cypress Semiconductor Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, l ife saving, critical control or safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize it s products for use as critical components in life -support systems where a malfunction or failure may reasonabl y be expected to result in significant injury to the user. The inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and subject to wo rldwide patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress h ereby grants to licensee a personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative works for the sole purpose of creating custom software and or firmware in supp ort of licensee product to be used only in conjunction with a Cypress integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or rep resentation of this Source Code except as specified above is prohibited without the express written permission of Cypress. Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the right to make changes without further notice to the materials described herein. Cypress does not a ssume any liability arising out of the application or use of any product or circuit described herein. Cypress does not authorize its products for use as critical components in lif e-support systems where a malfunction or failure may reasonably be expected t o result in significant injury to the user. The inclusion of Cypress’ product in a life -support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. Use may be limited by and subject to the applicable Cypress software license agreement.