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.

LAUNCHXL-CC1310: ADC数据存储问题

Part Number: LAUNCHXL-CC1310
Other Parts Discussed in Thread: TIMAC

你好,

我现在遇到一些问题需要寻求帮助。我现在计划使用TI15.4的collector与sensor例程发送采集到的ADC数据,我现在计划每次发送100个ADC数据,所以我将使用clock例程产生一个定时器,每10ms采集一个ADC数据,并将ADC数据存储到定义的包含一百个元素的数组中,但是当我从sensor发送数据到collector时,collector端接收到的数据全是零(我采集的ADC是3.3V的电压)。所以我想要询问一下是什么方面的原因,代码如下:

主函数

绿色部分标注的为时钟产生信号

int main(void)
{
Task_Params taskParams;
Clock_Params clkParams;
#ifndef USE_DEFAULT_USER_CFG
macUser0Cfg[0].pAssertFP = macHalAssertHandler;
#endif

#if ((CONFIG_RANGE_EXT_MODE == APIMAC_HIGH_GAIN_MODE) && \
defined(DeviceFamily_CC13X0) && !defined(FREQ_2_4G))
macUser0Cfg[0].pSetRE = Board_Palna_initialize;
#endif
/*
Initialization for board related stuff such as LEDs
following TI-RTOS convention
*/
PIN_init(BoardGpioInitTable);

#ifdef FEATURE_BLE_OAD
/* If FEATURE_BLE_OAD is enabled, look for a left button
* press on reset. This indicates to revert to some
* factory image
*/
if(!PIN_getInputValue(Board_PIN_BUTTON0))
{
OAD_markSwitch();
}
#endif /* FEATURE_BLE_OAD */

#if defined(POWER_MEAS)
/* Disable external flash for power measurements */
Board_shutDownExtFlash();
#endif

#if defined(FEATURE_BLE_OAD) || defined(FEATURE_NATIVE_OAD)
SPI_init();
#endif

#ifndef POWER_MEAS
#if defined(BOARD_DISPLAY_USE_UART)
/* Enable System_printf(..) UART output */
UART_init();
UART_Params_init(&uartParams);
#ifndef TIMAC_AGAMA_FPGA
uartParams.baudRate = 115200;
#else
uartParams.baudRate = 460800;
#endif
UartPrintf_init(UART_open(Board_UART0, &uartParams));
#endif /* BOARD_DISPLAY_USE_UART */
#endif
Display_init();
#ifdef OSAL_PORT2TIRTOS
_macTaskId = macTaskInit(macUser0Cfg);
#endif
ADC_init();
/* Configure task. */
Clock_Params_init(&clkParams);
clkParams.period = 10000/Clock_tickPeriod;
clkParams.startFlag = TRUE;
/* Construct a periodic Clock Instance */
Clock_construct(&clk0Struct, (Clock_FuncPtr)clk0Fxn,
5000/Clock_tickPeriod, &clkParams);
Task_Params_init(&taskParams);
taskParams.stack = appTaskStack;
taskParams.stackSize = APP_TASK_STACK_SIZE;
taskParams.priority = APP_TASK_PRIORITY;
Task_construct(&appTask, appTaskFxn, &taskParams, NULL);

#ifdef DEBUG_SW_TRACE
IOCPortConfigureSet(IOID_8, IOC_PORT_RFC_TRC, IOC_STD_OUTPUT
| IOC_CURRENT_4MA | IOC_SLEW_ENABLE);
#endif /* DEBUG_SW_TRACE */

clk2Handle = Clock_handle(&clk0Struct);
Clock_start(clk2Handle);

BIOS_start(); /* enable interrupts and start SYS/BIOS */

return (0);
}

ADC采集函数

在此函数中将采集到的ADC数据发送到   ambienceTemp[ADC_SAMPLE_COUNT_t] 中,这个是将原例程中温度数据修改成包含100个元素的数组

