f8wConfig.cfg file
Select channel and set PAN ID
Select channel
#define DEFAULT_CHANLIST 0x00000800
DEFAULT_CHANLIST
Indicates the network where the Zigbee module is to work. When there are multiple channel parameter values or operations, the result is used as DEFAULT_CHANLIST
the value.
Meaning for routers, terminals, and coordinators:
- Routers and terminals:
- I can choose the best network for me on the channels I participate in or operate on, and join it.
- Coordinator
- You can choose an optimal channel among these channels to participate or operate and create your own Zigbee network on this channel
Select PAN ID
-
Not 0xFFFF
- Routers and terminals: must be added to a Zigbee wireless LAN with PANID as the parameter value
- Coordinator: To create a network, and use this parameter value as the PANED of this network
-
is 0xFFFF
- Routers and terminals: There is no PANID restriction when joining the network
- Coordinator: can randomly generate a value and use this random value as the PANED of this network
When 2 modules download the same coordinator code and the specified PANID parameter value is non-0xffff,
The module powered on first can create a Zigbee network like 0xFFF8, and the module powered on later can create a network based on 0xFFF8 plus 1.
Respond to task events
Hardware layer: hardware operation related
Network layer: network-related code
Application layer: write the application part yourself
- Almost every layer is a task. The system assigns a one-byte unique numerical number to each task. Each task can handle some things they can handle.
- Task ID: This numerical number is called
- Event: something they can handle
/*
*task_id:任务ID
*event_flag:任务事件
*/
uint8 osal_set_event( uint8 task_id, uint16 event_flag )
Test in project
- In
TestAPP.c
the file, findUINT16 TestAPP_ProcessEvent( byte task_id, UINT16 events )
the function - Add the following statements under the test code for the three modes written previously
osal_set_event(TestAPP_TaskID,TestAPP_SEND_MSG_EVT);
- Search down in the function, see
TestAPP_SEND_MSG_EVT
the response code to the event, and proceed as follows:
P0DIR |= 0X02;
P0_1 = 0;
- Break the point before the
P0DIR语句前
andLS164_BYTE(11)
statement, then compile it under the router project, then burn the code, download it and execute it at full speed and single-step debugging - Experimental phenomenon: jump to
TestAPP_SEND_MSG_EVT
the response code of the event, LED2 lights up
Software timer response event
/*
*taskID:任务ID
*event_id:任务事件
*timeout_value:超时时间(毫秒),多长时间处理一次
*/
uint8 osal_start_timerEx( uint8 taskID, uint16 event_id, uint16 timeout_value )
Experimental verification
osal_start_timerEx(TestAPP_TaskID,TestAPP_SEND_MSG_EVT,2000);
osal_set_event
Comment out the function you just wroteosal_start_timerEx
and write the function below
- Compile and download, observe experimental phenomena
- Lights up after a delay of 2 seconds
Define events
The format is
#define 事件名 0x000?
? It can be a hexadecimal number and can define up to 16 times 0 ~ FMust ensure 3 0's, the position is arbitrary
Experimental verification
- In
TestAPP.h
the file, define the event
The format is #define event name 0x000? ? can be a hexadecimal number, and can define up to 16 times 0 ~ F
Must ensure 3 0's, the position is arbitrary
//格式为 #define 事件名 0x000? ?可以是十六进制的数,最多定义16个时间 0 ~ F
//必须保证3个0,位置随意
#define TestAPP_EVT 0x0002
- as follows
- In
TestAPP.c
the file, find the function just nowUINT16 TestAPP_ProcessEvent( byte task_id, UINT16 events )
, and under the last event response code, add a new event response code
if ( events & TestAPP_EVT ){
//初始化要全面,因为使用的是TI官方代码移植的,他官方例程中可能也配置了这个IO口,我们在这里重新配置的时候必须要全面配置,否则这个IO口可能默认不是通用IO
P0SEL &=0XEF;//1110 1111
P0DIR |= 0X10;
P0_4 = 0;
return (events ^ TestAPP_EVT);
}
- Add the response event function for this event
- Compile, download, light on
The initialization must be comprehensive, because it is transplanted from TI's official code, and this IO port may also be configured in its official routines. When we reconfigure here, we must fully configure it, otherwise this IO port may not be general IO by default.
information
In ZSTACK, the characteristics of task event definition determine that each task can only handle up to 16 different events, and the system has many transactions to process when running. If each physical processing is defined as an event, then 16 There are definitely not enough events to introduce all messages.
The principle of message processing transaction:
An event is defined #define SYS_EVENT_MSG 0x8000 // A message is waiting event.
When an application layer task is required to process a transaction, first send a message to the application layer task
osal_set_event(SDApp_TaskID,SYS_EVENT_MSG) ;
Then, the application layer will enter SYS_EVENT_MSG processing. In this event processing, it will be judged which type of message just caused us to generate the SYS_EVENT_MSG event, and then the corresponding processing will be done according to the type of the message.
The type of message can be defined by oneself. In this way, there can be many types of messages, so the application layer tasks can handle many types of things.
Experimental verification
- Clear all contents under the function
TestAPP.c
in the filevoid TestAPP_HandleKeys( byte shift, byte keys )
, and then call the digital tube display function
- Called before
TestAPP_ProcessEvent
the function is commented outosal_start_timerEx
, add the following function below
// 定义一个名为keyChange_t的结构体指针msgPtr
keyChange_t *msgPtr;
//定义按键响应消息
msgPtr = (keyChange_t *)osal_msg_allocate( sizeof(keyChange_t) );
if ( msgPtr ){
// 将消息头部的事件设置为KEY_CHANGE
msgPtr->hdr.event = KEY_CHANGE;
// 将键值设置为3
msgPtr->keys=3;
//将发送给TestAPP_TaskID任务的消息压入消息队列,并响应系统事件osal_set_event(TestAPP_TaskID,SYS_EVENT_MSG);
osal_msg_send( TestAPP_TaskID, (uint8 *)msgPtr );
}
- Compile, download, the digital tube displays the key numbers, and the expression is correct.
Button experiment (protocol stack implementation)
- Add the encapsulated code to the project
Key.c
Change the file name and event name inside according to your actual situation.
#include<iocc2530.h>
#include "TestApp.h"
#include "OSAL_Timers.h"
extern unsigned char TestAPP_TaskID;
void delay()
{
int i,j;
for(i=0;i<1000;i++)
for(j=0;j<30;j++);
}
void KeysIntCfg()
{
//Key3 Key4 Key5
P1SEL &=~0X02;
P1DIR &=~0X02;
IEN2|=0x10;//开P1IE组中断
P1IEN|=0x02;//开Key3组内中断
PICTL|=0x02;//设置P1_1为下降沿
P2SEL &=~0X01;
P2DIR &=~0X01;
IEN2|=0x02;
P2IEN|=0x01;
PICTL|=0x08;//设置P2_0为下降沿
P0SEL &=~0X20;
P0DIR &=~0X20;
P0IE=1;//或者写成 IEN1|=0x20
P0IEN|=0x20;
PICTL|=0x01;//设置P0_5为下降沿
EA=1; //开总中断
}
#pragma vector=P1INT_VECTOR
__interrupt void Key3_ISR() //P1_1
{
if(P1IFG & 0X02)
{
osal_start_timerEx(TestAPP_TaskID,TestAPP_EVT,25);
}
P1IFG =0;
P1IF=0;
}
#pragma vector=P2INT_VECTOR
__interrupt void Key4_ISR()//P2_0
{
if(P2IFG & 0X01)
{
osal_start_timerEx(TestAPP_TaskID,TestAPP_EVT,25);
}
P2IFG =0;
P2IF=0;
}
#pragma vector=P0INT_VECTOR
__interrupt void Key5_ISR()//P0_5
{
if(P0IFG & 0X20)
{
osal_start_timerEx(TestAPP_TaskID,TestAPP_EVT,25);
}
P0IFG =0;
P0IF=0;
}
Key.h
#ifndef KEY_H
#define KEY_H
void KeysIntCfg();
#endif
- Reference header file, initialization. [The initialization function must be placed
osal_start_system();
before]
- Shield the interrupt function in the official routine. [hal-target-CC2530EB-drivers]
HAL_ISR_FUNCTION( halKeyPort2Isr, P2INT_VECTOR )
andHAL_ISR_FUNCTION( halKeyPort0Isr, P0INT_VECTOR )
- Modify the
TestAPP.c
previously definedTestAPP_EVT
event response in the file as follows
if ( events & TestAPP_EVT ){
P0SEL &=0XEF;//1110 1111
P0DIR |= 0X10;
P0_4 ^= 1;
if(0==P1_1){
/*按钮3按下*/LS164_BYTE(3);}
if(0==P2_0){
/*按钮4按下*/LS164_BYTE(4);}
if(0==P0_5){
/*按钮5按下*/LS164_BYTE(5);}
return (events ^ TestAPP_EVT);
}
- Download, experimental phenomenon: when the button is pressed, the light turns on and off alternately, and the digital tube displays the button number.
Note on using protocol stack to generate hex file
-
Configure the project project to generate hex. I have previously mentioned how to set it up in the generated project.
-
In
f8w2530.xc
the file, uncomment the following two lines