• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Low Power RF & Wireless Connectivity » Bluetooth® Applications » re-connecting to last paired BT MAC
Share
Low Power RF & Wireless Connectivity
  • Forums
  • Announcements
  • Files
  • E2E Wiki
Options
  • Subscribe via RSS

re-connecting to last paired BT MAC

re-connecting to last paired BT MAC

This question has suggested answer(s)
ethan juan
Posted by ethan juan
on Oct 16 2011 21:18 PM
Prodigy10 points

Hello, Sir

We are using below solution on a thermal measuring device project.
MSP430 + PAN1315 (CC2560-based)+ Ethermind Bluetooth Stack

The project in on field test stage, the customer asked to implement a feature “re-connecting to last paired BT MAC”.
The requirement ask our device to, after it is powered off and power on again, INITIATE connection to the last paired device.

We are able to achieve below steps
•    Turning Bluetooth on
•    making the device discoverable
•    performing inquiry
•    pairing the devices, record paired BT MAC
•    receive/transmit data over SPP

But we do not find the way to initiate the BT connection from the MSP430/PAN1315.
Would you show us API we can use or any resource, direction we can work on?

We appreciate your help.

Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • srisenthilkumar chandrasekaran
    Posted by srisenthilkumar chandrasekaran
    on Jan 26 2012 22:57 PM
    Suggested Answer
    Intellectual425 points

    Hi Ethan,

    Please find attached the changes required to application files in order to be able to automatically reconnect to the last paired device.

     

    In sm_storage_pl.c,

    /**

    * Copyright (c) 2009-2010. MindTree Ltd. All rights reserved.

    * \file sm_storage_pl.c

    * \brief This file contains the implementation for the storage related API's

    * The example shows an implementation where the information is stored

    * in the RAM and is maintained across BT on/off cycles without

    * recycling the power.

    * An empty region of the RAM is selected based on the map file output

    * Similar implementation could be done for access to flash.

    */

    /* Header File Inclusion */

    #include "sm_storage_pl.h"

    #define SM_STORAGE_START_ADDR 0x1800 /* Initialize to free RAM location */

    static volatile UCHAR *sm_storage_ptr; /* location for storing SM info */

    void sm_ps_open(SDK_SM_PS_OPEN_MODES mode)

    {

    sm_storage_ptr = (unsigned char *)SM_STORAGE_START_ADDR;

    }

     

    void sm_ps_close(void)

    {

    }

     

    void sm_ps_write(UCHAR * p, UINT16 nb)

    {

    UINT16 st_index;

    __disable_interrupt();

    UART_DISABLE_BT_UART_RTS();

    FCTL3 = FWKEY; /* Clear Lock bit */

    FCTL1 = FWKEY + ERASE; /* Set Erase bit */

    asm(" bis.w #0,R3 "); /* Flash contents: 0x03 0xd3 */

    asm(" bis.w #0,R3 "); /* Flash contents: 0x03 0xd3 */

    asm(" bis.w #0,R3 "); /* Flash contents: 0x03 0xd3 */

    FCTL1 = FWKEY + WRT; /* Set WRT bit for write operation */

    /* Copy information to SM storage location */

    for (st_index = 0; st_index < nb; st_index++) {

    *sm_storage_ptr = *p;

    sm_storage_ptr++;

    p++;

    }

    FCTL1 = FWKEY; /* Clear WRT bit */

    FCTL3 = FWKEY + LOCK; /* Set LOCK bit */

    __enable_interrupt();

    }

     

    void sm_ps_read(UCHAR * p, UINT16 nb)

    {

    UINT16 st_index;

    /* Read information from SM storage */

    for (st_index = 0; st_index < nb; st_index++) {

    *(p + st_index) = *(sm_storage_ptr + st_index);

    }

    sm_storage_ptr += nb;

    }

     

    In appl_sdk.c

     

    void appl_bluetooth_on_complete_event_handler(void)

    {

    /* Bluetooth ON Completed */

    sdk_bt_power = SDK_BT_ON;

    sdk_bt_visible = SDK_DISC_OFF;

    appl_bluetooth_on_indication();

    appl_sdk_display_status(STATUS_BLUETOOTH_ON);

    sdk_display((const UCHAR *)"Bluetooth ON Initialization Completed.\n");

    appl_spp_start();

    appl_sm_reconnect(); /* ------> Newly added */

     

    }

     

    /**

    * \fn appl_sm_reconnect

    * \brief Function to re-connect already paired devices.

    * \param void

    * \return void

    */

    void appl_sm_reconnect()

    {

    API_RESULT retval;

    UCHAR *sm_temp_ptr;

    UCHAR dev_bd_addr[6];

    UCHAR v_dev_info;

    sm_temp_ptr =(unsigned char*) 0x1815;

    v_dev_info = *(sm_temp_ptr);

    if(1== v_dev_info){

    sm_temp_ptr++;

    for(int i=0;i<=5;i++){

    dev_bd_addr[i] = *sm_temp_ptr;

    sm_temp_ptr++;

    }

    BT_mem_copy(sdk_status[0].peer_bd_addr,

    dev_bd_addr, BT_BD_ADDR_SIZE);

    retval= BT_hci_create_connection(dev_bd_addr,

    SDK_CONFIG_ACL_PKT_TYPE,

    rem_bt_dev[0].

    page_scan_rep_mode, 0,

    rem_bt_dev[0].

    clock_offset, 0x01);

    /* If already connected */

    if (HCI_STATE_ALREADY_CONNECTED == retval) {

    /* Initiate SDP Query */

    appl_spp_sdp_query(0);

    SDK_SPP_CHANGE_STATE(0, SDK_IN_SDP_QUERY);

    } else if (API_SUCCESS == retval) {

    /* On Success */

    SDK_SPP_CHANGE_STATE(0, SDK_IN_ACL_CONNECTION);

    } else {

    sdk_display((const UCHAR *)

    "SM device does not exist\n");

    }

    }else{

    printf("Device info does not exist..So,Initiate the new connection\n");

    }

    }

    Regards,

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • shali lv
    Posted by shali lv
    on Feb 24 2012 21:09 PM
    Intellectual320 points

    Hi, srisenthilkumar chandrasekaran

    I have read your program above and couldn't understand what use of below three sentences in void sm_ps_write(UCHAR * p, UINT16 nb).

    asm(" bis.w #0,R3 "); /* Flash contents: 0x03 0xd3 */

    asm(" bis.w #0,R3 "); /* Flash contents: 0x03 0xd3 */

    asm(" bis.w #0,R3 "); /* Flash contents: 0x03 0xd3 */

    I have the problem about automatically reconnect to the last paired device. I have tried your program in ez430-rf2560 board,but It seems not work. would you mind tell me where is the key problem?

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • srisenthilkumar chandrasekaran
    Posted by srisenthilkumar chandrasekaran
    on Feb 27 2012 00:05 AM
    Intellectual425 points
    Hi Shali,
     
           The three in-line assembly instructions above are the dummy instructions that will execute just after flash erase completion. These instructions have no impact to the CPU 
           or functionality. They simply execute with no output and represent accesses to flash where the MSB is set to 1 within the instruction op-code. This assures the instructions 
           execute properly even if a flash read error occurs. 
           These lines are suggested by TI with following comments
    "Three op-codes are needed to cover both possible cases of alignment between the op-codes and the 32-bit Flash fetch.Note that operations with R3 as a destination register have no effect (same as an actual NOP). Also, the 'bis.w' instruction was chosen since it does not affect the status register (SR) bits neither" .
     
    Thanks
    Senthil.
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • shali lv
    Posted by shali lv
    on Feb 27 2012 23:18 PM
    Intellectual320 points

    Hi,srisenthilkumar chandrasekaran

            I think below instructions are used to erase flash information segment D (at address 1800h). but there is no information about which segment to be erased. Of course, those instructions are work well, and I tried  *p=0; as dummy instruction instead of  asm(" bis.w #0,R3 "); the result is bad. So far so good asm(" bis.w #0,R3 "); is only magical instruction.

    Thanks

    FCTL3 = FWKEY; /* Clear Lock bit */

    FCTL1 = FWKEY + ERASE; /* Set Erase bit */

    asm(" bis.w #0,R3 "); /* Flash contents: 0x03 0xd3 */

    asm(" bis.w #0,R3 "); /* Flash contents: 0x03 0xd3 */

    asm(" bis.w #0,R3 "); /* Flash contents: 0x03 0xd3 */

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • srisenthilkumar chandrasekaran
    Posted by srisenthilkumar chandrasekaran
    on Feb 28 2012 06:45 AM
    Intellectual425 points

    Hi Shali,

       Yes, you are right. We have received above asm instruction from TI only with the same comments and we are not much interested to analyse what these instruction does internally.

     

    Regards,

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • shali lv
    Posted by shali lv
    on Feb 29 2012 08:05 AM
    Intellectual320 points

    Hi,

    I tested your function "sm_ps_write(UCHAR * p, UINT16 nb)"  today

    void sm_ps_write(UCHAR * p, UINT16 nb)
      {
        UINT16 st_index;
        __disable_interrupt();
        UART_DISABLE_BT_UART_RTS();
        FCTL3 = FWKEY; /* Clear Lock bit */
        FCTL1 = FWKEY + ERASE; /* Set Erase bit */
         asm(" bis.w #0,R3 "); /* Flash contents: 0x03 0xd3 */
        asm(" bis.w #0,R3 "); /* Flash contents: 0x03 0xd3 */
        asm(" bis.w #0,R3 "); /* Flash contents: 0x03 0xd3 */
        FCTL1 = FWKEY + WRT; /* Set WRT bit for write operation */
        /* Copy information to SM storage location */
        for (st_index = 0; st_index < nb; st_index++) {
        *sm_storage_ptr = *p;
        sm_storage_ptr++;
        p++;
        }
        FCTL1 = FWKEY; /* Clear WRT bit */
        FCTL3 = FWKEY + LOCK; /* Set LOCK bit */
        __enable_interrupt();
      }

    and found that the they have no erasing flash memory function. So, if we connect ez430 board to other bluetooth device, the new information about this device could not be write to flash memory correctly because there are old information not be erased. Inorder to erasing before writing, I add instructions

        if (sm_storage_ptr==(unsigned char *)SM_STORAGE_START_ADDR)
          *sm_storage_ptr=0;     //dummy instruct for erase flash

    be


    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • srisenthilkumar chandrasekaran
    Posted by srisenthilkumar chandrasekaran
    on Mar 01 2012 23:05 PM
    Intellectual425 points

    Hi Shali,

          Yes, You are right. Dummy Flash Write must be required to erase the content properly. 

                    FCTL3 = FWKEY;          /* Clear Lock bit */
                    FCTL1 = FWKEY + ERASE;  /* Set Erase bit */
                    *sm_storage_ptr = 0x00;  /* Dummy Flash Write */

    Regards, 

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use