cc2430 pdf不能初始化

CC2430点对点使用说明_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
CC2430点对点使用说明
C​C40
阅读已结束,如果下载本文需要使用
想免费下载本文?
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢CC2430协议栈按键传递机制 -- zigbee -- 工控网博客
/tuzhuke.ashx
KEY初始化:1、void InitBoard( byte level ){
…… & & &OnboardKeyIntEnable =&HAL_KEY_INTERRUPT_DISABLE;//使用轮询方式 & &HalKeyConfig( OnboardKeyIntEnable, OnBoard_KeyCallback); &}}2、void HalKeyConfig (bool interruptEnable, halKeyCBack_t cback){#if (HAL_KEY == TRUE) &/* Enable/Disable Interrupt or */ &Hal_KeyIntEnable =&interruptE &/* Register the callback fucntion */ &pHalKeyProcessFunction =&//注册回调函数 &/* Determine if interrupt is enable or not */ &if (Hal_KeyIntEnable)//中断方式 &{ &else & &/* Interrupts NOT enabled */轮询方式 &{ & &/* & & & Work around for CC2430DB when interrupt is enabled and SW5 (center joystick) & & & is used. This SW5 uses P2 which also has debug lines connected to it. This & & & causes contant interruption on P2INT_VECTOR. Disable the usage of P2 interrupt & & & will stop this problem. & &*/ & &#if defined (HAL_BOARD_CC2430DB) & & &#define HAL_KEY_SW_5_ENABLE /* Allow SW5 only when key interrupt is disable */ & &#endif#if defined (HAL_KEY_SW_6_ENABLE) & HAL_KEY_SW_6_ICTL &= ~(HAL_KEY_SW_6_ICTLBIT);/* Clear interrupt enable bit */ & HAL_KEY_SW_6_IEN &= ~(HAL_KEY_SW_6_IENBIT);#endif#if defined (HAL_KEY_SW_5_ENABLE) &HAL_KEY_SW_5_ICTL &= ~(HAL_KEY_SW_5_ICTLBIT); /* Clear interrupt enable bit */ & &HAL_KEY_SW_5_IEN &= ~(HAL_KEY_SW_5_IENBIT);#endif & &osal_start_timerEx (Hal_TaskID, HAL_KEY_EVENT, HAL_KEY_POLLING_VALUE); & &/* Kick off polling */------开启轮询事件 &} &/* Key now is configured */ &HalKeyConfigured =&TRUE;#endif /* HAL_KEY */}3、uint16 Hal_ProcessEvent( uint8 task_id, uint16 events ){ & if (events & HAL_KEY_EVENT) &{#if (defined HAL_KEY) && (HAL_KEY == TRUE) & &/* Check for keys */ & &HalKeyPoll(); &//检测按键 & &/* if interrupt disabled, do next polling */ & &if (!Hal_KeyIntEnable) & &{ & & &osal_start_timerEx( Hal_TaskID, HAL_KEY_EVENT, 100);}#endif // HAL_KEY & &return events ^&HAL_KEY_EVENT; &}说明:该事件触发了函数HalKeyPoll()来检测是否有按键按下,并且如果按键配置为非中断,即轮询方式,会开启定时器在100ms后再次触发事件 HAL_KEY_EVENT。以此来实现按键的轮询。4、void HalKeyPoll (void){#if (HAL_KEY == TRUE) &uint8 keys =&0;//初始键值为0 &* &If interrupts are enabled, get the status of the interrupt-driven keys from 'halSaveIntKey' &* &which is updated by the key ISR. &If Polling, read these keys directly. &*/#if defined (HAL_KEY_SW_6_ENABLE) &if (!(HAL_KEY_SW_6_PORT & HAL_KEY_SW_6_BIT)) & &/* Key is active low */ &{ & &keys |= HAL_KEY_SW_6;//如果按键6被按下,则将按键6的值赋给keys &}#endif#if defined (HAL_KEY_SW_5_ENABLE) &if (HAL_KEY_SW_5_PORT & HAL_KEY_SW_5_BIT) & & & /* Key is active high */ &{ & &keys |= HAL_KEY_SW_5;//如果按键5被按下,则将按键5的值赋给keys &}#endif &/* Exit if polling and no keys have changed */ &if (!Hal_KeyIntEnable)//如果是轮询方式执行以下代码 &{ & &if (keys == halKeySavedKeys) & &{ & & & & &} & &halKeySavedKeys =& & &/* Store the current keys for comparation next time */ &} &/* Invoke Callback if new keys were depressed */ &if (keys && (pHalKeyProcessFunction)) &{ & &(pHalKeyProcessFunction) (keys, HAL_KEY_STATE_NORMAL); &}#endif /* HAL_KEY */}5、void OnBoard_KeyCallback (&uint8 keys, uint8 state ){ &uint8 &…… &shift =&(OnboardKeyIntEnable == HAL_KEY_INTERRUPT_ENABLE) ?&false :&((keys & HAL_KEY_SW_6) ?&true :&false);if (&OnBoard_SendKeys( keys, shift )&!= ZSuccess )//调用OnBoard_SendKeys将信息发送到上层 &{…… &}}6、byte OnBoard_SendKeys( byte keys, byte state ){ &keyChange_t *msgP &if (&registeredKeysTaskID != NO_TASK_ID )//这里必须要被注册 &{ & &// Send the address to the task & &msgPtr =&(keyChange_t *)osal_msg_allocate( sizeof(keyChange_t) );//分配内存空间 & &if (&msgPtr ) & &{ & & &msgPtr-&hdr.event =&KEY_CHANGE; & & &msgPtr-&state =& & & &msgPtr-&keys =& & & &osal_msg_send( registeredKeysTaskID, (uint8 *)msgPtr ); & &} & &return (&ZSuccess ); &} &else & &return (&ZFailure );}说明1)、注册,通过注册的机制实现数据在层之间的传递。在应用层: &
RegisterForKeys( SampleApp_TaskID );函数说明:byte RegisterForKeys( byte task_id ){ &// Allow only the first task &if (&registeredKeysTaskID == NO_TASK_ID )&//判断条件,确定没有被注册 &{ & &registeredKeysTaskID =&task_//将传来的ID赋给了registeredKeysTaskID
& &return (&true ); &} &else & &return (&false );}通过task_id的传递,registeredKeysTaskID已经为应用层的任务ID了,如果使用该ID可直接将任务事件发送到应用层。osal_msg_send( registeredKeysTaskID, (uint8 *)msgPtr )就是将msgPtr发送给了 registeredKeysTaskID层,即应用层。2)、消息打包: &msgPtr =&(keyChange_t *)osal_msg_allocate( sizeof(keyChange_t) );//分配内存空间 //以下为装载信息:msgPtr-&hdr.event =&KEY_CHANGE;//装载事件msgPtr-&state =&//装载状态msgPtr-&keys =&//装载键值7、byte osal_msg_send( byte destination_task, byte *msg_ptr ){ & //检查消息的有效性 &if (&msg_ptr == NULL ) & &return (&INVALID_MSG_POINTER ); &if (&destination_task &= tasksCnt ) &{ & &osal_msg_deallocate( msg_ptr ); & &return (&INVALID_TASK ); &} &// Check the message header &if (&OSAL_MSG_NEXT( msg_ptr )&!= NULL || & & & OSAL_MSG_ID( msg_ptr )&!= TASK_NO_TASK ) &{ & &osal_msg_deallocate( msg_ptr ); & &return (&INVALID_MSG_POINTER ); &}//将事件加入到系统任务队列里 &OSAL_MSG_ID( msg_ptr )&= destination_ &// queue message &osal_msg_enqueue( &osal_qHead, msg_ptr ); &// Signal the task that a&message is waiting &osal_set_event( destination_task, SYS_EVENT_MSG );//触发事件 &return (&ZSUCCESS );}说明:在最后触发了SYS_EVENT_MSG事件,其任务ID为destination_task,即SampleApp_TaskID。8、byte osal_set_event( byte task_id, UINT16 event_flag ){ &if (&task_id & tasksCnt ) &{ &halIntState_t & intS & &HAL_ENTER_CRITICAL_SECTION(intState); & &// Hold off interruptstasksEvents[task_id] |= event_ &// Stuff the event bit(s)//task_id 为SampleApp_TaskID。 & &HAL_EXIT_CRITICAL_SECTION(intState); & & // Release interrupts &} & else & &return (&INVALID_TASK ); &return (&ZSUCCESS );}9、void osal_start_system( void ){ &for(;;) & &{ & &uint8 idx =&0; & &Hal_ProcessPoll(); &// This replaces MT_SerialPoll() and osal_check_timer(). & &do { & & &if (tasksEvents[idx]) &// Task is highest priority that is ready. & & &{ & & & & & & &} & &} while (++idx & tasksCnt);//tasksEvents[task_id] |= event_使得跳出循环 & &if (idx & tasksCnt) & &{ & & &uint16 & & &halIntState_t intS & & &HAL_ENTER_CRITICAL_SECTION(intState); & & &events =&tasksEvents[idx];//提取事件 & & &tasksEvents[idx] =&0; &// Clear the Events for this task. & & &HAL_EXIT_CRITICAL_SECTION(intState); & & &events =&(tasksArr[idx])( idx, events );//调用处理函数进行处理 & & &HAL_ENTER_CRITICAL_SECTION(intState); & & &tasksEvents[idx] |= &// Add back unprocessed events to the current task. & & &HAL_EXIT_CRITICAL_SECTION(intState); & & &} & &}}10、uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events ){ &afIncomingMSGPacket_t *MSG &if (&events & SYS_EVENT_MSG ) &{ & &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 ); & & & & &……}消息解包过程,队列中读取MSGpkt消息,然后检测其event,我们打包按键是event为KEY_CHANGE。所以在switch语句中最终会之心函数SampleApp_HandleKeys().。同时将MSG的state和keys传递到函数中,即我们打包时按键的状态和按键的数值。11、void SampleApp_HandleKeys( uint8 shift, uint8 keys ){ &if (&keys & HAL_KEY_SW_1 )//如果按键值keys&HAL_KEY_SW_1 为1,执行以下代码 &{ &
& &SampleApp_SendFlashMessage( SAMPLEAPP_FLASH_DURATION ); &} &if (&keys & HAL_KEY_SW_2 )//如果按键值keys&HAL_KEY_SW_2 为1,执行以下代码 &{ & &aps_Group_t * & &grp =&aps_FindGroup( SAMPLEAPP_ENDPOINT, SAMPLEAPP_FLASH_GROUP ); & &if (&grp ) & &{ & & &// Remove from the group & & &aps_RemoveGroup( SAMPLEAPP_ENDPOINT, SAMPLEAPP_FLASH_GROUP ); & &} & &else & &{ & & &// Add to the flash group & & &aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group ); & &} &}}热门版块:
CC2430驱动DS18b20和运行Z-stack的问题,成功解决,分享经验!
& && & 前几天在做一个基于ZigBee的医疗无线监护系统,采用TIcc2430的芯片和DS18b20温度传感器,Z-stack协议栈。在用测温节点采集DS18b20的数据时,遇到如下问题,程序总是停在DS18b20的驱动程序里的这一句:
while(IN_DQ)&&{;}//等待回复
#define IN_DQ&&P0_0
& && & 说明传感器的DQ引脚总是输出高电平,所以无法完成传感器的初始化,导致后面的测温、无线发送程序无法运行。传感器应该是好的,驱动也是网上流传甚广,经过认证的。而且我以前成功过。试了很多方法都没能解决。
& && & 这个问题也直接导致了第二个问题,即数据收集显示节点因为无法接收到采集节点的数据信息而无法进入数据处理程序,即Z-stack总在osal_start_system()这个操作系统函数里循环,即下面的函数段
& && &if (tasksEvents[idx])&&// Task is highest priority that is ready.
& & } while (++idx & tasksCnt);
其中tasksEvents[idx]总为0,说明没有事件触发消息传递到tasksEvents[idx]中来,程序检测不到事件的发生,无法运行任务处理函数。
& && & 经过艰苦调试,终于找到了解决的方法,或者说是碰到了,呵呵
。过程如下:
①DS18b20无法完成初始化:
& &这个问题出自驱动程序中初始化函数
void init_1820(void)
& &//cli();
&&//P0SEL&=0//将P0.0口设置为普通IO口
&&SET_OUT;
&&SET_DQ;//输出1
&&Delay_nus(700);//拉低一段时间
&&SET_DQ;//释放
&&SET_IN;//输入
&&Delay_nus(40); //释放总线后等待15-60us
while(IN_DQ);//等待回复
&&Delay_nus(240);//回复的低电平在60到240us&&
&&SET_OUT;
&&SET_DQ;//回到初始DQ=1;
中的while(IN_DQ);,经检测,IN_DQ的输出总是1,即程序无法得到完成初始化所需的IN_DQ低电平信号,故而卡在这个无限满足的死循环里。
首先感谢kennan前辈的回答,原先我也以为是时序问题,但是了很多不同的延时时间,但都无效。又以为是DS18b20坏了,但换了几个都是这样,于是也排除这种可能。
& && &最后,我用IAR的断点设置功能,在while(IN_DQ);这句上设置断点,当程序运行这一句之前,我把DS18b20的DQ引脚从连接的P0.0口上拔下来,插到GND引脚上,也就是人为的制造一个低电平,嘻嘻。效果还不错,程序终于越过这一句,成功运行下去了!而且后面循环执行初始化函数时也没有再卡在这一句上。虽然不能解释为什么,但我灵机一动,把while(IN_DQ);这句之前的读写操作改成循环语句,即将原函数修改如下:
&&void init_1820(void)
& &//cli();
&&//P0SEL&=0//将P0.0口设置为普通IO口
&&SET_OUT;
&&SET_DQ;//输出1
&&Delay_nus(700);//拉低一段时间
&&SET_DQ;//释放
&&SET_IN;//输入
&&Delay_nus(40); //释放总线后等待15-60us
&&} while(IN_DQ);//等待回复
&&Delay_nus(240);//回复的低电平在60到240us&&
&&SET_OUT;
&&SET_DQ;//回到初始DQ=1;
此后,程序就再也没有卡过了。但是,到现在我也不知道自己为什么要这样改,只是一时的灵感而已···
不过,后来在运行时,又遇到一个问题,读出的第一个数据总是85℃,也就是DS18b20以12位精度初始化时输出的数据。经过仔细排查,发现是读数据函数中:
unsigned int read_data_value(void)
& & unsigned char temh,
//& & unsigned char a,b,c;
//& & unsigned int data_
& & init_1820();&&//复位18b20&&
& & write_1820(0xcc);& &// 发出转换命令 搜索器件
& & write_);& &&&//启动
& & for(j=20;j&1;j--)&&
& & Delay_nus(500);
& & init_1820();&&
& & write_1820(0xcc);
& & //match_rom(serial);& &//匹配
& & write_1820(0xbe);
& & teml=read_1820();&&//读数据&&
& & temh=read_1820();&&
& && &if(temh&0x80)//判断正负
& && &flag=1;
& && &flag=0;& &//为正
& & sensor_data_value[0]=
& & sensor_data_value[1]=
& & data_value =
& & data_value = ( data_value && 8 )|
& & return data_
的for(j=20;j&1;j--)&&
& & Delay_nus(500);一句被注释掉了,导致该错误。去掉注释后就一切正常了。
②协议栈无法运行
呵呵,其实第一个问题解决了,这个问题也就迎刃而解了,因为测温节点成功读取数据后就可以发送无线数据给显示节点,显示节点就获得了进入任务处理的激发信号,因此程序也就顺利运行,成功地在液晶屏上显示出温度数值了,呵呵。
以上就是本人针对这两个问题的一点经验,拿来与大家分享,献丑了,呵呵
您好,您能不能把您的关于TIcc2430的芯片和DS18b20温度传感器的程序资料给我发一份啊,谢谢啦。邮箱:
经验之谈最有价值
您好,您能不能把您的关于TIcc2430的芯片和DS18b20温度传感器的程序资料给我发一份啊,谢谢啦。
您好,您能不能把您的关于TIcc2430的芯片和DS18b20温度传感器的程序资料给我发一份啊,谢谢啦。
站长推荐 /5
Powered bycc2430外部中断_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
cc2430外部中断
c​c40​单​片​机​外​部​中​断​程​序​与​说​明
阅读已结束,如果下载本文需要使用
想免费下载本文?
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢CC2430讲解1_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
CC2430讲解1
C​C40​讲​解
阅读已结束,如果下载本文需要使用
想免费下载本文?
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢

我要回帖

更多关于 cc2430 pdf 的文章

 

随机推荐