Void clk0Fxn(UArg arg0)
{
UInt32 time;
Smsgs_tempSensorField_t temp;
if(ADC_inint_flag == 0){
ADC_inint_flag = 1;
ADC_Params_init(&params);
adc = ADC_open(Board_ADC1, &params);
if (adc == NULL) {
Display_printf(display, 0, 0, "Error initializing ADC0\n");
Display_print1(display, 0, 0, "ADC_inint_flag:%d",ADC_inint_flag);
while (1);
}
else{
Display_printf(display, 0, 0, "Success initializing ADC0\n");
}
}
else{
/* Blocking mode conversion */
if(ADC_SAMPLE_COUNT_t != ADC_SAMPLE_COUNT){
ADC_SAMPLE_COUNT_t++;
res = ADC_convert(adc,&temp.ambienceTemp[ADC_SAMPLE_COUNT_t]);
}
else{
ADC_SAMPLE_COUNT_t=1;
res = ADC_convert(adc, &temp.ambienceTemp[ADC_SAMPLE_COUNT_t]);
}

if (res == ADC_STATUS_SUCCESS) {
time = Clock_getTicks();
//System_printf("System time in clk0Fxn = %lu\n", (ULong)time);
LCD_WRITE_STRING_VALUE("ADC_DATA:",&temp.ambienceTemp[ADC_SAMPLE_COUNT_t], 16, 5);
}
else {
Display_printf(display, 0, 0, "ADC convert failed!\n");
}
}

}

修改后的数组结构

typedef struct _Smsgs_tempsensorfield_t
{
/*!
Ambience Chip Temperature - each value represents a 0.01 C
degree, so a value of 2475 represents 24.75 C.
*/
uint16_t ambienceTemp[100];
/*!
Object Temperature - each value represents a 0.01 C
degree, so a value of 2475 represents 24.75 C.
*/
//int16_t objectTemp;
} Smsgs_tempSensorField_t;

sensor组建发送数据字段,在这个程序中负责将采集到的100个ADC组帧到数据包中发送出去

static bool sendSensorMessage(ApiMac_sAddr_t *pDstAddr, Smsgs_sensorMsg_t *pMsg)
{
bool ret = false;
uint8_t *pMsgBuf;
uint16_t len = SMSGS_BASIC_SENSOR_LEN;
int cnt=0;

/* Figure out the length */
if(pMsg->frameControl & Smsgs_dataFields_tempSensor)
{
len += SMSGS_SENSOR_TEMP_LEN;
}
if(pMsg->frameControl & Smsgs_dataFields_lightSensor)
{
len += SMSGS_SENSOR_LIGHT_LEN;
}
if(pMsg->frameControl & Smsgs_dataFields_humiditySensor)
{
len += SMSGS_SENSOR_HUMIDITY_LEN;
}
if(pMsg->frameControl & Smsgs_dataFields_msgStats)
{
//len += SMSGS_SENSOR_MSG_STATS_LEN;
len += sizeof(Smsgs_msgStatsField_t);
}
if(pMsg->frameControl & Smsgs_dataFields_configSettings)
{
len += SMSGS_SENSOR_CONFIG_SETTINGS_LEN;
}

pMsgBuf = (uint8_t *)Ssf_malloc(len);
if(pMsgBuf)
{
uint8_t *pBuf = pMsgBuf;

*pBuf++ = (uint8_t)Smsgs_cmdIds_sensorData;

memcpy(pBuf, pMsg->extAddress, SMGS_SENSOR_EXTADDR_LEN);
pBuf += SMGS_SENSOR_EXTADDR_LEN;

pBuf = Util_bufferUint16(pBuf,pMsg->frameControl);

/* Buffer data in order of frameControl mask, starting with LSB */
if(pMsg->frameControl & Smsgs_dataFields_tempSensor)
{
for(int i=0;i<100;i++){
cnt++;
pBuf = Util_bufferUint16(pBuf, pMsg->tempSensor.ambienceTemp[cnt]);
}
//pBuf = Util_bufferUint16(pBuf, pMsg->tempSensor.ambienceTemp);
//pBuf = Util_bufferUint16(pBuf, pMsg->tempSensor.objectTemp);
}
if(pMsg->frameControl & Smsgs_dataFields_lightSensor)
{
pBuf = Util_bufferUint16(pBuf, pMsg->lightSensor.rawData);
}
if(pMsg->frameControl & Smsgs_dataFields_humiditySensor)
{
pBuf = Util_bufferUint16(pBuf, pMsg->humiditySensor.temp);
pBuf = Util_bufferUint16(pBuf, pMsg->humiditySensor.humidity);
}
if(pMsg->frameControl & Smsgs_dataFields_msgStats)
{
pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.joinAttempts);
pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.joinFails);
pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.msgsAttempted);
pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.msgsSent);
pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.trackingRequests);
pBuf = Util_bufferUint16(pBuf,
pMsg->msgStats.trackingResponseAttempts);
pBuf = Util_bufferUint16(pBuf,
pMsg->msgStats.trackingResponseSent);
pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.configRequests);
pBuf = Util_bufferUint16(pBuf,
pMsg->msgStats.configResponseAttempts);
pBuf = Util_bufferUint16(pBuf,
pMsg->msgStats.configResponseSent);
pBuf = Util_bufferUint16(pBuf,
pMsg->msgStats.channelAccessFailures);
pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.macAckFailures);
pBuf = Util_bufferUint16(pBuf,
pMsg->msgStats.otherDataRequestFailures);
pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.syncLossIndications);
pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.rxDecryptFailures);
pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.txEncryptFailures);
pBuf = Util_bufferUint16(pBuf, Ssf_resetCount);
pBuf = Util_bufferUint16(pBuf, Ssf_resetReseason);
pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.joinTime);
pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.interimDelay);
pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.numBroadcastMsgRcvd);
pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.numBroadcastMsglost);
pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.avgE2EDelay);
pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.worstCaseE2EDelay);
}
if(pMsg->frameControl & Smsgs_dataFields_configSettings)
{
pBuf = Util_bufferUint32(pBuf,
pMsg->configSettings.reportingInterval);
pBuf = Util_bufferUint32(pBuf,
pMsg->configSettings.pollingInterval);

}

