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

NRF_DRV_ADC_DEFAULT_CHANNEL compiling error

Hi, When compiling my program on SEGGER embedded studio I get the error:

  Compiling ‘main.c’
    main.c
    expected expression before '{' token
    in expansion of macro 'NRF_DRV_ADC_DEFAULT_CHANNEL'

In the code:

    #define ADC_RIGHT	ADC_CONFIG_PSEL_AnalogInput2
    #define ADC_DOWN	ADC_CONFIG_PSEL_AnalogInput3
    #define ADC_LEFT	ADC_CONFIG_PSEL_AnalogInput4
    #define ADC_UP	ADC_CONFIG_PSEL_AnalogInput5
    
    uint32_t SSW_LIST[4] = { ADC_RIGHT, ADC_DOWN, ADC_LEFT, ADC_UP };

static void adc_config(nrf_drv_adc_channel_t channel)
{
    ret_code_t ret_code;
    nrf_drv_adc_config_t config = NRF_DRV_ADC_DEFAULT_CONFIG;

    ret_code = nrf_drv_adc_init(&config, adc_event_handler);
    APP_ERROR_CHECK(ret_code);

    nrf_drv_adc_channel_enable(&channel);
}
    
int main(void)
{
    uint32_t err_code;
    bool erase_bonds;

    // Initialize.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
    uart_init();

    buttons_leds_init(&erase_bonds);
    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);
    APP_ERROR_CHECK(err_code);

    // Enter main loop.
    for (;;)
    {
        uint32_t i;
        int j = 0;
        for (i = 0; i < ADC_BUFFER_SIZE; i++)
        {
            nrf_adc_config_input_t channel = SSW_LIST[j];
	    adc_config(NRF_DRV_ADC_DEFAULT_CHANNEL(channel)); // error in this line
            APP_ERROR_CHECK(nrf_drv_adc_buffer_convert(adc_buffer,ADC_BUFFER_SIZE));
            if(j==3)
              j = 0;
            else
              j++;

            if(send_flag){
              uint32_t       err_code;
              char snum[5];
              itoa(adc_buffer[i], snum, 10);
              err_code = ble_nus_string_send(&m_nus, snum, 5);
            }
            power_manage();
            nrf_delay_ms(SAMPLING_PERIOD);
        }
    }
}

on the last line.

The same program compiled on Keil gives this error:

..\..\..\main.c(660): error:  #29: expected an expression
              adc_config(
RF_DRV_ADC_DEFAULT_CHANNEL(SSW_LIST[j]));

The function adc_config is the same as SDK V12 adc example thanks a lot

Parents
  • Hi,

    I'm not sure what you are trying to do in your code, but there are multiple problems. You should pass the adc input to the adc_config() function instead of NRF_DRV_ADC_DEFAULT_CHANNEL(channel):

    static void adc_config(nrf_adc_config_input_t input)
    {
        ret_code_t ret_code;
        nrf_drv_adc_config_t config = NRF_DRV_ADC_DEFAULT_CONFIG;
    
        ret_code = nrf_drv_adc_init(&config, adc_event_handler);
        APP_ERROR_CHECK(ret_code);
    
        nrf_drv_adc_channel_t channel_config = NRF_DRV_ADC_DEFAULT_CHANNEL(input)
        nrf_drv_adc_channel_enable(&channel_config);
    }
    

    Another problem is that you cannot call nrf_drv_adc_init() if the ADC driver is already initialized. You are now calling this function ADC_BUFFER_SIZE times. You will have to split this into two separate functions, or integrate the channel loop into your adc_config() function. It is not a good idea to put the ADC configuration inside a loop, unless you are uninitializing it somewhere. This will cause errors when the loop starts over again.

    Best regards,

    Jøgen

  • Thanks for your input, it helped me separate the initialization from channel selection reading.

Reply Children
No Data
Related