main.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include "main.h"
  2. #include "ReadKey.h"
  3. #include "key.h"
  4. #include "ReadKey.h"
  5. #include "crc8.h"
  6. #include "led.h"
  7. #include "eventUnit.h"
  8. #include "myADC.h"
  9. #include "myInputCapture.h"
  10. #include "myLcd.h"
  11. #include "myDisplayUnit.h"
  12. #include "myFlashData.h"
  13. #include "myTim.h"
  14. #include "myUart.h"
  15. #include "myUart3.h"
  16. #include "myRadio.h"
  17. static rfRxPacket_ts rfRecvPacket;
  18. static rfTxPacket_ts rfTxPacket;
  19. static bool rftxflag = false;
  20. static void rcc_init(void)
  21. {
  22. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  23. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  24. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
  25. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
  26. RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
  27. RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
  28. #if defined(STM32F10X_LD_VL) || defined(STM32F10X_MD_VL) || defined(STM32F10X_HD_VL)
  29. /* ADCCLK = PCLK2/2 */
  30. RCC_ADCCLKConfig(RCC_PCLK2_Div2);
  31. #else
  32. /* ADCCLK = PCLK2/4 */
  33. RCC_ADCCLKConfig(RCC_PCLK2_Div4);
  34. #endif
  35. }
  36. void TIM3_CALLBACK(void)
  37. {
  38. static uint8_t timeCnt_1ms = 0;
  39. if( ++timeCnt_1ms == 5)
  40. {
  41. timeCnt_1ms = 0;
  42. }
  43. }
  44. void rfRx_callback(uint8_t status, rfRxPacket_ts packet)
  45. {
  46. switch (status)
  47. {
  48. case RX_STA_SECCESS:
  49. {
  50. rfRecvPacket = packet;
  51. myRadio_receiver();
  52. }
  53. break;
  54. case RX_STA_TIMEOUT:
  55. {
  56. myRadio_receiver();
  57. }
  58. break;
  59. case RX_STA_PAYLOAD_ERROR:
  60. {
  61. myRadio_receiver();
  62. }
  63. break;
  64. case TX_STA_SECCESS:
  65. {
  66. myRadio_receiver();
  67. rftxflag = false;
  68. }
  69. break;
  70. default:
  71. break;
  72. }
  73. }
  74. int main(void)
  75. {
  76. rcc_init();
  77. GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); //
  78. myTim1_init(200, TIM3_CALLBACK);
  79. myRadio_init(0, rfRx_callback);
  80. myRadio_setFrequency(433920000);
  81. myRadio_setTxPower(20);
  82. myRadio_receiver();
  83. while(1)
  84. {
  85. if (rftxflag == false)
  86. {
  87. myRadio_delay(500);
  88. rftxflag = true;
  89. rfTxPacket.len = 5;
  90. strcpy(rfTxPacket.payload, "hello");
  91. myRadio_transmit(&rfTxPacket);
  92. }
  93. myRadio_process();
  94. }
  95. }