123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- #include "main.h"
- #include "ReadKey.h"
- #include "key.h"
- #include "ReadKey.h"
- #include "crc8.h"
- #include "led.h"
- #include "eventUnit.h"
- #include "myADC.h"
- #include "myInputCapture.h"
- #include "myLcd.h"
- #include "myDisplayUnit.h"
- #include "myFlashData.h"
- #include "myTim.h"
- #include "myUart.h"
- #include "myUart3.h"
- #include "myRadio.h"
- static rfRxPacket_ts rfRecvPacket;
- static rfTxPacket_ts rfTxPacket;
- static bool rftxflag = false;
- /**
- *
- * 串口回调函数,当串口有硬件超时时会调用该函数
- */
- static void rcc_init(void)
- {
- //---------普通IO口时钟使能
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE );
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE );
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOD, ENABLE );
- //----------SPI1时钟使能
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_SPI1, ENABLE );
- //----------复用功能时钟使能
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
- #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
- /* ADCCLK = PCLK2/2 */
- RCC_ADCCLKConfig(RCC_PCLK2_Div2);
- #else
- /* ADCCLK = PCLK2/4 */
- RCC_ADCCLKConfig(RCC_PCLK2_Div4);
- #endif
- }
- /**
- *
- * 定时器中断回调,当产生定时器中断会调用该函数
- */
- void TIM3_CALLBACK(void)
- {
- static uint8_t timeCnt_1ms = 0;
- if(++timeCnt_1ms == 5)
- {
- timeCnt_1ms = 0;
- }
- }
- void rfRx_callback(uint8_t status, rfRxPacket_ts packet)
- {
- switch (status)
- {
- case RX_STA_SECCESS:
- {
- rfRecvPacket = packet;
- myRadio_receiver();
- }
- break;
- case RX_STA_TIMEOUT:
- {
- myRadio_receiver();
- }
- break;
- case RX_STA_PAYLOAD_ERROR:
- {
- myRadio_receiver();
- }
- break;
- case TX_STA_SECCESS:
- {
- myRadio_receiver();
- rftxflag = false;
- }
- break;
- default:
- break;
- }
- }
- int main(void)
- {
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
- rcc_init();
-
- GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);//关闭jtag , 开启swd
- //初始化定时器
- myTim1_init(200, TIM3_CALLBACK);
- myRadio_init(0, rfRx_callback);
- myRadio_setFrequency(433920000); //根据实际使用的模块对应的频段设置频点
- myRadio_setTxPower(12); //注意大功率模块不能设置过大,具体根据对应的模块规格书设置
- myRadio_setBaudrate(RF_BAUDRATE_1220);
- myRadio_receiver();
-
- while(1)
- {
- if (rftxflag == false)
- {
- myRadio_delay(500);
- rftxflag = true;
- rfTxPacket.len = 5;
- strcpy(rfTxPacket.payload, "hello");
- myRadio_transmit(&rfTxPacket);
- }
- myRadio_process();
- }
- }
|