main.c 2.3 KB

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