2 of 2 people found this helpful
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.
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 ?
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)
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.