ERROR 17 [NRF_ERROR_BUSY] when I call " nrf_drv_spi_transfer() "

I am developing an application that get information from a thermocouple sensor that use a IC (max6675k) to communicate with the NRF52832 via SPI.

The application needs to get the information from the sensor each certain time, and print it on the serial monitor. As well, I need to get the account of times that buttom is push thus I defined a GPIO interrupt to register it. Also I need communication with the NRF using the NUS and get the battery level using BAS.

when I call "nrf_drv_spi_transfer()" the first time, I have no Errors, however I notice that the SPI handler functions it is never called. When the "nrf_drv_spi_transfer()" is called for second time, I get the ERROR 17 [NRF_ERROR_BUSY]. 

I will describe the steps that the application take:

    /*Init Functions*/
    {
        ret_code_t err_code;
        
        uart_init();
        
        log_init();
        
        timers_init();
        
        gpio_init();
        
        gpiote_init();
        
        saadc_init(); 
        
        spi_init();
        
        init_pin_MAX6675();  

        power_management_init();

        ble_stack_init();

        err_code = nrf_fstorage_init(&fstorage, &nrf_fstorage_sd, NULL);
        APP_ERROR_CHECK(err_code);

        gap_params_init();

        gatt_init();

        services_init();

        advertising_init();

        conn_params_init();        
    }

// Start execution.
    
    advertising_start();
    start_send_info();


    NRF_LOG_INFO("STARTED");
    

loop:

    for (;;)
    {
        
        idle_state_handle(); 
         

        if (SEND_INFO_FLAG){

            // ***** Get The values ******//
            stop_send_info();
            SEND_INFO_FLAG=0;


            /* Battery status: true - battery ok, false - battery low */
            bool  batteryStatus   = get_battery_status();
            
            /* Channels Counter DRYCON's */ 
            uint32_t conunterDif1 = dryConCounter1 - dryConCounter1_p;   
            uint32_t conunterDif2 = dryConCounter2 - dryConCounter2_p;         
            uint32_t conunterDif3 = dryConCounter3 - dryConCounter3_p;        
                  
            storage_counter_data(dryConCounter1Flash, conunterDif1);
            storage_counter_data(dryConCounter2Flash, conunterDif2);
            storage_counter_data(dryConCounter3Flash, conunterDif3);             
            
            uint32_t channel1counter = dryConCounter1;
            uint32_t channel2counter = dryConCounter2;
            uint32_t channel3counter = dryConCounter3;

            dryConCounter1_p=dryConCounter1;
            dryConCounter2_p=dryConCounter2;
            dryConCounter3_p=dryConCounter3;

            uint32_t channel1counter_h = get_historical_counter(dryConCounter1Flash) ;
            uint32_t channel2counter_h = get_historical_counter(dryConCounter2Flash);
            uint32_t channel3counter_h = get_historical_counter(dryConCounter3Flash);

            /* Digitals Values */
            bool digital1Value = get_digital_status(DIGITAL1);
            bool digital2Value = get_digital_status(DIGITAL2);

            /* Analogs Values */
            float analog1Value = get_analog_reading(ANALOG1);
            float analog2Value = get_analog_reading(ANALOG2);
            float analog3Value = get_analog_reading(ANALOG3);

            /* Temperature reading*/
            uint16_t temp=max6675_readcelsius();     //<---- error occurs here
            
            /*PRINT THE DATA IN SERIAL MONITOR*/
            
    }

Function called in the loop:

uint16_t max6675_readcelsius(void) {

    ret_code_t err_code;
    uint8_t outbuffer[2];
    uint16_t temp;

    err_code = nrf_drv_spi_transfer(&spi,NULL,0,outbuffer,2);
    APP_ERROR_CHECK(err_code);
    
    nrf_gpio_pin_set(CS_MAX6675);

    temp = ((uint16_t)outbuffer[0]<<8)|((uint16_t)outbuffer[1]);  
        
    temp = temp>>3;
    temp = temp*25;

    return temp;
}

static void send_info (void *p_context){

      NRF_LOG_INFO("TIMER handler.");

      SEND_INFO_FLAG = 1;

}

I has read some forums where it is indicate that the problem could be that into the interrupts other interrupts functios are be called, but it is not the case. I am not calling other functions into the interrupts. However the  SPI functions handler it is never called.

what is it wrong?

Parents
  • Hi

    What instance of the SPI are you using for this communication? The SPI, SPIM, SPIS, TWI, TWIM and TWIS all have shared peripheral IDs, meaning that you can run only one of these on each of the 3 instance IDs on the nRF52832.

    My guess is that you're trying to start a new SPI transfer before the SPI peripheral is ready. You need to wait for a "COMPLETE" event from the SPI peripheral before calling the next transfer function on your end.

    Best regards,

    Simon

Reply
  • Hi

    What instance of the SPI are you using for this communication? The SPI, SPIM, SPIS, TWI, TWIM and TWIS all have shared peripheral IDs, meaning that you can run only one of these on each of the 3 instance IDs on the nRF52832.

    My guess is that you're trying to start a new SPI transfer before the SPI peripheral is ready. You need to wait for a "COMPLETE" event from the SPI peripheral before calling the next transfer function on your end.

    Best regards,

    Simon

Children
No Data
Related