TI中文支持网
TI专业的中文技术问题搜集分享网站

CC1350 ADCBUF 求助

我根据adcbufcontinuous的提示更改代码想要四信道adc采集但是只能读出单通道数据

 *  ======== adcBufContinuousSampling.c ========
 */
#include <stdint.h>
#include <stdio.h>
/* For sleep() */
#include <unistd.h>
/* Driver Header files */
#include <ti/drivers/ADCBuf.h>
#include <ti/drivers/UART.h>
/* Example/Board Header files */
#include "Board.h"
#define ADCBUFFERSIZE    (64)
#define UARTBUFFERSIZE   ((20* ADCBUFFERSIZE) + 24)
uint16_t sampleBufferOne[ADCBUFFERSIZE/4];
uint16_t sampleBufferTwo[ADCBUFFERSIZE/4];
uint16_t sampleBufferOne2[ADCBUFFERSIZE/4];
uint16_t sampleBufferTwo2[ADCBUFFERSIZE/4];
uint16_t sampleBufferOne3[ADCBUFFERSIZE/4];
uint16_t sampleBufferTwo3[ADCBUFFERSIZE/4];
uint16_t sampleBufferOne4[ADCBUFFERSIZE/4];
uint16_t sampleBufferTwo4[ADCBUFFERSIZE/4];
uint32_t microVoltBuffer[ADCBUFFERSIZE];
uint32_t buffersCompletedCounter = 0;
char uartTxBuffer[UARTBUFFERSIZE];
/* Driver handle shared between the task and the callback function */
UART_Handle uart;
/*
 * This function is called whenever an ADC buffer is full.
 * The content of the buffer is then converted into human-readable format and
 * sent to the PC via UART.
 */
void adcBufCallback(ADCBuf_Handle handle, ADCBuf_Conversion *conversion,
    void *completedADCBuffer, uint32_t completedChannel)
{
    uint_fast16_t i;
    uint_fast16_t uartTxBufferOffset = 0;
    /* 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. */
    uartTxBufferOffset = snprintf(uartTxBuffer,
        UARTBUFFERSIZE – uartTxBufferOffset, "\r\nBuffer %u finished.",
        (unsigned int)buffersCompletedCounter++);
    /* Write raw adjusted values to the UART buffer if there is room. */
    uartTxBufferOffset += snprintf(uartTxBuffer + uartTxBufferOffset,
        UARTBUFFERSIZE – uartTxBufferOffset, "\r\nRaw Buffer: ");
    for (i = 0; i < ADCBUFFERSIZE && uartTxBufferOffset < UARTBUFFERSIZE; i++) {
        uartTxBufferOffset += snprintf(uartTxBuffer + uartTxBufferOffset,
            UARTBUFFERSIZE – uartTxBufferOffset, "%u,",
        *(((uint16_t *)completedADCBuffer) + i));
    }
    /* Write microvolt values to the UART buffer if there is room. */
    if (uartTxBufferOffset < UARTBUFFERSIZE) {
        uartTxBufferOffset += snprintf(uartTxBuffer + uartTxBufferOffset,
            UARTBUFFERSIZE – uartTxBufferOffset, "\r\nMicrovolts: ");
        for (i = 0; i < ADCBUFFERSIZE && uartTxBufferOffset < UARTBUFFERSIZE; i++) {
            uartTxBufferOffset += snprintf(uartTxBuffer + uartTxBufferOffset,
                UARTBUFFERSIZE – uartTxBufferOffset, "%u,",
                (unsigned int)microVoltBuffer[i]);
        }
    }
    /*
     * Ensure we don't write outside the buffer.
     * Append a newline after the data.
     */
    if (uartTxBufferOffset < UARTBUFFERSIZE) {
        uartTxBuffer[uartTxBufferOffset++] = '\n';
    }
    else {
        uartTxBuffer[UARTBUFFERSIZE-1] = '\n';
    }
    /* Display the data via UART */
    UART_write(uart, uartTxBuffer, uartTxBufferOffset);
}
/*
 * Callback function to use the UART in callback mode. It does nothing.
 */
