main.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #define BOARD_PIN_MOTOR GPIO_PIN_1 //
  34. #define BOARD_PORT_MOTOR GPIOC //
  35. #define BOARD_GPIO_MOTOR BOARD_PORT_MOTOR, BOARD_PIN_MOTOR //
  36. uint16_t ADC_VAL = 0;
  37. float MCU_VDD = 0;
  38. void rfRx_callback(uint8_t status, rfRxPacket_ts packet)
  39. {
  40. printf("status:%d\r\n", status);
  41. switch (status)
  42. {
  43. case RX_STA_SECCESS:
  44. {
  45. printf("receive data:%s\r\n", packet.payload);
  46. // RF_StopCad();
  47. // myRadio_receiver();
  48. // myRadio_restartCadReceiver();
  49. myRadio_transmitArray("hello world", 10);
  50. motor_long();
  51. }
  52. break;
  53. case RX_STA_TIMEOUT:
  54. {
  55. // myRadio_receiver();
  56. myRadio_restartCadReceiver();
  57. }
  58. break;
  59. case RX_STA_PAYLOAD_ERROR:
  60. {
  61. // myRadio_receiver();
  62. myRadio_restartCadReceiver();
  63. }
  64. break;
  65. case TX_STA_SECCESS:
  66. {
  67. // myRadio_receiver();
  68. myRadio_cadReceiver(500, 2000);
  69. }
  70. break;
  71. default:
  72. break;
  73. }
  74. }
  75. void motor_short(void)
  76. {
  77. SN_GPIO_PIN_write(BOARD_GPIO_MOTOR, 1);
  78. std_delayms(50);
  79. SN_GPIO_PIN_write(BOARD_GPIO_MOTOR, 0);
  80. }
  81. void motor_long(void)
  82. {
  83. SN_GPIO_PIN_write(BOARD_GPIO_MOTOR, 1);
  84. std_delayms(200);
  85. SN_GPIO_PIN_write(BOARD_GPIO_MOTOR, 0);
  86. }
  87. uint32_t sendTimeout = 0;
  88. int main(void)
  89. {
  90. SN_SYSCLK_set(SYSCLK_48MHZ); //设置系统时钟为48MHZ
  91. std_delay_init(); //初始化延时(该延时是使用滴答定时器实现的)
  92. std_delayms(500);
  93. SN_UART_init(UART1,921600, UART1_RX_PA2, UART1_TX_PB6); //初始化串口
  94. myRadio_init(0, rfRx_callback);
  95. myRadio_cadReceiver(500, 2000);
  96. SN_GPIO_PIN_init(BOARD_GPIO_MOTOR , GPIO_MODE_OUTPUT ,GPIO_PULLUP ,GPIO_OUTPUT_PUSHPULL);
  97. // myRadio_receiver();
  98. printf("power on");
  99. while(1){
  100. std_delayms(1);
  101. // SN_ADC_start(); //此时编译的SN_ADC_star()是轮询处理
  102. // ADC_VAL = SN_ADC_Get_float(0); //PA7通道电压值
  103. // MCU_VDD = SN_ADC_MCU_VDD(); //获取MCU的当前vdd电压
  104. if (sendTimeout++ > 1000)
  105. {
  106. sendTimeout = 0;
  107. // myRadio_transmitArray("hello world", 10);
  108. }
  109. myRadio_process();
  110. }
  111. }