This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

how can nrf51822 make 2.4G communication and BLE communication arbitrary switch?

how can nrf51822  make 2.4G communication and BLE communication arbitrary switch?

Parents Reply Children
  • I asked you before if you meant switching between BLE and some other protocol and you said, "NO".

    Now you're saying that you do want to switching between BLE and some other protocol ?

  • I got idea for switching between BLE and 2.4GHZ.But when i was disabled to softdevice using "sd_softdevice_disable()",the program come in "while (loop);". If i want to  close the softdevice, what am i going to do?  My  idea is this code for  switching between BLE and 2.4GHz.

    			nrf_gpio_cfg_output(LED_BLE);		//ble±êÖ¾
    			nrf_gpio_pin_write(LED_BLE, 0); //³õʼ״̬µçƽÀ­µÍʹ֮²»ÁÁ
    			
    			nrf_gpio_cfg_output(LED_TXS);		//2.4G±êÖ¾
    			nrf_gpio_pin_write(LED_TXS, 0); //³õʼ״̬µçƽÀ­µÍʹ֮²»ÁÁ
    			
    			nrf_gpio_cfg_input(switch_24toble,NRF_GPIO_PIN_NOPULL);
    			
    			ble_stack_init();
    			ble_app_cfg_start();
    			
        // Enter main loop.
        for (;;)
        {
    			
    			pinvalue = nrf_gpio_pin_read(switch_24toble);
    			if (pinvalue == 1)
    			{
    				running_mode = BLE;
    			}
    			else
    			{
    				running_mode = GHZ;
    			}
    			
    			 power_manage();
    			
    			if (running_mode != previous_mode)
    			{
    				previous_mode = running_mode;
    				if (running_mode == BLE)
    				{
    						AppTx_stop(); //Í£Ö¹·¢ËÍ£¬¿ªÊ¼ble
    						ble_stack_init();
    						ble_app_cfg_start();
    				}
    				else if (running_mode == GHZ)
    				{
    					//ble_app_cfg_stop();
    					ble_stack_stop(); //Í£Ö¹ble£¬×¢Òâֹͣ˳Ðò£»¿ªÊ¼2.4GHZ
    					
    					
    					esb_tx_init();		//³õʼ»¯·¢ËÍÅäÖÃ
    					ret = AppTx_Send((uint8_t *)buf,5);			//·¢ËÍÒ»Ö¡¹Ì¶¨Ö¡£¬²âÊÔÓÃ
    					if (ret < 0)
    					{
    						ret = 0;
    					}
    				}
    				
    void ble_stack_stop(void)
    {
        uint32_t err_code;
    
        err_code = softdevice_handler_sd_disable();
        APP_ERROR_CHECK(err_code);
    }
    
    uint32_t softdevice_handler_sd_disable(void)
    {
        uint32_t err_code = sd_softdevice_disable();
    #if 1
        if (err_code == NRF_SUCCESS)
        {
            m_softdevice_enabled = false;
            nrf_drv_clock_on_sd_disable();
        }
    #else
        m_softdevice_enabled = !(err_code == NRF_SUCCESS);
    #endif
        return err_code;
    }

Related