I can't control LED belt

I am using nrf52832 and developing with FreeRTOS. I want to use Bluetooth and control a WS2812 LED strip simultaneously. When I don't start Bluetooth, i.e. //nrf_sdh_freertos_init(advertising_start, &erase_bonds), I can control the LED strip normally. However, when I start Bluetooth, the LED strip control becomes abnormal.

  • Hi Suhaihui, 

    Could you please show how do you control the WS2812. Please show the task that handle the LEDs. 
    You mentioned it became abnormal, could you give more info on what exactly happened ? 
    Have you looked at our ble_app_hrs_freertos example ? Please see how we run the xtimers to do different tasks there. 

  • I was use hardware timer to control ws2812.

    uint32_t led_hardware_timer_init(void)
    {
    	uint32_t err_code = NRF_SUCCESS;
    	
    	nrf_drv_timer_config_t timer_config;
    	timer_config.frequency = NRF_TIMER_FREQ_62500Hz;
    	timer_config.mode = NRF_TIMER_MODE_TIMER;
    	timer_config.bit_width = NRF_TIMER_BIT_WIDTH_24;
    	timer_config.interrupt_priority = APP_IRQ_PRIORITY_HIGHEST;
    	timer_config.p_context = NULL;
    	
    	err_code = nrf_drv_timer_init(&led_timer, &timer_config, led_timeout_handler);
        
        if(NRF_SUCCESS == err_code)
    	{
            m_led_timer_state = TIMER_STATE_INITIALIZED;
    	}
    	
    	return err_code;
    }

  • Hi Suhaihui, 

    I don't think using the hardware timer can be tricky when using with FreeRTOS. 
    How long do you stay in the interrupt handler ? Have you tried to test with APP_IRQ_PRIORITY_LOW ? 
    Which timer do you use ? Please be aware that TIMER0 is blocked by the softdevice and you should choose other TIMER.

  • 1. I was used timer1
       ie: NRF_DRV_TIMER_INSTANCE(1)
    2.  I tried to test with APP_IRQ_PRIORITY_LOW
       same result

    3. It stay in interrupt less then 0.5ms

    I control ws2812 like this

    #define   RGB_H      (NRF_GPIO->OUTSET = (1UL << TARGET_LED1_PIN))   
    #define   RGB_L      (NRF_GPIO->OUTCLR = (1UL << TARGET_LED1_PIN))  
    
    static void LED_Write0(void)
    {
    	RGB_H;
    	__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
    	__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
    	RGB_L;
    	__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
    	__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
        __NOP();
    }
    
    static void LED_Write1(void)
    {
    	RGB_H;
    	__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
    	__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
        __NOP();__NOP();__NOP();__NOP();__NOP();
        __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
    	__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
    	
    	RGB_L;
    	__NOP();__NOP();__NOP();
    }

  • Hi, 
    Please show the full code how you call LED_Write0 and LED_Write1.
    Have you looked at how we use timer in the ble_app_hrs_freertos example ? 

Related