1. At first, we really need to use official templates, add simple codes, make basic communication transceiver experiments, and build perceptual knowledge.
2. Then, on the basis of the basic experiment of official code, we understand the relevant concepts, grasp the principle of communication process, and do a personalized experiment to verify our understanding.
unicast
In Zigbee network, communication between modules is needed. The transmitting module knows the network address of the receiving module very clearly, and sends data to the receiving module with this address, which is called unicast.
The address characteristics of Zigbee module:
When the module enters the network, the parent node randomly assigns the network address to the child node. But the address of the coordinator module in the network is always 0x0000.
In the same project, tabs control the compilation details of different files! Copy SimonAPP.c file as Enddevice.c file, then select different tabs, set the option of the file, and use Exclude from build option to set whether a file participates in compilation under a tab!!!
Send a single character
Sending Module-Terminal Node
In the Enddevice.c file SimonApp_MY_EVT event processing button 1 press the relevant processing code:
if ( events & SimonApp_MY_EVT )
{
if(0==P1_1)
{//Press button 3
LS164_BYTE(3);
char theMessageData[] ={8};
SimonApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
SimonApp_DstAddr.addr.shortAddr = 0x0000;
// Take the first endpoint, Can be changed to search through endpoints
SimonApp_DstAddr.endPoint =SimonApp_ENDPOINT ;
AF_DataRequest( &SimonApp_DstAddr, &SimonApp_epDesc,
SimonApp_CLUSTERID,
1,//(byte)osal_strlen( theMessageData ) + 1,
(byte *)&theMessageData,
&SimonApp_TransID,
AF_DISCV_ROUTE, AF_DEFAULT_RADIUS );
P1SEL &=0Xfe;// Flip LED
P1DIR |=0X01;
P1_0 ^=1;
}
if(0==P2_0)
{//Press button 4
LS164_BYTE(4);
}
if(0==P0_5)
{//Press button 5
LS164_BYTE(5);
}
return (events ^ SimonApp_MY_EVT);
}
Receiving Module-Coordinator
When the terminal module sends data, the underlying task of the coordinator module gets the wireless data and sends an AF_INCOMING_MSG_CMD to our application task in message processing. We take out the useful data and display it on the digital tube.
In Simon APP.c:
void SimonApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )
{
switch ( pkt->clusterId )
{
case SimonApp_CLUSTERID:
// "the" message
#if defined( LCD_SUPPORTED )
HalLcdWriteScreen( (char*)pkt->cmd.Data, "rcvd" );
#elif defined( WIN32 )
WPRINTSTR( pkt->cmd.Data );
#endif
LS164_BYTE(pkt->cmd.Data[0]);
break;
}
}
Send string
Sending module
In the Enddevice.c file SimonApp_MY_EVT event processing button 1 press the relevant processing code:
if ( events & SimonApp_MY_EVT )
{
if(0==P1_1)
{//Press button 3
LS164_BYTE(3);
char theMessageData[] ="Hello Simon";
SimonApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
SimonApp_DstAddr.addr.shortAddr = 0x0000;
// Take the first endpoint, Can be changed to search through endpoints
SimonApp_DstAddr.endPoint =SimonApp_ENDPOINT ;
AF_DataRequest( &SimonApp_DstAddr, &SimonApp_epDesc,
SimonApp_CLUSTERID,
(byte)osal_strlen( theMessageData ) + 1,
(byte *)&theMessageData,
&SimonApp_TransID,
AF_DISCV_ROUTE, AF_DEFAULT_RADIUS );
P1SEL &=0Xfe;// Flip LED
P1DIR |=0X01;
P1_0 ^=1;
}
if(0==P2_0)
{//Press button 4
LS164_BYTE(4);
}
if(0==P0_5)
{//Press button 5
LS164_BYTE(5);
}
return (events ^ SimonApp_MY_EVT);
}
Receiving module
1. To receive strings, transplant serial modular files, add UART.C UART.h header files to the project source file directory!!!
2. The main of ZMain.c file is close to module void InitUart(); initialize serial port!!!
3. Cancel TI's default configuration of serial port, find HalDriverInit function in main function, and modify the macro definition through this function:
define HAL_UART FALSE
4. In ZMain, the initial calculation of adding UART.h header file to C is completed.
5. Add in SimonApp_MessageMSGCB function:
Uart_Send_String(pkt->cmd.Data,pkt->cmd.DataLength);
Remember to add UART.h header file to SDAP.c file