KW36 central device can not scan the device problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KW36 central device can not scan the device problem

2,184 Views
jictannu
Contributor III

I am using sdk version 2.2.10, setting KW36 as the central device, and the scan configuration is as follows, I  restart scanning every 100 and print the number of times scanned.

 

void BleApp_Start(bool_t addDevice)
{
	if (!mScanningOn)
	{
        /* Set low power mode */
#if defined(cPWR_UsePowerDownMode) && (cPWR_UsePowerDownMode)
      #if defined(MULTICORE_APPLICATION_CORE) && (MULTICORE_APPLICATION_CORE)
        #if defined(gErpcLowPowerApiServiceIncluded_c) && (gErpcLowPowerApiServiceIncluded_c)
            (void)PWR_ChangeBlackBoxDeepSleepMode(gAppDeepSleepMode_c);
        #endif
      #else
        (void)PWR_ChangeDeepSleepMode(gAppDeepSleepMode_c);
      #endif
#endif

		/* Range: 0U = -30dbM to 31U = +3,5dBm, steplength ~ 1dbm */
		Controller_SetTxPowerLevel(31U,gConnTxChannel_c); // = 3,5 dbm

		if(addDevice)
		{
			gScanParams.filterPolicy = gScanAll_c;
		}
		else
		{
			gScanParams.filterPolicy = gScanWithWhiteList_c;
		}

        /* Start scanning */
        (void)App_StartScanning(&gScanParams, BleApp_ScanningCallback, gGapDuplicateFilteringEnable_c, gGapScanContinuously_d, gGapScanPeriodicDisabled_d);
	}
}
static void BleApp_ScanningCallback(gapScanningEvent_t* pScanningEvent)
{
	static bool_t isScanTimeout = FALSE;

	switch (pScanningEvent->eventType)
	{

	case gDeviceScanned_c:
	{

		mFoundDeviceToConnect = CheckScanEvent(	&pScanningEvent->eventData.scannedDevice);
		if (mFoundDeviceToConnect)
		{
			gConnReqParams.peerAddressType = pScanningEvent->eventData.scannedDevice.addressType;
			FLib_MemCpy(gConnReqParams.peerAddress, pScanningEvent->eventData.scannedDevice.aAddress, sizeof(bleDeviceAddress_t));
			bleResult_t Gap_StopScanning_status = Gap_StopScanning();
			#if defined(gAppUsePrivacy_d) && (gAppUsePrivacy_d)
				gConnReqParams.usePeerIdentityAddress = pScanningEvent->eventData.scannedDevice.advertisingAddressResolved;
			#endif

			bleResult_t App_Connect_status = App_Connect(&gConnReqParams, BleApp_ConnectionCallback);

			#if Debug_Support
				SEGGER_RTT_printf(0, "\r\nGap_StopScanning() status:0x%X \r\n", Gap_StopScanning_status);
				SEGGER_RTT_printf(0, "\r\nApp_Connect() status:0x%X \r\n", App_Connect_status);
			#endif
		}
		mFoundDevicesCount++;
	}
		break;

	case gScanStateChanged_c:
	{
		mScanningOn = !mScanningOn;

		/* Node starts scanning */
		if (mScanningOn)
		{
			mFoundDeviceToConnect = FALSE;
			#if Debug_Support
				SEGGER_RTT_printf(0, "\r\nScanning...\r\n");
			#endif
			/* Start scanning timer */
			// TMR_StartLowPowerTimer(mAppTimerId,
			// gTmrLowPowerSecondTimer_c, gScanningTime_c, ScanningTimeoutTimerCallback, NULL);
				isScanTimeout = FALSE;
			TMR_StartLowPowerTimer(mAppTimerId,
					gTmrLowPowerIntervalMillisTimer_c, 100, ScanningTimeoutTimerCallback, &isScanTimeout);
			#if (cPWR_UsePowerDownMode)
				Led1On();
			#else
				LED_StopFlashingAllLeds();
				Led1Flashing();
			#endif
		}
		/* Node is not scanning */
		else
		{
			 TMR_StopTimer(mAppTimerId);
			#if Debug_Support
				SEGGER_RTT_printf(0, "\r\nStopped scanning!\r\n");
			#endif

			if (mFoundDeviceToConnect)
			{
//				App_Connect(&gConnReqParams, BleApp_ConnectionCallback);
			} 
			else
			{
				if (mCurrentLearingKeyNum != gInvalidKeyNumber_c && isScanTimeout == FALSE)
				{
					BleApp_KeyLearningStateMachineHandler();
				}
				else
				{
					BleApp_Start(true);
				}
				#if (cPWR_UsePowerDownMode)
						Led1Off();
						/* Go to sleep */
                    #if defined(MULTICORE_APPLICATION_CORE) && (MULTICORE_APPLICATION_CORE)
                        #if defined(gErpcLowPowerApiServiceIncluded_c) && (gErpcLowPowerApiServiceIncluded_c)
                            (void)PWR_ChangeBlackBoxDeepSleepMode(cPWR_DeepSleepMode);
                        #endif
                    #else
                        (void)PWR_ChangeDeepSleepMode(cPWR_DeepSleepMode);
                    #endif
				#else
			
				#endif
			}
		}
	}
		break;

	case gScanCommandFailed_c:
	{
		#if Debug_Support
			SEGGER_RTT_printf(0, "\r\nScan command failed! Reason = 0x%X \r\n", pScanningEvent->eventData.failReason);
		#endif
	}
	break;

	default:
	{
		; /* No action required */
	}
		break;
	}
}
static void ScanningTimeoutTimerCallback(void* pParam)
{
	static uint32_t cnt = 0;
	static uint32_t oldFoundDevicesCount = 0;
	bool_t *pTimeOut = (bool_t*)pParam;
	cnt++;
	*pTimeOut = TRUE;
//	if (oldFoundDevicesCount != mFoundDevicesCount)
//	{
//		oldFoundDevicesCount = mFoundDevicesCount;
//	}
#if Debug_Support
	SEGGER_RTT_printf(0, "\r\nDeviceScanned... %d, %d ms\r\n", mFoundDevicesCount, cnt * 100);
#endif

	/* Stop scanning */
	if (mScanningOn)
	{
		Gap_StopScanning();
	}
}

 

