CC2530片内ADC的用法
时间:10-02
整理:3721RD
点击:
谁用过CC2530片内AD?
我将AD程序写入协议栈里工作,为什么一点儿反应也没有,就像没有工作似的
帮忙找找原因
if ( events & SYS_EVENT_MSG ) //#define SYS_EVENT_MSG 0x8000 // A message is waiting event
{
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );
while ( MSGpkt )
{
switch ( MSGpkt->hdr.event )
{
// Received when a key is pressed
case KEY_CHANGE:
SampleApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
break;
// Received when a messages is received (OTA) for this endpoint
case AF_INCOMING_MSG_CMD:
SampleApp_MessageMSGCB( MSGpkt );
break;
// Received whenever the device changes state in the network
case ZDO_STATE_CHANGE:
SampleApp_NwkState = (devStates_t)(MSGpkt->hdr.status);
if ( (SampleApp_NwkState == DEV_ZB_COORD)
|| (SampleApp_NwkState == DEV_ROUTER)
|| (SampleApp_NwkState == DEV_END_DEVICE) )
{
HalLedSet( HAL_LED_1,HAL_LED_MODE_ON );
// Start sending the periodic message in a regular interval.
osal_start_timerEx( SampleApp_TaskID,
SAMPLEAPP_SEND_PERIODIC_MSG_EVT,
SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT );
}
else
{
// Device is no longer in the network
}
break;
default:
break;
}
if(IRCON > 0)
{
IRCON = 0; //清溢出标志
TempFlag++;
}
if(TempFlag == 5)//采样间隔 5s左右
{
TempFlag = 0;
for(int i=0;i<4;i++)
{
InitialAD(); //初始化ADC
if(ADCCON1&0x80)
{
adc = ADCH;
adc = adc;//---------------------------->由补码求原码
adc = adc&0x7f;
}
//if(adc&0x8000)adc = 0;
ADCCON1 = 0X30; //停止A/D
}
SampleApp_SendFlashMessage( (uint16)adc | (2<<8) );//------------------------------------------------>修改终端/路由的id号!!
}
// Release the memory
osal_msg_deallocate( (uint8 *)MSGpkt );
// Next - if one is available
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );
}
// return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
其中,AD的设置是这样的
void InitialAD(void)
{
ADCH &= 0X00; //清EOC标志
ADCCFG |= 0X80;
ADCCON3=0x87; //单次转换,参考电压为电源电压,对P07进行采样
//8位分辨率
ADCCON1 = 0X30; //停止A/D
ADCCON1 |= 0X40; //启动A/D
}
先谢谢了
我将AD程序写入协议栈里工作,为什么一点儿反应也没有,就像没有工作似的
帮忙找找原因
if ( events & SYS_EVENT_MSG ) //#define SYS_EVENT_MSG 0x8000 // A message is waiting event
{
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );
while ( MSGpkt )
{
switch ( MSGpkt->hdr.event )
{
// Received when a key is pressed
case KEY_CHANGE:
SampleApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
break;
// Received when a messages is received (OTA) for this endpoint
case AF_INCOMING_MSG_CMD:
SampleApp_MessageMSGCB( MSGpkt );
break;
// Received whenever the device changes state in the network
case ZDO_STATE_CHANGE:
SampleApp_NwkState = (devStates_t)(MSGpkt->hdr.status);
if ( (SampleApp_NwkState == DEV_ZB_COORD)
|| (SampleApp_NwkState == DEV_ROUTER)
|| (SampleApp_NwkState == DEV_END_DEVICE) )
{
HalLedSet( HAL_LED_1,HAL_LED_MODE_ON );
// Start sending the periodic message in a regular interval.
osal_start_timerEx( SampleApp_TaskID,
SAMPLEAPP_SEND_PERIODIC_MSG_EVT,
SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT );
}
else
{
// Device is no longer in the network
}
break;
default:
break;
}
if(IRCON > 0)
{
IRCON = 0; //清溢出标志
TempFlag++;
}
if(TempFlag == 5)//采样间隔 5s左右
{
TempFlag = 0;
for(int i=0;i<4;i++)
{
InitialAD(); //初始化ADC
if(ADCCON1&0x80)
{
adc = ADCH;
adc = adc;//---------------------------->由补码求原码
adc = adc&0x7f;
}
//if(adc&0x8000)adc = 0;
ADCCON1 = 0X30; //停止A/D
}
SampleApp_SendFlashMessage( (uint16)adc | (2<<8) );//------------------------------------------------>修改终端/路由的id号!!
}
// Release the memory
osal_msg_deallocate( (uint8 *)MSGpkt );
// Next - if one is available
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );
}
// return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
其中,AD的设置是这样的
void InitialAD(void)
{
ADCH &= 0X00; //清EOC标志
ADCCFG |= 0X80;
ADCCON3=0x87; //单次转换,参考电压为电源电压,对P07进行采样
//8位分辨率
ADCCON1 = 0X30; //停止A/D
ADCCON1 |= 0X40; //启动A/D
}
先谢谢了
建议楼主直接采用TI的ADC API