cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

DhDa_2432241
Contributor II

Hello all,

I have my BLE configured as follows:

1.PNG

2.PNG

My code is as follows

/******************************S T A R T ********* M A I N . C ******************************/

void monitorCybleState();

int main(){

   CyBle_Start(StackEventHandler);

   for(;;){

       monitorCybleState();

   }

   return 0;

}

void monitorCybleState()

{

    switch(CyBle_GetState()){

        case CYBLE_STATE_STOPPED:

            break;

        case CYBLE_STATE_INITIALIZING:

            break;

       

        case CYBLE_STATE_CONNECTED:

            break;

       

        case CYBLE_STATE_ADVERTISING:

            break;

       

        case CYBLE_STATE_SCANNING:

            break;

       

        case CYBLE_STATE_CONNECTING:

            break;

       

        case CYBLE_STATE_DISCONNECTED:

            CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);

            CyBle_GapcStartScan(CYBLE_SCANNING_FAST);

            break;

        default:

            break;

    }

}

/******************************E N D ********* M A I N . C ******************************/

/**********************S T A R T *********** E V E N T . C **********************/

void StackEventHandler(uint32 event, void* eventParam){

    switch(event){

           case CYBLE_EVT_STACK_ON:

                  break;

          case CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:

                 printf(".");

                 break;

          case  CYBLE_EVT_GAPC_SCAN_START_STOP:

                  printf("CYBLE_EVT_GAPC_SCAN_START_STOP\r\n");

                  break;

           default:

                 break;

   }

}

/**********************E N D **************** E V E N T . C ***********************/

/**********************OBSERVATIONS******************/

I see that advertisement and scanning are started. I can see my BLE advertising with the payload I configured. Also,the scanning is active as I can see the dots on my console. After a while I don't see any dots which means there are no scan events. This implies that scanning has stopped because there are active BLE devices emitting beacons all the time. I printed the value of CyBle_GetState() and it shows 4.

4 corresponds to CYBLE_STATE_SCANNING.

This implies that Cyble is still in scanning state but it is not scanning anymore. I am not sure why. I added debug messages to see if somehow CyBle_GapcStopScan() is being called. I didn't see my debug messages on console. So no. I am not sure why scan is stopping after a while. It stops at random times. However, advertisement is functioning well.

As of now the only way to fix this is using stack restart which is CyBle_Stop() and Cyble_Start() which starts the advertisement and scan again. Any suggestions on how to fix this without stack restart?

Thanks

Dheeraj

0 Likes
Reply
1 Solution
GyanC_36
Employee

Hello Dheeraj,

    Since, your device is configured as "Central and Peripheral" and you are starting 'Advertising' and 'Scanning' at the same time. If you have set the Advertising type as 'Connectable Undirected Advertising' ( See the attached BLE component Screen shot) then you will get an HCI error. Both 'Connectable Undirected Advertising' and 'Scanning'  is not possible at the same time because PSoC BLE /PRoC BLE device supports only one connection at a time.

What you could do is -

1) Either change the Advertising type as 'Scannable Undirected Advertising' or Non-connectable Advertising'  OR

2) Do the time multiplexing between Central ( Scanning ) role and Peripheral Role( Advertising) role of the device. You can refer the example project from here

          PSoC-4-BLE/100_Projects_in_100_Days/Day012_Central_Peripheral at master · cypresssemiconductorco/PSo...

Regards,

Gyan

  

View solution in original post

17 Replies
GyanC_36
Employee

Hello Dheeraj,

    Since, your device is configured as "Central and Peripheral" and you are starting 'Advertising' and 'Scanning' at the same time. If you have set the Advertising type as 'Connectable Undirected Advertising' ( See the attached BLE component Screen shot) then you will get an HCI error. Both 'Connectable Undirected Advertising' and 'Scanning'  is not possible at the same time because PSoC BLE /PRoC BLE device supports only one connection at a time.

What you could do is -

1) Either change the Advertising type as 'Scannable Undirected Advertising' or Non-connectable Advertising'  OR

2) Do the time multiplexing between Central ( Scanning ) role and Peripheral Role( Advertising) role of the device. You can refer the example project from here

          PSoC-4-BLE/100_Projects_in_100_Days/Day012_Central_Peripheral at master · cypresssemiconductorco/PSo...

