RFDAproto.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "RFDAproto.h"
  2. #include "usbd_cdc_if.h"
  3. #define RFDA_TIM TIM1 //timer [CH1] --- PA8
  4. #define RFDA_TIM_ARR 10U
  5. #define RFDA_TIM_CCR1 7U
  6. #define LE_AND_DATA_PORT GPIOA
  7. #define LE_S GPIO_BSRR_BS1 //[LE] --- PA1
  8. #define LE_R GPIO_BSRR_BR1
  9. #define DATA_S GPIO_BSRR_BS2 //[DATA] --- PA2
  10. #define DATA_R GPIO_BSRR_BR2
  11. #define DMA_CH DMA1_Channel5
  12. #define BUF_LEN 7U
  13. uint32_t buf[BUF_LEN];
  14. uint8_t i;
  15. void PWM_init(void){
  16. SET_BIT(RFDA_TIM->BDTR,TIM_BDTR_MOE);//OUTPUT ENABLE
  17. SET_BIT(RFDA_TIM->CCER, TIM_CCER_CC1E); //Capture/Compare 1 output enable
  18. }
  19. void PWM(uint8_t ar,uint8_t cc){
  20. //TIM CFG
  21. CLEAR_BIT(RFDA_TIM->CR1, TIM_CR1_CEN); //turn off counter
  22. CLEAR_BIT(RFDA_TIM->CCER, TIM_CCER_CC1E); //disable data OUTPUT
  23. WRITE_REG(RFDA_TIM->ARR,ar); //SET autoreload value
  24. WRITE_REG(RFDA_TIM->CCR1,cc);//SET capture-compare value
  25. WRITE_REG(RFDA_TIM->CNT,0U); //Set TIM counter to zero
  26. SET_BIT(RFDA_TIM->CCER, TIM_CCER_CC1E); //enable data OUTPUT
  27. SET_BIT(RFDA_TIM->EGR, TIM_EGR_UG); //update gen
  28. SET_BIT(RFDA_TIM->CR1,TIM_CR1_CEN); //enable counter
  29. }
  30. /**
  31. * @brief This function handles DMA1 channel2 global interrupt.
  32. */
  33. void DMA1_Channel5_IRQHandler(void)
  34. {
  35. /* USER CODE BEGIN DMA1_Channel2_IRQn 0 */
  36. // CLEAR_BIT(RFDA_TIM->CR1, TIM_CR1_CEN); //turn off counter
  37. // CLEAR_BIT(RFDA_TIM->CCER, TIM_CCER_CC1E); //disable data channel
  38. // WRITE_REG(LE_AND_DATA_PORT->BSRR,LE_S|DATA_R); //LE SET and DATA RESET at the END of transfer
  39. // SET_BIT(DMA1->IFCR, DMA_IFCR_CTCIF5); //CTCIFx: Channel x transfer complete flag clear (x = 1 ..7)
  40. /* USER CODE END DMA1_Channel2_IRQn 0 */
  41. /* USER CODE BEGIN DMA1_Channel2_IRQn 1 */
  42. /* USER CODE END DMA1_Channel2_IRQn 1 */
  43. }