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(¶ms);
adc = ADC_open(Board_ADC1, ¶ms);
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);
}
期待收到您们的回复,谢谢!