main.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /************************************************************************************************/
  2. /**
  3. * @file main.c
  4. * @author MCU Ecosystem Development Team
  5. * @brief 该示例展示的SN模块用法。
  6. *
  7. *
  8. **************************************************************************************************
  9. * @attention
  10. * Copyright (c) CEC Huada Electronic Design Co.,Ltd. All rights reserved.
  11. *
  12. **************************************************************************************************
  13. */
  14. /*------------------------------------------includes--------------------------------------------*/
  15. #include "main.h"
  16. #include "common.h"
  17. #include "SN_GPIO.h"
  18. #include "SN_ADC.h"
  19. #include "SN_PWM.h"
  20. #include "SN_EXIT.h"
  21. #include "SN_TIM3_INIT.h"
  22. #include "SN_TIM1_INIT.h"
  23. #include "SN_UART.h"
  24. #include "SN_FLASH.h"
  25. #include "SN_RCC.h"
  26. #include "SN_SPI.h"
  27. #include "SN_DDQ.h"
  28. #include "i2c_bsp.h"
  29. #include "SN_STOP.h"
  30. #include <stdio.h>
  31. #include "myRadio.h"
  32. /*------------------------------------------functions-------------------------------------------*/
  33. uint16_t ADC_VAL = 0;
  34. float MCU_VDD = 0;
  35. void rfRx_callback(uint8_t status, rfRxPacket_ts packet)
  36. {
  37. printf("status:%d\r\n", status);
  38. switch (status)
  39. {
  40. case RX_STA_SECCESS:
  41. {
  42. printf("receive data:%s\r\n", packet.payload);
  43. // RF_StopCad();
  44. // myRadio_receiver();
  45. // myRadio_restartCadReceiver();
  46. }
  47. break;
  48. case RX_STA_TIMEOUT:
  49. {
  50. // myRadio_receiver();
  51. myRadio_restartCadReceiver();
  52. }
  53. break;
  54. case RX_STA_PAYLOAD_ERROR:
  55. {
  56. // myRadio_receiver();
  57. myRadio_restartCadReceiver();
  58. }
  59. break;
  60. case TX_STA_SECCESS:
  61. {
  62. // myRadio_receiver();
  63. myRadio_cadReceiver(300, 1000);
  64. }
  65. break;
  66. default:
  67. break;
  68. }
  69. }
  70. uint32_t sendTimeout = 0;
  71. int main(void)
  72. {
  73. SN_SYSCLK_set(SYSCLK_48MHZ); //设置系统时钟为48MHZ
  74. std_delay_init(); //初始化延时(该延时是使用滴答定时器实现的)
  75. std_delayms(500);
  76. SN_UART_init(UART1,921600, UART1_RX_PA2, UART1_TX_PB6); //初始化串口
  77. myRadio_init(0, rfRx_callback);
  78. myRadio_cadReceiver(500, 2000);
  79. // myRadio_receiver();
  80. printf("power on");
  81. while(1){
  82. std_delayms(1);
  83. // SN_ADC_start(); //此时编译的SN_ADC_star()是轮询处理
  84. // ADC_VAL = SN_ADC_Get_float(0); //PA7通道电压值
  85. // MCU_VDD = SN_ADC_MCU_VDD(); //获取MCU的当前vdd电压
  86. if (sendTimeout++ > 1000)
  87. {
  88. sendTimeout = 0;
  89. // myRadio_transmitArray("hello world", 10);
  90. }
  91. myRadio_process();
  92. }
  93. }