This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

re-connecting to last paired BT MAC



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.

  • 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,

     

  • 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?

  • 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.
  • 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 */

  • 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,

  • Hi,srisenthilkumar chandrasekaran

    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


  • 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,