How to start and stop advertising

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi ,

I'm trying to achieve the following :

listen on UART for data , if data is received then start advertising the received data for a minute and then stop advertising.

What I currently have working :

The BLE is already advertising a BLE packet , once data is received , the BLE advertisement packet is updated and then turned off after a minute. However , after the advertisement is turned off , the UART is not working anymore and I can detect any data coming in .

Also when I tired to remove

        CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);

form the

    case CYBLE_EVT_STACK_ON:    /*BLE stack ON*/

nothing works , I cant even detect anything on the UART.

The BLE module configuration is set to be a broadcaster .

So I'm pretty sure that I'm not fully understating when and how to start and stop advertising without breaking the code .

I have had a look at similar questions and projects but couldn't find an answer that resolves my issue so I would really appreciate your help

0 Likes
1 Solution
Anonymous
Not applicable

You would need to pass in the advertisement timeout value you want to use when you start advertising. (To change it you would need to stop, then restart advertisement with the new timeout)

The function:

CYBLE_API_RESULT_T CyBle_GappEnterDiscoveryMode (CYBLE_GAPP_DISC_MODE_INFO_T * advInfo)

will start advertisement, and the variable advTo in the parameter structure will have the timeout in seconds I believe.

If you want more accurate timing, then you would probably want to use a separate timer yourself to call advertisement stop when you reach the "timeout" that you want.

If you are using a simple PWM timer, the function is TIMER_WritePeriod(timeout); You should probably stop the timer before changing the period however.

View solution in original post

0 Likes
3 Replies
Anonymous
Not applicable

You are trying to use CyDelay(60000) to delay for one minute, but this will delay execution of the CPU for 1 minute, not the BLE; This will cause deadlocking/failed interrupts during the 60s. Most likely why you can only get data the first time, and the UART fails after this point.

Instead of using the CyDelay(60,000) to time the device, set the unit to time out the advertisement after 60 seconds using the configuration in the component in topdesign.cysch (Double-click component and go to GAP->advertisement or something similar)

case CYBLE_EVT_TIMEOUT will occur when the advertisement times out, otherwise if you are wanting the timer to reset upon receiving UART data, then you will want to create/use and peripheral timer that can run while in deep-sleep (WDT is a good choice imo), and will wake up the unit to turn off advertising or be reset to 60s when UART data is received. Call the advertisement stop function when the timer elapses 60s, and just change the advertisement data without having the cydelay after it.

You can start the advertisement pretty much anywhere/time if it is not already active;

You can stop the advertisement pretty much anywhere/time if it is active;

The requests to change advertising state aren't handled until you call CyBle_ProcessEvents(); where the BLESS handles all pending events and requests (kind of like a message queue handling)

But, the biggest thing would be making the timer asynchronous from the CPU operation and the power mode so that you can handle doing other operations like deepsleep or calculating numbers while the timer is running for more timer accuracy.

Anonymous
Not applicable

Hi Thanks for your response , I got it sorted now.

I just have a question if you dont mind , how do you set the timeout value programmaticly (in code ) ? also can it be done in ms ?

0 Likes
Anonymous
Not applicable

You would need to pass in the advertisement timeout value you want to use when you start advertising. (To change it you would need to stop, then restart advertisement with the new timeout)

The function:

CYBLE_API_RESULT_T CyBle_GappEnterDiscoveryMode (CYBLE_GAPP_DISC_MODE_INFO_T * advInfo)

will start advertisement, and the variable advTo in the parameter structure will have the timeout in seconds I believe.

If you want more accurate timing, then you would probably want to use a separate timer yourself to call advertisement stop when you reach the "timeout" that you want.

If you are using a simple PWM timer, the function is TIMER_WritePeriod(timeout); You should probably stop the timer before changing the period however.

0 Likes