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

How to implement buzzer in ble_uart_peripheral example

Hi,

I am using nrf52 with sdk11.0, I have migrated the code of pwm_library code to ble_uart_peripheral. But when i'm initializing the pwm the code it stops the advertising.Is there an code which works Ble and buzzer at the same time. Please help me.

Thanks&Regards,

Prudhvi

Parents Reply Children
  • .

    static void power_manage(void)
    {
        uint32_t err_code = sd_app_evt_wait();
        APP_ERROR_CHECK(err_code);
    }
    
    /***********PWM callback function*********/
    void pwm_ready_callback(uint32_t pwm_id)    
    {
        ready_flag = true;
    }
    /* 2channel PWM, 5kHz, output on DK LED pins. */
     app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(200L, TEST_PIN,BSP_LED_1); 
    static void on_timeout(void * p_context)
    {
        uint32_t err_code;
        uint32_t value;
             app_pwm_enable(&PWM1);
       // APP_ERROR_CHECK(err_code);
        for (uint8_t i = 0; i < 60; ++i)
        {
             value = (i < 30) ? (i * 5) : (100 - (i - 30) * 5); 
             ready_flag = false;
             while (app_pwm_channel_duty_set(&PWM1, 0, value) == NRF_ERROR_BUSY);
            //while(!ready_flag);
            APP_ERROR_CHECK(app_pwm_channel_duty_set(&PWM1, 1, value));
        }  
    
    }
    void timer_init()
    {
            uint32_t err_code;
            APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
        err_code = app_timer_create(&m_led_a_timer_id,APP_TIMER_MODE_REPEATED,on_timeout);
          err_code = app_timer_start(m_led_a_timer_id, APP_TIMER_TICKS(2000, APP_TIMER_PRESCALER), NULL);
        APP_ERROR_CHECK(err_code);
    
    }
    
    /**@brief Application main function.
     */
    int main(void)
    {
        uint32_t err_code;
        bool erase_bonds;
        timer_init();           
          uart_init(); // baudrate 115200
        buttons_leds_init(&erase_bonds);
        pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH;
          app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback);
          ble_stack_init();
        gap_params_init();
        services_init();
        advertising_init();
        conn_params_init();
        printf("\r\nUART Start!\r\n");
        err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    
    
        // Enter main loop.
        for (;;)
        {
            power_manage();
        }
    }
    
Related