"Turn" ble_cc2540_ Beginner Guide

Source: Internet
Author: User

Original URL: http://www.deyisupport.com/question_answer/wireless_connectivity/bluetooth/f/103/t/61462.aspx

Looked at the question, found not very will answer, long time did not make, all forgot, had to post some things before, help beginners into the door bar:

First, the initial knowledge of ble

Through these two days to "CC2540 BLE software Developer guider v1.2.pdf" study on the CC2540 and Bluetooth 4.0 has a general understanding: 1, Bluetooth 4.0 protocol: BR/EDR (standard Bluetooth) + BLE current CC254 The 0 hardware only supports the single-mode wireless standard of BLE, and cannot communicate with versions older than 4.0. 2, for CC2540 Ble-stack focus on learning the structure of the protocol stack, TI's Bluetooth platform supports two protocol stacks/application configuration: Single device configuration, network processor configuration (Application/profile application on another processor or PC). 3, focus on the top level of the protocol stack two general Profile:gap (Universal access Specification), GATT (General attribute specification). 4, Gap is mainly responsible for processing equipment access and access to the process: equipment discovery, link establishment, link termination, start security functions, equipment configuration (mainly the configuration of the connection parameters). 5, GATT mainly completes the communication between the server and client related sub-process. 6, BLE support 40 channels of the frequency hopping mechanism, of which 3 channels for advertise, the remainder for data communication, and BR channel number in 80, compared to the mechanism of ble more power-saving. The frequency hopping offsets of both are 2MHz and 1MHz respectively. 7, the OS Abstraction layer related process learning, how to configure a new task, task priority, event triggering, message delivery and so on. 8, the existence of the problem: do not know the BLE agreement within the gap, GATT profile and application profile contact and difference, whether BLE can be added to the app: A2DP (Bluetooth stereo Audio transmission protocol), HID (Human Machine Interface specification) and other such specifications. second, start understanding Stack  Further learning Gap, mainly played four roles: broadcaster (broadcaster), OBSEERVER (Observer), peripheral (peripheral), Central (center). 1, Ble-stack has each role of the sample program, and is different from the sample program corresponding to the LIB is not the same, Eg:CC2540_ble_single_chip_peri.lib, Cc2540_ble_network_ Processor_all.lib and so on. 2, for the application profile needs to be written according to the specification, TI provides several medical profiles, for file transfer, audio transmission, and so on, I understand that BLE is not suitable for these occasions (refer to the wiki online some topic discussion, Ble_  Techday_2011.pdf, ble_cc2540_deepdive_training_2011.pdf from the wiki network). I understand that classic is the traditional kind of Bluetooth application, BLE application is mainly used for the first picture. BLE currently supports a packet with a maximum byte count of 20Byte, which is basically a few bytes of application, TI routines. 3, in the wiki to find a relevant example: Serial APP through the serial port to achieve data transmission between two PCs, to start with this example, in the switch to the USB, a preliminary look at this Serial App, on this page can download an HCI Tester script test tool, Not directly through the two serial port to achieve data transmission, the need for the upper profile and HCI Command. Attached address: http://processors.wiki.ti.com/index.php/LPRF_BLE_SerialApp 4, Btool tool by connecting the USB dongle to see the software options, try to connect two USB dongle , on the wiki to see someone said to be able to establish a connection, measured cannot search the device. 5, the initial plan to transplant Keyfob program to dongle, to achieve a connection between the two devices, keyfob through a button trigger 30s dicoverable state, this time to start dongle scan a series of operations. third, Stones1, the transplant keyfob routine to the USB dongle above, modifies the key and so on macro, removed the acceleration, the buzzer procedure, the sample and the Hosttestapp can establish the link and the correspondence, the reference wiki address is as follows:/HTTP Processors.wiki.ti.com/index.php/category:keyfobdemo existing problems: 1) Keyfob routines use the key to start a 30-second advertising, followed by the Btool via USB Dongle the command to send a request link to keyfob (another dongle simulation).      The key uses the polling method to enter the corresponding event normally, unable to enter the way of using the IO interrupt, and inspected many times not found the reason. 2) before establishing the link, the USB dongle requires a scan device, which is caused by the inability to find the device after Keyfob sends the advertising, guessing because of the way the polling button was used. 2, the CC2540 receive sends the cache to be 128Byte: again to see before the wiki to see the send byte not more than 20Byte of the argument, is limited to within 10MS. 3, Btool establish the status of the connection: [25] indicates that Gap_establishlink Success, in the Read/write option through the operation of keywords, descriptors to achieve the interaction of data in the communication, referring to the 1 Web site. Eg: read keyfob battery power through USB dongle, actual read error, invalid data (I want to buy a keyfob speed up development) 4, want to achieve communication between the two PCs: 1) If you use Hosttestapp way, The host computer needs to be similar to Btool, generating HCI command to read and write the data also need the relevant command and operation sequence. 2) using a single chip method (different from the network processor mode, Hosttestapp mode), not directly with the external PC or MCU interaction. Finally how to choose, but also take time to further learn ble-stack. Four, stand a little higher  1. Basically figuring out what parts of an application are composed, what initialization to do, where the app functions, and how to respond to various events. 2, about the CC2540 RF register problem: 1) User Guide does not detail the register of each bit, only a simple register description, check e2e determined ti is not open, so unable to write the RF part of the driver. 2) TI recommends the way: note, that osal and HAL source are avail, a free sniffer is avail, and RF studio can access RF directly.  3) Open the RF Studio CC2540 interface and take a good look at what parts are available for testing and so on. In principle, it is possible to send and receive data packet tests. 3, consult the relevant TI Bluetooth device, a simple comparison is as follows: Five, started up  Through the study on Ti_ble_vendor_specific_hci_guide.pdf and e2e on the relevant discussion, summarized as follows;  1, can be related to CC2540 by HIC command, general description.   2, about cc2540 production Test mode reference URL:  http://processors.wiki.ti.com/index.php/ptm 3, Create a CC2540 test project file, mainly to remove the Protocol section and some unrelated osal initialization programs.  uint16 userapp_processevent ( uint8 task_id, uint16 events ) {     if  ( events & USER_START_DEVICE_EVT )     {         HCI_EXT_SetTxPowerCmd  (HCI_EXT_TX_POWER_4_DBM);         HCI_EXT_ModemTestTxCmd  (hci_ext_tx_modulated_carrier,37);                 //hci_ext_ modemhoptesttxcmd  ();        //hci_ext_modemtestrxcmd  (37)  ;        //HCI_EXT_EndModemTestCmd  ();                return  ( events ^  USER_START_DEVICE_EVT );     }    return 0;}   Main involved function: hci_ext_settxpowercmd              Set transmit power hci_ext_modemtesttxcmd          start a continuous send test, need to specify the channel and whether modulation   HCI_EXT_ModemHopTestTxCmd     starts a continuous send test, sends a 37BYTE packet (pseudo-random number), and the channel increments from 0-39 Hci_ext_ modemtestrxcmd          start receiving the test, you need to specify the channel hci_ext_endmodemtestcmd         Stop Modem Testing    Six, simple analysis   1, take the central, peripheral communication as an example, learning the data communication between the Ble-stack devices:1) peripheral data transmission via gatt_notification function, in which case the peripheral device plays Seriver (note 1). 2) Central The Gatt_msg_event event triggers any read gattmsgevent_t structure of MSG corresponding to the indication and Notification messages (reference program in the relevant structure) to achieve data reception, In this case the central device plays the client (note 2). Note 1:  static attHandleValueNoti_t *pReport= NULL;   if  ( gatt_ Notification ( 0, pRepor, FALSE ) ==success)   {    // The user can be sent here after the successful delivery of the relevant operation, Prepor for the notification   to be sent}   /**   * Handle  value notification format.   */  typedef struct  {    uint16  handle;                             //!< handle of the  attribute that has been changed  (Must be first field)     uint8 len;                                    //!< length of value    uint8 value[att_mtu_size-3];      //!< New  value of the attribute } atthandlevaluenoti_t;    NOTE 2:   if  ( pmsg->method == att_handle_value_noti | | pmsg->method == att_handle_value_ind )   {          attHandleValueNoti_t noti;          Datacount = datacount+ 1;           lcd_ Write_string_value (  "data cnt: ", datacount, 10, hal_lcd_line_1 );           noti.handle = pMsg-> Msg.handlevaluenoti.handle;      noti.len = pmsg-> msg.handlevaluenoti.len;          osal_memcpy (& Noti.value, &pmsg->msg.handlevaluenoti.value,noti.len);         //user can operate &noti here, via serial port or USB send out and so on &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp; }   2, the establishment of some of the details of the connection function is not clear, the sending of data can be seen by the user of the lowest function as described in 13. Further planning:1) through the central and peripheral communication as the basic template to achieve a connection between the device, and then use the 1 way to achieve data exchange. 2) on the basis of 1) to join the serial communication to achieve the communication between the serial port, and can be connected through the serial control device to establish the process of connection. 3) using dongle to implement USB function, mainly Hosttestapp in the CDC class USB program extracted, to achieve dongle and PC data communication, does not involve Ble-stack protocol stack related just a USB program. 4) because the CDC class of USB relatively simple, the host computer programming can use the serial port, in 3) on the basis of the implementation of HID, specifically about this part of the USB drive and the host computer is not very clear thinking. 4, need to do things:1) Use the purchased CC2540 verification link to establish the function of data interaction. 2) realize the function of CC2540 UART and PC communication. 3) Use dongle to realize the function of CDC class USB and PC communication. 4) Use dongle to realize the function of HID class USB and PC communication. Attachment: The description of Gatt_notification, gatt_indication function, not be able to run independently need to establish a connection on the basis. Seven, a change of hardware to see 1, using the purchase of CC2540 module experiment, modified the debug interface, can use TI's ccdebug download CD-ROM program test normal. The disc routines are modified using Ble-stack 1.1, respectively, to download Kebfob and hostapptest. 2, download Ble-stack 1.21 in the routine kebfob and hostapptest test connection process is also normal. Figure 1: Test UUID read keyword success, keyfob power (percent) Figure 2: Test Adv.commands read Rssi value 3, using the virtual keyboard in the Ble-stack 1.1 routine, test the connection failure (both the disc and the protocol stack original routines have been tested), the device address searched with the Hostapptest Test matches the address to be bound. What to do: 1) figure out the problems that occur during the 3 connection process. 2) Take the time to familiarize yourself with API functions and related structures. Eight, began to do the hardware 1, reference "Cc2540em_discrete_schematic.pdf" drawing CC2540 Wireless module schematic diagram. 1) P0 (8pin), P1 (8pin), P2 (3pin), Power (2pin), USB (2pin), RESET (1pin) Total 24pin. 2) do not know whether the pin arrangement is reasonable, the current arrangement is conducive to module wiring. See annex: Cc2540_ble_rf.pdf 2, the reference "Cc2540_minidk_schematic.pdf" and the purchase kit floor schematic diagram Drawing CC2540 floor schematic. 1) Add a low-power accelerometer CMA3000 (for step, etc., can not be welded by default). 2) Add CP2102 for USB to serial port, print characters through UART for easy debugging, etc. 3) optional USB power supply, Ccdebug power supply, CR2032 button battery. 4) 0R resistors are used in the design, which is easy to modify two times. See annex: CC2540 Board.pdf 3, read the information of BLE, feel not suitable to add a traditional sensor on the backplane, do not know whether the need to add sensors? See attachment: TI BLE @ ces.pdf     Nine, Idle stage, casual play   1, the schematic modification, inspection:1) Add the PCB antenna and the external antenna. 2) Add OLED display, Power LED, add dial switch. 2, OLED selected a built-in boost circuit model with the previous pixel consistent:1) Select the built-in boost OLED eliminates the design of the boost circuit. 2) The actual research section selected TPS61040 as a boost chip to meet the demand (considering the inductor, freewheeling diode and other materials are not good procurement problems). 3, determine the base material in the ERP model, the main devices are now determined, including connectors. 4, Debug CC2540 UART, debug OK can print information:1) It is found that errors occur during the advertising process (testing for multiple delivery situations, and verifying that the RF is caused by advertising). 2) Using DMA, ISR is the same situation.       10, start playing with her.   1, CC2540 Communication establishment process debugging:1) to find the UART in the advertising process to send data garbled problem, so that the low power consumption (pwrmgr_battery) will accompany the main clock switching, causing the baud rate instability, turn off the low-power data normal, to progress a study, temporarily do not do in-depth study. 2) on the basis of the transfer of the serial port to achieve the basic communication setup process debugging, mainly through the peripheral, central example, the realization of the PC through the serial port to the peripheral device to send data through the wireless by the central device received and then transmitted through the serial port to another PC.  Peripheral (Send): From 05 to 1 (Receive): 0D 00 01 (in)------- (1) 05 00 01 00 07 07 00 22 22 22 22 22 Above reference: Annex I, annex Ii. 2, Blood pressure routine test:1) The BP collector is not available in the new version of ble-stack1.21, and there is only one BP Sensor, so it takes some time to build the collector project. 2) found on the TI wiki on the ble-stack1.1 about the BP demo, need a Blehealthdemo (C # Development) host computer, collector is working in network process mode. Test results reference: annex III. 3. Summary of questions raised by the meeting:1) Why should there be proflie? The A:profile is released by the Bluetooth SIG and describes the differences and uniformity of the Bluetooth protocol stack used by different devices. For example, a sphygmomanometer, which is defined by the BP profile and BP service, allows a BP collector to collect BP sensor-measured blood pressure from different manufacturers. If there is no profile has a protocol then everyone can only behind closed doors, I produced mobile phone with Bluetooth function, then you use the Bluetooth headset must be my production, because those data format, device description and so only I know, So there is audio profile (A2DP) After everyone according to this specification to strictly define their own equipment can be. 2) Profile comparison of the BT popular version: I understand that in BT2.0, BT2.1, BT3.0 These versions can use traditional profiles, and 4.0 will have a portion of the Gatt-basic specification profile. What we need to understand here is:BT2.0 = Core Version2.0 +edrbt2.1 = core Version2.1 +edrbt3.0 = core Version3.0 +hsbt4.0 = core Version4.0 +ble = Br/edr + BLE (unlike in the past, V4.0 has two cores, CC2540 only ble) for Sphygmomanometer:The V4.0 version uses the BP profile (Blood pressure profile) + BP ServiceV4.0 prior version using HD profile (Human Device profiles) HD Profile (health specification) including BP P Rofile (blood pressure specification) + HT profile (temperature specification) + ... These specifications can be viewed from the official website: https://www.bluetooth.org/Technical/Specifications/adopted.htm above reference: Annex IV, annex Five. 3. Accessories:Annex IV Annex II Annex III Annex V     11, blood pressure monitor analysis     1. Blood pressure sample program consumes resources (256K Flash + 8K RAM): 2, Blood pressure profile of the data format specified: 3, profile defines the data format, process, service UUID, etc.:   these will be reflected in the Protocol attribute table, and this property sheet will pass him as a parameter to the protocol stack through the relevant API.  static gattAttribute_t bloodPressureAttrTbl[] = {    //  bloodpressure service    {         {  ATT_BT_UUID_SIZE, primaryServiceUUID }, /* type */         GATT_PERMIT_READ,                                  /* permissions */        0,                                                             /* handle */         (uint8 *) &bloodPressureService                    /* pValue */    },         // 1. Characteristic Declaration    {          { ATT_BT_UUID_SIZE, characterUUID },         GATT_PERMIT_READ,        0,         &bloodPressureTempProps     },         // 2. Characteristic Value    {          { ATT_BT_UUID_SIZE, bloodPressureTempUUID },         0, //return read_not_permitted        0,          &bloodPressureTemp     },         // 3.characteristic configuration    {          { att_bt_uuid_size, clientcharcfguuid },         GATT_PERMIT_READ | GATT_PERMIT_WRITE,          0,          (uint8  *) &bloodPressureMeasConfig    },    // 4.Presentation  Format    {         { att_bt_uuid_size,  charFormatUUID },        GATT_PERMIT_READ,          0,          (uint8 *) & bloodpressuretempformat    },             //////////////////////////////////////////////    // IMMEDIATE  measurement    //////////////////////////////////////////////         // 5.Characteristic Declaration    {          { ATT_BT_UUID_SIZE, characterUUID },         GATT_PERMIT_READ,         0,         &bloodPressureImeasProps     },         // 6.Characteristic Value    {          {&nBsp att_bt_uuid_size, bloodpressureimeasuuid },        0, / /return read_not_permitted        0,          &bloodPressureImeas     },         // 7.Characteristic Configuration    {          { ATT_BT_UUID_SIZE, clientCharCfgUUID },         GATT_PERMIT_READ | GATT_PERMIT_WRITE,          0,          (uint8 *) & bloodpressureimeasconfig    },             //////////////////////////////////////////////    // FEATURE     ////////////////        // 8.Characteristic  Declaration    {         { att_bt_uuid_ size, characteruuid },        gatt_permit_read,          0,        & Bpfeatureprops     },        // 9. characteristic value    {         {  att_bt_uuid_size, bpfeatureuuid },        gatt_permit_ read,        0,          ( uint8 *) &bpFeature     },      };
  Well, the first chapter to share to the end of this, just simple to help beginners get started, right when playing, professional developers please ignore. Do not rule out your own understanding and layout caused by the problem, please judge, thank you.   follow-up will upload the code and related documents, and continue to open to say the second chapter     ha, Hope ti can give a package hard drive what, encourage a bit.

"Turn" ble_cc2540_ Beginner Guide

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.