This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/CC1350: ADCBuf one-shot mode callback problem

Part Number: CC1350


Tool/software: TI-RTOS

I am trying to use ADCBuf driver on CC1350 Launchpad board. I am using TI-RTOS. When I use ADCBuf in blocking mode, everything is fine. But when I use it in non-blocking mode, it goes to callback just once then it gets stuck. Other tasks runs fine. If I change the sample size to 1, it does not get stuck but the value returned from ADC is wrong and always the same value returns. Please help.

/*
 *  ======== adcBufCallback ========
 *  ADCBuf conversion complete callback function
 */
void adcBufCallback(ADCBuf_Handle handle, ADCBuf_Conversion *conversion, void *completedADCBuffer, uint32_t completedChannel)
{
    PIN_setOutputValue(ledPinHandle, Board_LED1, 0);

    //uint32_t microVoltBuffer[ADCBUFFERSIZE];
    //ADCBuf_adjustRawValues(handle, completedADCBuffer, ADCBUFFERSIZE, completedChannel);
    //ADCBuf_convertAdjustedToMicroVolts(handle, completedChannel, completedADCBuffer, microVoltBuffer, ADCBUFFERSIZE);
}

void adcConvertFxn()
{
    while(1)
    {
        Semaphore_pend(scConductivityExcStarted, BIOS_WAIT_FOREVER);

        ADCBuf_Conversion singleConversion;

        /* Configure the conversion struct */
        singleConversion.arg = NULL;
        singleConversion.adcChannel = 7;
        singleConversion.sampleBuffer = sampleBufferOne;
        singleConversion.sampleBufferTwo = NULL;
        singleConversion.samplesRequestedCount = ADCBUFFERSIZE;

        if (!adcBufHandle)
        {
            System_printf("ADC handler error!\n");
        }

        PIN_setOutputValue(ledPinHandle, Board_LED1, 1);

        if (ADCBuf_convert(adcBufHandle, &singleConversion, 1) != ADCBuf_STATUS_SUCCESS)
        {
            // handle error
            System_printf("ADC error!\n");
        }

        //ADCBuf_adjustRawValues(adcBufHandle, sampleBufferOne, ADCBUFFERSIZE, singleConversion.adcChannel);
        //ADCBuf_convertAdjustedToMicroVolts(adcBufHandle, singleConversion.adcChannel, sampleBufferOne, microVoltBuffer, ADCBUFFERSIZE);

        //Mailbox_post(adcMicroVoltMailbox, microVoltBuffer, BIOS_NO_WAIT);
        //ADCBuf_close(adcBufHandle);
    }
}

  • Hi,

    How are you setting up the ADCBuf params? I tried myself to modify the "adcbufcontinuous"  example to run in one_shot mode using the same conversion you are using and I'm not having any trouble with the callback or readings. 

    Have you done any changes to the board file ADCBuf structures? 

  • Hi,

    Can you share the code how you changed the adcbufcontinous example to single-shot?

  • Inside main thread I did the following changes:

        /* Set up an ADCBuf peripheral in ADCBuf_RECURRENCE_MODE_CONTINUOUS */
        ADCBuf_Params_init(&adcBufParams);
        adcBufParams.callbackFxn = adcBufCallback;
        adcBufParams.recurrenceMode = ADCBuf_RECURRENCE_MODE_ONE_SHOT;
        adcBufParams.returnMode = ADCBuf_RETURN_MODE_CALLBACK;
        adcBufParams.samplingFrequency = 200;
        adcBuf = ADCBuf_open(Board_ADCBUF0, &adcBufParams);
    
        ADCBuf_Conversion singleConversion;
    
        /* Configure the conversion struct */
        singleConversion.arg = NULL;
        singleConversion.adcChannel = 7;
        singleConversion.sampleBuffer = sampleBufferOne;
        singleConversion.sampleBufferTwo = NULL;
        singleConversion.samplesRequestedCount = ADCBUFFERSIZE;
    
        /* Configure the conversion struct */
    //    continuousConversion.arg = NULL;
    //    continuousConversion.adcChannel = Board_ADCBUF0CHANNEL0;
    //    continuousConversion.sampleBuffer = sampleBufferOne;
    //    continuousConversion.sampleBufferTwo = sampleBufferTwo;
    //    continuousConversion.samplesRequestedCount = ADCBUFFERSIZE;
    
        if (!adcBuf){
            /* AdcBuf did not open correctly. */
            while(1);
        }
    
        PIN_State pinState;
        ledPinHandle = PIN_open(&pinState, BoardGpioInitTable);
    
        PIN_setOutputValue(ledPinHandle, Board_LED1, 1);
        /* Start converting. */
        if (ADCBuf_convert(adcBuf, &singleConversion, 1) !=
            ADCBuf_STATUS_SUCCESS) {
            /* Did not start conversion process correctly. */
            while(1);
        }

    Inside the callback function, i did changed to the following:

    void adcBufCallback(ADCBuf_Handle handle, ADCBuf_Conversion *conversion,
        void *completedADCBuffer, uint32_t completedChannel) {
    //    uint_fast16_t i;
    //    uint_fast16_t uartTxBufferOffset;
    //
    //    /* Adjust raw adc values and convert them to microvolts */
    //    ADCBuf_adjustRawValues(handle, completedADCBuffer, ADCBUFFERSIZE,
    //        completedChannel);
    //    ADCBuf_convertAdjustedToMicroVolts(handle, completedChannel,
    //        completedADCBuffer, microVoltBuffer, ADCBUFFERSIZE);
    //
    //    /*
    //     * Start with a header message and convert each entry in the current buffer
    //     * to a human-readable format
    //     */
    //    uartTxBufferOffset = sprintf(uartTxBuffer,
    //        "\r\nBuffer %u finished:\r\n", (unsigned int)buffersCompletedCounter++);
    //
    //    for (i = 0; i < ADCBUFFERSIZE; i++) {
    //        uartTxBufferOffset += sprintf(uartTxBuffer + uartTxBufferOffset,
    //            "%u,", (unsigned int)microVoltBuffer[i]);
    //    }
    //    uartTxBuffer[uartTxBufferOffset] = '\n';
    //    /* Send out the data via UART */
    //    UART_write(uart, uartTxBuffer, uartTxBufferOffset + 1);
    
        // Toggle LED
        uint32_t pinValue = PIN_getOutputValue(Board_LED1);
        if (pinValue & Board_LED1)
            PIN_setOutputValue(ledPinHandle, Board_LED1, 0);
        else
            PIN_setOutputValue(ledPinHandle, Board_LED1, 1);
        // Start a new conversion
        ADCBuf_convert(handle, conversion, 1);
    }

    When running the example with these changes I get a blinking LED and correct ADC readings of DIO30.