void uartCallback(UART_Handle handle, void *buf, size_t count) {
   return;
}
/*
 *  ======== mainThread ========
 */
void *mainThread(void *arg0)
{
    UART_Params uartParams;
    ADCBuf_Handle adcBuf;
    ADCBuf_Params adcBufParams;
    ADCBuf_Conversion continuousConversion[4];
    /* Call driver init functions */
    ADCBuf_init();
    UART_init();
    /* Create a UART with data processing off. */
    UART_Params_init(&uartParams);
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.writeMode = UART_MODE_CALLBACK;
    uartParams.writeCallback = uartCallback;
    uartParams.baudRate = 115200;
    uart = UART_open(Board_UART0, &uartParams);
    /* Set up an ADCBuf peripheral in ADCBuf_RECURRENCE_MODE_CONTINUOUS */
    ADCBuf_Params_init(&adcBufParams);
    adcBufParams.callbackFxn = adcBufCallback;
    adcBufParams.recurrenceMode = ADCBuf_RECURRENCE_MODE_CONTINUOUS;
    adcBufParams.returnMode = ADCBuf_RETURN_MODE_CALLBACK;
    adcBufParams.samplingFrequency = 200;
    adcBuf = ADCBuf_open(Board_ADCBUF0, &adcBufParams);
    /* Configure the conversion struct */
    continuousConversion[0].arg = NULL;
    continuousConversion[0].adcChannel = 2;
    continuousConversion[0].sampleBuffer = sampleBufferOne;
    continuousConversion[0].sampleBufferTwo = sampleBufferTwo;
    continuousConversion[0].samplesRequestedCount = ADCBUFFERSIZE/4;
    continuousConversion[1].arg = NULL;
    continuousConversion[1].adcChannel = 3;
    continuousConversion[1].sampleBuffer = sampleBufferOne2;
    continuousConversion[1].sampleBufferTwo = sampleBufferTwo2;
    continuousConversion[1].samplesRequestedCount = ADCBUFFERSIZE/4;
    continuousConversion[2].arg = NULL;
    continuousConversion[2].adcChannel = 4;
    continuousConversion[2].sampleBuffer = sampleBufferOne3;
    continuousConversion[2].sampleBufferTwo = sampleBufferTwo3;
    continuousConversion[2].samplesRequestedCount = ADCBUFFERSIZE/4;
    continuousConversion[3].arg = NULL;
    continuousConversion[3].adcChannel = 5;
    continuousConversion[3].sampleBuffer = sampleBufferOne4;
    continuousConversion[3].sampleBufferTwo = sampleBufferTwo4;
    continuousConversion[3].samplesRequestedCount = ADCBUFFERSIZE/4;
    if (adcBuf == NULL){
        /* ADCBuf failed to open. */
        while(1);
    }
    /* Start converting. */
    if (ADCBuf_convert(adcBuf, continuousConversion, 4) !=
        ADCBuf_STATUS_SUCCESS) {
        /* Did not start conversion process correctly. */
        while(1);
    }
    /*
     * Go to sleep in the foreground thread forever. The ADC hardware will
     * perform conversions and invoke the callback function when a buffer is
     * full.
     */
    while(1) {
        sleep(1000);
    }
}

如果将

if (ADCBuf_convert(adcBuf, continuousConversion, 4) !=
ADCBuf_STATUS_SUCCESS) {
/* Did not start conversion process correctly. */
while(1);
}
中的continuousConversion[4]改为 continuousConversion[0]、 continuousConversion[1]、 continuousConversion[2]、 continuousConversion[3]
均只能读出单个通道的数据
这是为什么

应该如何更改

Viki Shi:

e2echina.ti.com/…/589204

YiKai Chen:

已經在你的另一重複帖子給你範例程序

赞(0)
未经允许不得转载:TI中文支持网 » CC1350 ADCBUF 求助
分享到: 更多 (0)