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

In Nordic\nrf51822\Board\pca10001\s110\ble_app_hrs project,the NVIC_EnableIRQ(TIMER2_IRQn)

In Nordic\nrf51822\Board\pca10001\s110\ble_app_hrs project,when I add somting into this project but the now that I add dose not work!!?

//this is buzee_gpiote_init()
static void buzee_gpiote_init(void)
{
    // Connect GPIO input buffers and configure PWM_OUTPUT_PIN_NUMBER as an output.
    //nrf_gpio_range_cfg_input(BUTTON_START, BUTTON_STOP, BUTTON_PULL);
    nrf_gpio_cfg_output(20);

    nrf_gpio_port_clear(NRF_GPIO_PORT_SELECT_PORT0, 0xFF);

    // Configure GPIOTE channel 0 to toggle the PWM pin state
    // @note Only one GPIOTE task can be connected to an output pin.
    nrf_gpiote_task_config(3, 20, \
                           NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
}
//this is buzee_ppi_init();
static void buzee_ppi_init(void)
{
    // Configure PPI channel 0 to toggle PWM_OUTPUT_PIN on every TIMER2 COMPARE[0] match.
    NRF_PPI->CH[4].EEP = (uint32_t)&NRF_TIMER2->EVENTS_COMPARE[0];
    NRF_PPI->CH[4].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[3];

    // Configure PPI channel 1 to toggle PWM_OUTPUT_PIN on every TIMER2 COMPARE[1] match.
    NRF_PPI->CH[5].EEP = (uint32_t)&NRF_TIMER2->EVENTS_COMPARE[1];
    NRF_PPI->CH[5].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[3];
    
    // Configure PPI channel 1 to toggle PWM_OUTPUT_PIN on every TIMER2 COMPARE[2] match.
    NRF_PPI->CH[6].EEP = (uint32_t)&NRF_TIMER2->EVENTS_COMPARE[2];
    NRF_PPI->CH[6].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[3];
    
    // Enable PPI channels 0-2.
    NRF_PPI->CHEN = (PPI_CHEN_CH4_Enabled << PPI_CHEN_CH4_Pos)
                    | (PPI_CHEN_CH5_Enabled << PPI_CHEN_CH5_Pos)
                    | (PPI_CHEN_CH6_Enabled << PPI_CHEN_CH6_Pos);
}
//this is buzee_timer2_init();
static void buzee_timer2_init(void)
{
    // Start 16 MHz crystal oscillator .
    //NRF_CLOCK->EVENTS_HFCLKSTARTED  = 0;
    //NRF_CLOCK->TASKS_HFCLKSTART     = 1;

    // Wait for the external oscillator to start up.
    //while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) 
    //{
        //Do nothing.
   // }

    NRF_TIMER2->MODE        = TIMER_MODE_MODE_Timer;
    NRF_TIMER2->BITMODE     = TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos;
    NRF_TIMER2->PRESCALER   = TIMER_PRESCALERS;

    // Clears the timer, sets it to 0.
    NRF_TIMER2->TASKS_CLEAR = 1;

    // Load the initial values to TIMER2 CC registers.
    NRF_TIMER2->CC[0] = MAX_SAMPLE_LEVELS + MAX_SAMPLE_LEVELS;
    NRF_TIMER2->CC[1] = MAX_SAMPLE_LEVELS;

    // CC2 will be set on the first CC1 interrupt.
    NRF_TIMER2->CC[2] = 0;

    // Interrupt setup.
    
	//NRF_TIMER2->INTENCLR = 0xFFFFFFFF;
    
    NRF_TIMER2->INTENSET = (TIMER_INTENSET_COMPARE1_Enabled << TIMER_INTENSET_COMPARE1_Pos);
}

int main(void)
{
    uint32_t err_code;

    timers_init();
    gpiote_init();
    buttons_init();
	buzee_gpiote_init();
    buzee_ppi_init();
    buzee_timer2_init();
	

    ble_stack_init();
    bond_manager_init();
	

    //Initialize Bluetooth Stack parameters
    gap_params_init();
    advertising_init();
    services_init();
    conn_params_init();
    sec_params_init();


    // Start advertising
    
    advertising_start();
	NVIC_EnableIRQ(TIMER2_IRQn);
	//
    // Enter main loop
    for (;;)
    {
        // Switch to a low power state until an event is available for the application
        err_code = sd_app_evt_wait();
        APP_ERROR_CHECK(err_code);
    }
}

The code like up,but the NVIC_EnableIRQ(TIMER2_IRQn); does not work so I can not get a PWM signal. But if I put NVIC_EnableIRQ(TIMER2_IRQn); before ble_stack_init(); ,I can get a PWM signal but Ble(the radio ) does not work .

I does not kown why,Please! dong Thanks!

Parents
  • Hi,

    If you're writing directly to the PPI/GPIOTE registers, this must be done prior to enabling the stack, as these are restricted peripherals (see softdevice specifications for full list). I do not know how your program is supposed to work, but you're using 3 CC registers, but only enabling interrupt on CC[1]. Is this desired behavior?

    Also, it seems that you're not clearing the CC-registers, which means that it will give you an interrupt when it overflows. You may do this in the TIMER2_IRQn function, but since you did not attach it, I cannot see if it's done there.

    Do you see an assert when calling ble_stack_init? If yes, can you post the results of the ASSERT?

    Best regards Håkon

Reply
  • Hi,

    If you're writing directly to the PPI/GPIOTE registers, this must be done prior to enabling the stack, as these are restricted peripherals (see softdevice specifications for full list). I do not know how your program is supposed to work, but you're using 3 CC registers, but only enabling interrupt on CC[1]. Is this desired behavior?

    Also, it seems that you're not clearing the CC-registers, which means that it will give you an interrupt when it overflows. You may do this in the TIMER2_IRQn function, but since you did not attach it, I cannot see if it's done there.

    Do you see an assert when calling ble_stack_init? If yes, can you post the results of the ASSERT?

    Best regards Håkon

Children
  • void TIMER2_IRQHandler(void) { static bool cc0_turn = false; /**< Keeps track of which CC register to be used. */

    if ((NRF_TIMER2->EVENTS_COMPARE[1] != 0) && ((NRF_TIMER2->INTENSET & TIMER_INTENSET_COMPARE1_Msk) != 0)) { // Sets the next CC1 value NRF_TIMER2->EVENTS_COMPARE[1] = 0; NRF_TIMER2->CC[1] = (NRF_TIMER2->CC[1] + MAX_SAMPLE_LEVELS);

    // Every other interrupt CC0 and CC2 will be set to their next values. uint32_t next_sample = next_sample_get();

    if (cc0_turn) { NRF_TIMER2->CC[0] = NRF_TIMER2->CC[1] + MAX_SAMPLE_LEVELS; } else { NRF_TIMER2->CC[2] = NRF_TIMER2->CC[1] + MAX_SAMPLE_LEVELS; } // Next turn the other CC will get its value. cc0_turn = !cc0_turn; } } this is TIMER2_IRQHandler(void);

    Please have a looK Thanks!

Related