2 Replies Latest reply on May 23, 2016 10:38 AM by pavlo.kostrytsia

    How to start advertisement?

    pavlo.kostrytsia

      I want to send single advertisement packet on particular event (data from serial interface) without entering Deep Sleep mode, In Project #009: Dynamic Broadcaster I use CyBle_GappStopAdvertisement() to stop advertisement (see code below). However, when I call CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST) it seems to be ignored. Why CyBle_GappStartAdvertisement(uint8 advertisingIntervalType) doesn't work?

         

      int main()
      {

          InitializeSystem();

         

          UART_1_Start();

         

          for(;;)
          {
              CyBle_ProcessEvents();

         

              rxData = UART_1_UartGetChar();
              if (rxData)
              {
                  CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);   
              }
              else
                  CyBle_GappStopAdvertisement();

         

      #if ENABLE_DYNAMIC_ADV       
              DynamicADVPayloadUpdate(rxData);
      #endif

         

          }
      }

        • 1. Re: How to start advertisement?
          George.Riggall_1541811

          It could be that your serial terminal is sending some extra bits (CR, etc) which might be screwing things up.. When I've used a similar method I tend to put UART_SpiUartClearRxBuffer() after UART_UartGetChar() just to clean up the received data.

             

          It may also be useful to put if( UART_SpiUartGetRxBufferSize()) in front.

             

          You might write instead:

             

                  
                  if (UART_1_SpiUartGetRxBufferSize())
                  {
                      CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);  
                      UART_1_SpiUartClearRxBuffer();
                  }
                  else
                      CyBle_GappStopAdvertisement();

             

          I would also check to see if the state is advertising (with CyBle_GetState() ) before sending stop advertising command because the stack might just keep throwing HCI status errors back at you.

             

          There's probably a bteer solution but I hope this helps.

          • 2. Re: How to start advertisement?
            pavlo.kostrytsia

            Thanks George_PR,

               

            Issue was not related to UART itself, but to the approach I used. I was reading data from UART constantly in the loop, while BLE sub-system allows to send advertisement with minimum interval of 100 ms. So it was just unable to send any packet before I send stop signal.

               

            Anyway your answer gave me some clue and feeling that I am not alone with my problem :)