cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 6 MCU

aaartis1
New Contributor II

Hello! I'm developing application which includes changing between broadcasting and observing functions. I'm using CY8CPROTO-063-BLE development board and I have configured push button to trigger interrupt:

void SW2_Handler()
{
flag_ble = ~flag_ble;
printf("button pressed, flag_ble = %i \n", flag_ble);
NVIC_ClearPendingIRQ(Pressed2_IRQ_cfg.intrSrc);
}

Depending on flag_ble value I should switch between broadcasting and observing states. So far I can change from Cy_BLE_GAPC_StartScan() to Cy_BLE_GAPC_StopScan() to Cy_BLE_GAPP_StartAdvertisement() but I cannot change back. Heres my code:

 

void StackEventHandler(uint32 event, void *eventParam)
{
cy_stc_ble_gapc_adv_report_param_t * advReport;
uint8_t scanState = Cy_BLE_GetScanState();
switch (event)
{
/* This event is received when the BLE stack is initialized and turned ON.*/
case CY_BLE_EVT_STACK_ON:
{
printf("CY_BLE_EVT_STACK_ON \r\n");
/* Stack initialized; ready for scan */
Cy_BLE_GAPC_StartScan(CY_BLE_SCANNING_FAST,CY_BLE_OBSERVER_CONFIGURATION_0_INDEX);
break;
}

case CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
advReport = (cy_stc_ble_gapc_adv_report_param_t *)eventParam;
printf("CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:\r\n");

/* PEER Device address type */
printf(" peerBdAddr: %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x \r\n",
advReport->peerBdAddr[5u], advReport->peerBdAddr[4u],
advReport->peerBdAddr[3u], advReport->peerBdAddr[2u],
advReport->peerBdAddr[1u], advReport->peerBdAddr[0u]);

/* RSSI of the received packet from peer Device */
printf(" Rssi: %i \r\n", advReport->rssi);
printf("ADV data: %s\r\n", advReport->data);
if (flag_ble == 255)
{
   Cy_BLE_GAPC_StopScan();
}

}
break;

/* This event is triggered when the central device has started/stopped scanning */
case CY_BLE_EVT_GAPC_SCAN_START_STOP:
{
if (flag_ble == 0){
Cy_BLE_GAPP_StopAdvertisement();
 }
printf("CY_BLE_EVT_GAPC_SCAN_START_STOP, scanstate = ");
switch(scanState)
{
case CY_BLE_SCAN_STATE_STOPPED:
Cy_BLE_GAPP_StartAdvertisement(CY_BLE_ADVERTISING_FAST, CY_BLE_BROADCASTER_CONFIGURATION_0_INDEX);
printf("CY_BLE_SCAN_STATE_STOPPED\r\n");
//CyDelayCycles(150000000*2);
break;

case CY_BLE_SCAN_STATE_SCAN_INITIATED:
printf("CY_BLE_SCAN_STATE_SCAN_INITIATED\r\n");
break;

case CY_BLE_SCAN_STATE_SCANNING:
printf("CY_BLE_SCAN_STATE_SCANNING\r\n");
break;

case CY_BLE_SCAN_STATE_STOP_INITIATED:
printf("CY_BLE_SCAN_STATE_STOP_INITIATED\r\n");
break;
}
break;
}
case CY_BLE_EVT_GAPP_ADVERTISEMENT_START_STOP:
{
for (i = WS_NUM_PIXELS; i>-1; i--){
for (n = 0; n<200; n++){
//do stuff
}
}

printf("0x + i = %i\n", 0x0 + i);
printf("Advertising!\n");
break;
}

default:
break;
}
}

Interrupt seem to work since I see printf from interrupt handler but nothing else happens.

0 Likes
1 Solution
Len_CONSULTRON
Honored Contributor II

aaartis1,

 

I don't know if this will help.

I created a two project workspace for the CY8CPROTO-063-BLE.

One project is  Broadcaster-only (Advertisements/Beacons).

The other project is a Observer-only (Scanner).

I program one project in one proto board and the other on another.

I used this project as a learning project that allows me to make changes and see the effects.

Here's a link to the project:  PSoC6-BLE-Beacon-and-Scanner-Creator-projects 

This can be a benefit in the learning process or as a launching point for your code.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
2 Replies
Len_CONSULTRON
Honored Contributor II

aaartis1,

 

I don't know if this will help.

I created a two project workspace for the CY8CPROTO-063-BLE.

One project is  Broadcaster-only (Advertisements/Beacons).

The other project is a Observer-only (Scanner).

I program one project in one proto board and the other on another.

I used this project as a learning project that allows me to make changes and see the effects.

Here's a link to the project:  PSoC6-BLE-Beacon-and-Scanner-Creator-projects 

This can be a benefit in the learning process or as a launching point for your code.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
aaartis1
New Contributor II

This helps a lot, thanks!

0 Likes
Top labels