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.

CC2640R2F-Q1: Function called on Bluetooth connection successful

Part Number: CC2640R2F-Q1

When a Bluetooth connection is made, what function is called? I need to drive a GPIO high whenever a BLE connection has been established. 

Similarly, when bluetooth is disconnected, I want to drive the GPIO low. 

Inside which (callback) function should I include the code for this?

Thanks in advance,

Tushar

  • Hi Tushar,

    If you are using the simple_central project, the GAP_LINK_ESTABLISHED_EVENT event is generated and is caught within the SimpleCentral_processRoleEvent() function whenever a connection is established. You are free to call whatever function you like within that case. For disconnections, the GAP_LINK_TERMINATED_EVENT event is caught in the same function.

    Best Regards,

    Jan

  • Hi Jan

    Thanks for the response. 

    I am using the simple_peripheral project by the way and as I found out by debugging, the two events GAP_LINK_ESTABLISHED_EVENT and GAP_LINK_TERMINATED_EVENT apply to the peripheral as well

    I have another problem now. When I include the statement GPIO_write inside either of these two cases, it does not get highlighted in purple as it normally would if the right header files are included. I created a test function to check this and below is a snapshot.

    I found out that there is one Typedef which is causing this issue but it beats me why. 

    The typedef that's causing this issue is found in simple_peripheral.c and is called spClockEventData_t.

    typedef struct
    {
      uint8_t event;                //
      uint8_t data[];
    } spClockEventData_t;

    When I comment out this piece, the GPIO_write is getting recognized.

    Can you please guide me on what could be going wrong here?

    Thanks.

  • Hi Tushar,

    I am glad you were able to make use of the events provided. With regards to the GPIO_write(1,0) highlighting, this may be a syntax highlighting bug. Ensure that the following include statement at the start of the file:

    #include <ti/drivers/GPIO.h>

    I would also refer to the gpiointerrupt example project which offers as a good example project which showcases how to use the gpio functionality. You may also find the pin examples useful. I would try building and flashing the project to see if it works (even if the syntax highlighting is not updating).

    Best Regards,

    Jan

  • Hi Jan

    The code compiles fine and flashes as well. The part is advertising also but when I tap to connect to it on my phone screen, it says "Connecting" and then times out. I think the GPIO statements have something to do with this because without them, the connection was happening fine. 

    I placed a breakpoint in GAP_LINK_ESTABLISHED_EVENT right after the GPIO_write. Then I entered debug mode. When I tapped on connect on my phone, the control entered GAP_LINK_ESTABLISHED_EVENT and then crashed with the following messages:

    Cortex_M3_0: Error: (Error -1170 @ 0x0) Unable to access the DAP. Reset the device, and retry the operation. If error persists, confirm configuration, power-cycle the board, and/or try more reliable JTAG settings (e.g. lower TCLK). (Emulation package 9.2.0.00002)
    Cortex_M3_0: Trouble Halting Target CPU: (Error -2064 @ 0x0) Unable to read device status. Reset the device, and retry the operation. If error persists, confirm configuration, power-cycle the board, and/or try more reliable JTAG settings (e.g. lower TCLK). (Emulation package 9.2.0.00002)

    Cortex_M3_0: Unable to determine target status after 20 attempts
    Cortex_M3_0: Failed to remove the debug state from the target before disconnecting. There may still be breakpoint op-codes embedded in program memory. It is recommended that you reset the emulator before you connect and reload your program before you continue debugging

    I also placed the breakpoint on the GPIO_write statement and tried to step over (F6), and received the message below.

    Cortex_M3_0: Can't Run Target CPU: (Error -2134 @ 0x0) Unable to control device execution state. Reset the device, and retry the operation. If error persists, confirm configuration, power-cycle the board, and/or try more reliable JTAG settings (e.g. lower TCLK). (Emulation package 9.2.0.00002)
    Cortex_M3_0: Error: (Error -1170 @ 0x0) Unable to access the DAP. Reset the device, and retry the operation. If error persists, confirm configuration, power-cycle the board, and/or try more reliable JTAG settings (e.g. lower TCLK). (Emulation package 9.2.0.00002)
    Cortex_M3_0: Unable to determine target status after 20 attempts
    Cortex_M3_0: Failed to remove the debug state from the target before disconnecting. There may still be breakpoint op-codes embedded in program memory. It is recommended that you reset the emulator before you connect and reload your program before you continue debugging

    Please help.

  • Hi Tushar,

    I believe you are correct. This seems to be an issue related to the GPIO. Are you running this program on a LaunchPad or on custom hardware? Can you try referencing the GPIOinterrupt example and ensuring that your project contains all of the necessary GPIO set up (besides including the library as mentioned previously).

    Best Regards,

    Jan

  • Jan,

    I am running it on my custom hardware. I know the GPIO set up is correct because the same GPIO writes are working in my main function outside of the simple_peripheral.c. 

    Regards,

    Tushar

  • Hi Tushar,

    Can you verify if you are able to see this issue on a LaunchPad? This will help us isolate the problem. If you do not have a LaunchPad, then you may upload the code here, and I can test it on a LaunchPad for you.

    Best Regards,

    Jan