这里有个基于smac发包的PROJECT,达人能否帮忙看下。这样在MC13213开发板上能否实现发包功能。
好像不能上传文件,那就发下我的主程序,劳烦大虾看下。
void main(void) {tRxPacket rx_packet; //SMAC structure for RX packets tTxPacket tx_packet; //SMAC structure for TX packets
byte rx_data_buffer[20]; //Data buffer to hold RX data, if you want larger packets change 20 to what you need. byte tx_data_buffer[20]; //Data buffer to hold TX data, if you want larger packets change 20 to what you need.
UINT16 packet_count; //Initialize the packet. tx_packet.u8DataLength = 0; //Set TX default to 0 tx_packet.pu8Data = &tx_data_buffer[0]; //Load the address of our txbuffer into tx structure.
rx_packet.u8DataLength = 0; //Set RX default to 0 rx_packet.pu8Data = &rx_data_buffer[0]; //Load the address of our rxbuffer into rx structure rx_packet.u8MaxDataLength = 100; //Define the max buffer we are interested in. rx_packet.u8Status = 0; //initialize the status packet to 0.
MCUInit(); //Initialize the mcu, setup GPIOs, SPI, clock scheme, etc. RadioInit(); app_init(); MLMESetMC13192ClockRate(0); /* Set initial Clk speed from MC13192s CLKO*/ UseExternalClock(); /* switch clock sources to EXTERNAL clock */ /* include your start up code here */ EnableInterrupts; /* Turn on system interrupts */ MLMESetChannelRequest(0); //Set channel zero, can be changed to users preference MLMEMC13192PAOutputAdjust(NOMINAL_POWER); //Set Nominal power setting app_status = INITIAL_STATE; //Set the initial app_status of the application state variable to INITIAL_STATE //Loop forever for (;;) {
switch (app_status) { case INITIAL_STATE: //For TX app_status = IDLE_STATE; //Switch app status to TX_STATE for (i=0; i<18; i++) { tx_data_buffer = i; } tx_packet.u8DataLength = 18; //Set the data length of the packet. in this case, 6. packet_count=0; break; case TX_STATE: //Load the tx buffer with the ZigBee packet. if (MCPSDataRequest(&tx_packet) == SUCCESS) //TX Packet, Blocking will stay here until the packet is in the air LED1 ^=1; //MLME_RX_enable_request
(&rx_packet,DELAY_COUNT); //Now turn on the RX with a timeout of DELAY_COUNT if (packet_count < 999) app_status = DELAY_STATE ; //Set app_status as waiting for ack. else app_status = FINAL_STATE; packet_count++; break; case RX_STATE: MLMERXEnableRequest(&rx_packet,0); //Zero means wait forever with RX ON. break; case RESET_STATE: //MC13192 Reset, reinitialize and return to default state (TX_STATE). RadioInit(); app_status = INITIAL_STATE; break; case RECEIVER_ALWAYS_ON: break; case WAITING_FOR_ACK: break; case SET_LEDS: /* This state takes the power value from the ack and turns on the appropriate LEDs */ LED1 ^= 1; /* Toggle LED1 whenever an ack is received. (blinks LED1) */ LED2 = LED_OFF; LED3 = LED_OFF; LED4 = LED_OFF; app_status = DELAY_STATE; //Take the app state and wait for some time to retransmit. break; case DELAY_STATE: //Sets the TX rate, small DELAY_COUNT means TX rate is fast while larger values slow it down. app_status = TX_STATE; //After the delay, retransmit break; case IDLE_STATE: break; case FINAL_STATE: tx_packet.pu8Data[0] = 'D'; tx_packet.pu8Data[1] = 'O'; tx_packet.pu8Data[2] = 'N'; tx_packet.pu8Data[3] = 'E'; tx_packet.pu8Data[4] = 'D'; tx_packet.pu8Data[5] = 'O'; tx_packet.pu8Data[6] = 'N'; tx_packet.pu8Data[7] = 'E'; tx_packet.pu8Data[8] = '\0'; tx_packet.u8DataLength = 9; for (i=0; i<20; i++) { for (loop = 0; loop < DELAY_COUNT; loop++); MCPSDataRequest(&tx_packet); app_status = FINAL_STATE; } LED1 = LED_OFF; app_status = IDLE_STATE; default: break; }
} }
[此贴子已经被作者于2007-5-21 15:53:50编辑过] |