Regards,

Gyan

  

View solution in original post

DhDa_2432241
Contributor II

Hello,

Thanks for replying. Yes, I have my advertising type set to connectable undirected advertising. I can't change it. I have enabled scan timeout and that seemed to work. After the scan timeout, the scan restarts again and hence not getting stuck after a while.

Regards

Dheeraj

0 Likes
Reply
Anonymous
Not applicable

Hi, gyan​.

Is it possible for the BLE to continue scanning for broadcasts while being connected to another device? Thanks

0 Likes
Reply
Anonymous
Not applicable

If the BLE acts as a Peripheral and is connected to a device, is it possible to scan for broadcasts while being in a connected state? I do understand that for this to happen, the BLE must be configured as GAP Central and Peripheral.

0 Likes
Reply
Anonymous
Not applicable

You can do "Observer" scanning while connected to another device.

You will indeed have to setup your device as both peripheral and central for usage.

0 Likes
Reply
Anonymous
Not applicable

Hi, e.pratt_1639216​. How do i do that observer scanning? What configurations do I need to do? As far as I can remember, I tried calling the Cyble_GapcStartScan() and Cyble_GappStartAdvertisement() at the same time with BLE configured as Central and Peripheral one time before. However, I remebered it resulted to an HCI error, which i am not sure what it is.

0 Likes
Reply
Anonymous
Not applicable

For the sequencing, you will need to advertise->get connected to->then start scanning for observer-mode. (At least, this is what I would try first, not quite sure if you can scan while advertising while you are NOT connected to a device).

HCI errors are pretty good indicators that something went wrong lol.

gyan​'s example should be very useful for figuring it out.

0 Likes
Reply
Anonymous
Not applicable

So, it needs to be connected to be able to scan; and advertising and scanning cannot be done at the same. Noted! Thanks, e.pratt_1639216​. I'll definitely give the example by gyan​ a look on this.

Anonymous
Not applicable

One more question. Is this "scanning while connected" possible for a CYBLE-022001-00 chip? e.pratt_1639216

0 Likes
Reply
Anonymous
Not applicable

I don't know the answer to that question, but I would think you can do a little bit of scanning while being connected (but you cannot connect while already connected).

You can scan, save the addresses of devices you want to connect to, and then connect to them later after you finish the connection that is currently active if that is what you are trying to do.

If you are just wanting to see broadcast messages, then I think that should work.

Anonymous
Not applicable

I simply want to see broadcast messages while being connected to a device. Thanks, e.pratt_1639216

0 Likes
Reply
DhDa_2432241
Contributor II

I don't think that's possible.

Some comments on your earlier replies:

1. Scanning and advertising doesn't happen at the same time. It's all based on multiplexing as Gyan said.

2. When you connect to an advertisement, the advertisement stops. I think scanning stops too. After you disconnect, you have to start scanning and advertising again.

0 Likes
Reply
Anonymous
Not applicable

DheerajDakecapardogracielle_2279656

1. Scanning and advertising are mutually exclusive for operation. However, once connected to another device, the unit is no longer scanning or advertising, and may perform one of those options once connected (I know for a fact that the advertising while connected is possible based on this thread)

2. Dheeraj is correct that you need to restart advertisements/scans after disconnecting from a device.

Anonymous
Not applicable

So, scanning and advertisement cannot be done at the same time, but BLE can do one when it is connected to a device. I guess we'll just have to see how this will go. Thanks, DheerajDake​ and e.pratt_1639216​.

0 Likes
Reply
GyanC_36
Employee

Hello,

  Please refer the attached project with this response for BLE as Peripheral and Observer role.

-Gyan

user_2457466
New Contributor II

Hi Gyan,

Sorry to ressurrect an old thread. But I want to point out that cypress has performed workshops where multi-role BLE for PSoC 4, was a possibility.

I can only refer to the document i have. Since it is not available online. The workshop was called "Advanced BLE System Design Workshop".

Reference: 002-10983 Rev *A

Lab #3 details multi role BLE where scan, advertisement and active connection is possible at the same time. Though of course multiplexed by the BLE radio HW.

As stated in the document: "Learn how to assign a broadcaster and observer roles while maintaining BLE connection as a central or peripheral".

We face the same issue, where scanning just stops working and we can't start it again.

0 Likes
Reply