单片机源程序如下:
- #include "stm8s.h"
- #include "data_base.h"
- #include "radio.h"
- #include "si446x_cmd.h"
- #include "gpio.h"
- #include "delay.h"
- #include "user.h"
-
- uint8_t bRadio_Process();
-
- U8 bMain_IT_Status;
- uint8_t RFstate;
- extern uint8_t tx_data[];
- extern volatile uint16_t tick_timer;
- #define EnableMaster 0
- /*
- Demo程序流程:Master EnableMaster=1,发送tx_data数据包后等待接收端ack数据包,若500ms后未接收到ack数据包超时处理,若接收到ack数据包LED闪烁指示
- Slaver EnableMaster=0,接收到tx_data数据包后发送ack数据包,发送完成后LED灯闪烁指示
- */
- void main(void)
- {
- vInitializeHW();// Initialize the Hardware and Radio
- #if EnableMaster
- RFstate=RFLR_STATE_TX_INIT;
- #else
- RFstate=RFLR_STATE_RX_INIT;
- #endif
- while(1)
- {
- bRadio_Process();
- }
- }
- uint8_t bRadio_Process()
- {
- switch(RFstate)
- {
- case RFLR_STATE_RX_INIT://接收初始化
-
- GPIO_WriteLow(SI4463_TX_PORT,SI4463_TX_IO);
- GPIO_WriteHigh(SI4463_RX_PORT,SI4463_RX_IO);//开关切换到接收通路
- vRadio_StartRX(pRadioConfiguration->Radio_ChannelNumber, 0);
- tick_timer=0;
- RFstate=RFLR_STATE_RX_RUNNING;
- break;
-
- case RFLR_STATE_RX_RUNNING://接收处理
- bMain_IT_Status = bRadio_Check_Tx_RX();
- if(bMain_IT_Status==SI446X_CMD_GET_INT_STATUS_REP_PH_PEND_PACKET_RX_PEND_BIT)
- {
- if(EnableMaster)
- {
- RFstate=RFLR_STATE_RX_ACK_DONE;
- }
- else
- {
- RFstate=RFLR_STATE_RX_DONE;
- }
- }
- if(tick_timer>500)
- {
- RFstate=RFLR_STATE_RX_TIMEOUT;
- }
-
- break;
-
- case RFLR_STATE_TX_INIT://发射客户数据包初始化
- GPIO_WriteHigh(SI4463_TX_PORT,SI4463_TX_IO);
- GPIO_WriteLow(SI4463_RX_PORT,SI4463_RX_IO);//开关切换到发送通路
- gSampleCode_SendVariablePacket();//打包发送客户数据包
- tick_timer=0;
- RFstate=RFLR_STATE_TX_RUNNING;
- break;
-
-
- case RFLR_STATE_TX_ACK_INIT://发射ack数据包初始化
- GPIO_WriteHigh(SI4463_TX_PORT,SI4463_TX_IO);
- GPIO_WriteLow(SI4463_RX_PORT,SI4463_RX_IO);//开关切换到发送通路
- vSampleCode_SendAcknowledge();//打包发送ACK数据包
- tick_timer=0;
- RFstate=RFLR_STATE_TX_RUNNING;
- break;
-
-
- case RFLR_STATE_TX_RUNNING://发射处理
- bMain_IT_Status = bRadio_Check_Tx_RX();
- if(bMain_IT_Status==SI446X_CMD_GET_INT_STATUS_REP_PH_PEND_PACKET_SENT_PEND_BIT)
- {
- if(EnableMaster)
- {
- RFstate=RFLR_STATE_TX_DONE;
- }
- else
- {
- RFstate=RFLR_STATE_TX_ACK_DONE;
- }
- }
- if(tick_timer>500)
- {
- RFstate=RFLR_STATE_TX_TIMEOUT;
- }
- break;
-
-
- case RFLR_STATE_RX_DONE://接收客户数据包完成
-
- if(gSampleCode_StringCompare(customRadioPacket, tx_data,20)==TRUE)
- {
- RFstate=RFLR_STATE_TX_ACK_INIT;//收到正确数据包后发射ack数据包
- }
- else
- {
- RFstate=RFLR_STATE_RX_INIT;
- }
- break;
-
- case RFLR_STATE_RX_ACK_DONE://接收ack数据包完成
-
- if(gSampleCode_StringCompare(customRadioPacket, "ACK",3)==TRUE)
- {
- GPIO_WriteLow(RF_LED1_PORT,RF_LED1_IO);//LED指示灯闪烁
- m928_delay(20);
- GPIO_WriteHigh(RF_LED1_PORT,RF_LED1_IO);
- }
-
- m928_delay(100);
- RFstate=RFLR_STATE_TX_INIT;
- break;
-
- case RFLR_STATE_TX_DONE://发射完客户数据包
-
- RFstate=RFLR_STATE_RX_INIT;
- break;
-
- case RFLR_STATE_TX_ACK_DONE://发射完ack数据包
-
- GPIO_WriteLow(RF_LED1_PORT,RF_LED1_IO);//LED灯闪烁
- m928_delay(20);
- GPIO_WriteHigh(RF_LED1_PORT,RF_LED1_IO);
-
- RFstate=RFLR_STATE_RX_INIT;
-
- break;
-
- case RFLR_STATE_TX_TIMEOUT://发射超时
-
- if(EnableMaster)
- {
- RFstate=RFLR_STATE_TX_INIT;
- }
- else
- {
- RFstate=RFLR_STATE_RX_INIT;
- }
- break;
-
- case RFLR_STATE_RX_TIMEOUT://接收超时
-
- if(EnableMaster)
- {
- RFstate=RFLR_STATE_TX_INIT;
- }
- else
- {
- RFstate=RFLR_STATE_RX_INIT;
- }
- break;
-
- default:break;
- }
- return RFstate;
- }
复制代码
所有资料51hei提供下载:
SI4438 Directional 硬件spi STM8S105 IAR.rar
(10.74 MB, 下载次数: 34)
|