main.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. switch (status)
  38. {
  39. case RX_STA_SECCESS:
  40. {
  41. myRadio_receiver();
  42. }
  43. break;
  44. case RX_STA_TIMEOUT:
  45. {
  46. myRadio_receiver();
  47. }
  48. break;
  49. case RX_STA_PAYLOAD_ERROR:
  50. {
  51. myRadio_receiver();
  52. }
  53. break;
  54. case TX_STA_SECCESS:
  55. {
  56. myRadio_receiver();
  57. }
  58. break;
  59. default:
  60. break;
  61. }
  62. }
  63. uint32_t sendTimeout = 0;
  64. int main(void)
  65. {
  66. SN_SYSCLK_set(SYSCLK_48MHZ); //设置系统时钟为48MHZ
  67. std_delay_init(); //初始化延时(该延时是使用滴答定时器实现的)
  68. myRadio_init(0, rfRx_callback);
  69. RF_SetPreamLen(50);
  70. // myRadio_setFrequency(SET_RF_FREQ_HZ(rfBaseFreqList[deviceInfor.chipType], deviceInfor.rfChannel, deviceInfor.channelStep));
  71. // myRadio_setTxPower(rfTxPowerList[deviceInfor.txPower]);
  72. // myRadio_setRfParams(deviceInfor.rf_sf, deviceInfor.rf_bw, deviceInfor.rf_cr);
  73. // myRadio_setSyncWord(0x45);
  74. // myRadio_receiver();
  75. // std_delayms(500);
  76. // myRadio_transmitArray("hello world", 10);
  77. // SN_ADC_IN_init(ADC_CHANNEL_4_PA7); //初始化ADC
  78. // SN_PWM_TIM1_OUT_Complementary(TIM1_CH2N_PA0); //设置互补通道,注意要先设定互补通道后,才能初始化pwm输出
  79. // SN_PWM_TIM1_OUT_init(TIM1_CH2_PA1,1000); //设置定时器3通道1 和 通道2 输出占空比数是1000的方波,输出io分别是PA0 ,PA4
  80. // SN_UART_init(UART1,9600, UART1_RX_PA4 ,UART1_TX_PA3 ); //初始化串口
  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+rand()%100)
  87. {
  88. sendTimeout = 0;
  89. myRadio_transmitArray("hello world", 10);
  90. }
  91. myRadio_process();
  92. }
  93. }