main.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*!
  2. \file main.c
  3. \brief DAC in LFSR noise mode demo
  4. */
  5. /*
  6. Copyright (C) 2017 GigaDevice
  7. 2017-06-06, V1.0.0, firmware for GD32F3x0
  8. */
  9. #include "gd32f3x0.h"
  10. #include "systick.h"
  11. void rcu_config(void);
  12. void gpio_config(void);
  13. void dac_config(void);
  14. void timer5_config(void);
  15. /*!
  16. \brief main function
  17. \param[in] none
  18. \param[out] none
  19. \retval none
  20. */
  21. int main(void)
  22. {
  23. rcu_config();
  24. gpio_config();
  25. dac_config();
  26. timer5_config();
  27. while (1){
  28. }
  29. }
  30. /*!
  31. \brief configure the RCU of peripherals
  32. \param[in] none
  33. \param[out] none
  34. \retval none
  35. */
  36. void rcu_config(void)
  37. {
  38. /* enable the clock of peripherals */
  39. rcu_periph_clock_enable(RCU_GPIOA);
  40. rcu_periph_clock_enable(RCU_DAC);
  41. rcu_periph_clock_enable(RCU_TIMER5);
  42. }
  43. /*!
  44. \brief configure the related GPIO
  45. \param[in] none
  46. \param[out] none
  47. \retval none
  48. */
  49. void gpio_config(void)
  50. {
  51. /* once enabled the DAC, the corresponding GPIO pin is connected to the DAC converter automatically */
  52. gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_4);
  53. }
  54. /*!
  55. \brief configure the DAC
  56. \param[in] none
  57. \param[out] none
  58. \retval none
  59. */
  60. void dac_config(void)
  61. {
  62. dac_deinit();
  63. /* configure the DAC */
  64. dac_trigger_source_config(DAC_TRIGGER_T5_TRGO);
  65. dac_trigger_enable();
  66. dac_wave_mode_config(DAC_WAVE_MODE_LFSR);
  67. dac_lfsr_noise_config(DAC_LFSR_BITS10_0);
  68. dac_output_buffer_disable();
  69. /* enable DAC and set data */
  70. dac_enable();
  71. dac_data_set(DAC_ALIGN_12B_R, 0x7F0);
  72. }
  73. /*!
  74. \brief configure the TIMER5
  75. \param[in] none
  76. \param[out] none
  77. \retval none
  78. */
  79. void timer5_config(void)
  80. {
  81. /* configure the TIMER5 */
  82. timer_prescaler_config(TIMER5, 0x10, TIMER_PSC_RELOAD_UPDATE);
  83. timer_autoreload_value_config(TIMER5, 0x1FF);
  84. timer_master_output_trigger_source_select(TIMER5, TIMER_TRI_OUT_SRC_UPDATE);
  85. timer_enable(TIMER5);
  86. }