ret = Sensor_sendMsg(Smsgs_cmdIds_sensorData, pDstAddr, true, len, pMsgBuf);
if(ret == true){
LCD_WRITE_STRING("Data Success Send.................", 2);
}
else{
LCD_WRITE_STRING("Data Success Failed", 2);
}

Ssf_free(pMsgBuf);
}

return (ret);
}

期待收到您们的回复,谢谢!

  • 您好,您这边sensor采集到的电压值有没有进行串口打印输出进行调试查看,sensor是否获得了adc电压值并成功存储进自己定义的数组里

  • 你好,

    我这边抓取了sensor在与collector通信状态下打印的数组数据,具体结果如下:

    ADC采集程序中打印的数据组数据

    Void clk0Fxn(UArg arg0)
    {
    UInt32 time;
    Smsgs_sensorMsg_t tempSensor;
    if(ADC_inint_flag == 0){
    ADC_inint_flag = 1;
    ADC_Params_init(&params);
    adc = ADC_open(Board_ADC1, &params);
    if (adc == NULL) {
    Display_printf(display, 0, 0, "Error initializing ADC0\n");
    Display_print1(display, 0, 0, "ADC_inint_flag:%d",ADC_inint_flag);
    while (1);
    }
    else{
    Display_printf(display, 0, 0, "Success initializing ADC0\n");
    //Display_print1(display, 0, 0, "ADC_inint_flag:%d",ADC_inint_flag);
    }
    }
    else{
    /* Blocking mode conversion */
    if(ADC_SAMPLE_COUNT_t != ADC_SAMPLE_COUNT){
    ADC_SAMPLE_COUNT_t++;
    res = ADC_convert(adc,&tempSensor.tempSensor.ambienceTemp[ADC_SAMPLE_COUNT_t]);
    }
    else{
    ADC_SAMPLE_COUNT_t=1;
    res = ADC_convert(adc, &tempSensor.tempSensor.ambienceTemp[ADC_SAMPLE_COUNT_t]);
    }

    if (res == ADC_STATUS_SUCCESS) {
    time = Clock_getTicks();
    // LCD_WRITE_STRING("Sample ADC Success", 2);
    //System_printf("System time in clk0Fxn = %lu\n", (ULong)time);
    LCD_WRITE_STRING_VALUE("ADC_DATA_sample:",tempSensor.tempSensor.ambienceTemp[ADC_SAMPLE_COUNT_t], 16, 5);

    此行代码打印出来的数据如图所示:

    这一部分所采集到的数据是正常的。
    }
    else {
    Display_printf(display, 0, 0, "ADC convert failed!\n");
    }
    }
    // time = Clock_getTicks();
    //System_printf("System time in clk0Fxn = %lu\n", (ULong)time);
    // Display_print1(display, 0, 0, "[%d]:ADC_DATA:%d",time);
    //ADC_close(adc);
    }

    在sensor的组帧程序中打印出来的数据确实零,具体结果如下图所示:

    static bool sendSensorMessage(ApiMac_sAddr_t *pDstAddr, Smsgs_sensorMsg_t *pMsg)
    {
    bool ret = false;
    uint8_t *pMsgBuf;
    uint16_t len = SMSGS_BASIC_SENSOR_LEN;
    //Smsgs_tempSensorField_t temp;

    /* Figure out the length */
    if(pMsg->frameControl & Smsgs_dataFields_tempSensor)
    {
    len += SMSGS_SENSOR_TEMP_LEN;
    }
    if(pMsg->frameControl & Smsgs_dataFields_lightSensor)
    {
    len += SMSGS_SENSOR_LIGHT_LEN;
    }
    if(pMsg->frameControl & Smsgs_dataFields_humiditySensor)
    {
    len += SMSGS_SENSOR_HUMIDITY_LEN;
    }
    if(pMsg->frameControl & Smsgs_dataFields_msgStats)
    {
    //len += SMSGS_SENSOR_MSG_STATS_LEN;
    len += sizeof(Smsgs_msgStatsField_t);
    }
    if(pMsg->frameControl & Smsgs_dataFields_configSettings)
    {
    len += SMSGS_SENSOR_CONFIG_SETTINGS_LEN;
    }

    pMsgBuf = (uint8_t *)Ssf_malloc(len);
    if(pMsgBuf)
    {
    uint8_t *pBuf = pMsgBuf;

    *pBuf++ = (uint8_t)Smsgs_cmdIds_sensorData;

    memcpy(pBuf, pMsg->extAddress, SMGS_SENSOR_EXTADDR_LEN);
    pBuf += SMGS_SENSOR_EXTADDR_LEN;

    pBuf = Util_bufferUint16(pBuf,pMsg->frameControl);

    /* Buffer data in order of frameControl mask, starting with LSB */
    if(pMsg->frameControl & Smsgs_dataFields_tempSensor)
    {
    for(int i=0;i<100;++i){
    pBuf = Util_bufferUint16(pBuf, pMsg->tempSensor.ambienceTemp[i]);
    LCD_WRITE_STRING_VALUE("ADC_DATA_zhuzhen:",pMsg->tempSensor.ambienceTemp[i], 16, 6);
    }
    //pBuf = Util_bufferUint16(pBuf, pMsg->tempSensor.ambienceTemp);
    //pBuf = Util_bufferUint16(pBuf, pMsg->tempSensor.objectTemp);
    }

    此部分进行ADC数据的组帧工作,我将数据进行打印,但是结果全为零,并且此处只能打印50个数据:


    if(pMsg->frameControl & Smsgs_dataFields_lightSensor)
    {
    pBuf = Util_bufferUint16(pBuf, pMsg->lightSensor.rawData);
    }
    if(pMsg->frameControl & Smsgs_dataFields_humiditySensor)
    {
    pBuf = Util_bufferUint16(pBuf, pMsg->humiditySensor.temp);
    pBuf = Util_bufferUint16(pBuf, pMsg->humiditySensor.humidity);
    }
    if(pMsg->frameControl & Smsgs_dataFields_msgStats)
    {
    pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.joinAttempts);
    pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.joinFails);
    pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.msgsAttempted);
    pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.msgsSent);
    pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.trackingRequests);
    pBuf = Util_bufferUint16(pBuf,
    pMsg->msgStats.trackingResponseAttempts);
    pBuf = Util_bufferUint16(pBuf,
    pMsg->msgStats.trackingResponseSent);
    pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.configRequests);
    pBuf = Util_bufferUint16(pBuf,
    pMsg->msgStats.configResponseAttempts);
    pBuf = Util_bufferUint16(pBuf,
    pMsg->msgStats.configResponseSent);
    pBuf = Util_bufferUint16(pBuf,
    pMsg->msgStats.channelAccessFailures);
    pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.macAckFailures);
    pBuf = Util_bufferUint16(pBuf,
    pMsg->msgStats.otherDataRequestFailures);
    pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.syncLossIndications);
    pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.rxDecryptFailures);
    pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.txEncryptFailures);
    pBuf = Util_bufferUint16(pBuf, Ssf_resetCount);
    pBuf = Util_bufferUint16(pBuf, Ssf_resetReseason);
    pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.joinTime);
    pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.interimDelay);
    pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.numBroadcastMsgRcvd);
    pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.numBroadcastMsglost);
    pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.avgE2EDelay);
    pBuf = Util_bufferUint16(pBuf, pMsg->msgStats.worstCaseE2EDelay);
    }
    if(pMsg->frameControl & Smsgs_dataFields_configSettings)
    {
    pBuf = Util_bufferUint32(pBuf,
    pMsg->configSettings.reportingInterval);
    pBuf = Util_bufferUint32(pBuf,
    pMsg->configSettings.pollingInterval);

    }

    ret = Sensor_sendMsg(Smsgs_cmdIds_sensorData, pDstAddr, true, len, pMsgBuf);
    if(ret == true){
    LCD_WRITE_STRING("Data Success Send.................", 2);
    }
    else{
    LCD_WRITE_STRING("Data Send Failed", 2);
    }

    Ssf_free(pMsgBuf);
    }

    return (ret);
    }

    我怀疑是不是我在ADC采样的未将ADC的数据缓存进我所定义的数组中,又或是我定义的数组出现问题,所以导致失败。

    希望得到你们的回复。

    非常感谢!

  • 对的,目前问题先定位到您这边设置的sensor缓存adc数据的数组这边,

    1.我看您这边不仅定义了电压值,还有温湿度以及光照度,这边的温湿度以及光照度数据按照相同的方法去操作的话,数组里有数据吗,?

    2.如果跟您这边电压值数组是相同的情况,

    tempSensor.tempSensor.ambienceTemp这个数组在不停的进行参数更新,

    建议您这边重新定义一个新的数组来进行参数的重新赋值,在之后去操作你新的缓存数组,看看新的数组是否可以出现压力值,然后使用这个数组去进行数据的交互。

  • 我看您这边不仅定义了电压值,还有温湿度以及光照度,这边的温湿度以及光照度数据按照相同的方法去操作的话,数组里有数据吗,?

    没有数据。

    如果跟您这边电压值数组是相同的情况,
    
    tempSensor.tempSensor.ambienceTemp这个数组在不停的进行参数更新,
    
    建议您这边重新定义一个新的数组来进行参数的重新赋值,在之后去操作你新的缓存数组,看看新的数组是否可以出现压力值,然后使用这个数组去进行数据的交互。

    我这边自定义了一个数组,但是还是无法解决ADC数据缓存的问题,我这边准备使用adcBuf尝试一下。

  • 那这些adc数组应该是一样的情况,这块的问题应该就是您这边adc的缓存区出现问题了

  • 我这边也会继续跟进您这边的问题,耐心等待一下 谢谢

  • 您好,您似乎正在更新clk0Fxn中的一个局部变量。您要么需要将其定义为全局变量,然后使用相同的变量进行传输。或者您需要将变量传递给transmit函数。

  • 你好,我听取您的建议,首先在程序中新定义了两个全局变量的ADC数组,将采集到的ADC数据分别存放于两个数组中,通过两个数组分时向组帧数组中传送ADC数据。现在程序可以正常工作了。

    感谢您这段时间对我这个问题的持续关注,真的十分感谢!

  • 不客气,有问题可以在论坛随时交流。