but after a while no new devices are scanned, resulting in no connection.

 

00> DeviceScanned... 16363, 125600 ms
00> 
00> Stopped scanning!
00> 
00> Scanning...
00> 
00> DeviceScanned... 16373, 125700 ms
00> 
00> Stopped scanning!
00> 
00> Scanning...
00> 
00> DeviceScanned... 16384, 125800 ms
00> 
00> Stopped scanning!
00> 
00> Scanning...
00> 
00> DeviceScanned... 16384, 125900 ms
00> 
00> Stopped scanning!
00> 
00> Scanning...
00> 
00> DeviceScanned... 16384, 126000 ms
00> 
00> Stopped scanning!
00> 
00> Scanning...
00> 
00> DeviceScanned... 16384, 126100 ms
00> 
00> Stopped scanning!
00> 
00> Scanning...
00> 
00> DeviceScanned... 16384, 126200 ms
00> 
00> Stopped scanning!
00> 
00> Scanning...
00> 
00> DeviceScanned... 16384, 126300 ms
00> 
00> Stopped scanning!
00> 
00> Scanning...
00> 
00> DeviceScanned... 16384, 126400 ms

 

Hope to get your help.

 

Labels (1)
0 Kudos
Reply
3 Replies

2,105 Views
Ricardo_Zamora
NXP TechSupport
NXP TechSupport

Hello,

 

What SDK example are you taking as a base? What other modifications did you made?

 

What is the porpoise of restarting the scanning continually? Are you connecting to a peripheral?

 

Regards,

Ricardo

0 Kudos
Reply

2,089 Views
jictannu
Contributor III

Hi, Ricardo

This is my test project, using evk test, I can see the timer printing after pressing the button to start the scan. This number is mFoundDevicesCount, each time gDeviceScanned_c adds one, after the program runs for a while mFoundDevicesCount remains the same, proving that there is no gDeviceScanned_c anymore.

 

企业微信截图_16502708832406.png

0 Kudos
Reply

2,097 Views
jictannu
Contributor III

Hi, Ricardo

I've tested this on w_uart and it happens too. Because the normal logic of my code is scan -> connect & stop scanning -> disconnect -> scan, and after using it multiple times I found that I couldn't scan any devices, so I used this to test if the scan would be abnormal after multiple restarts

0 Kudos
Reply