#include "RFDAproto.h" #include "usbd_cdc_if.h" #define RFDA_TIM TIM1 //timer [CH1] --- PA8 #define RFDA_TIM_ARR 10U #define RFDA_TIM_CCR1 7U #define LE_AND_DATA_PORT GPIOA #define LE_S GPIO_BSRR_BS1 //[LE] --- PA1 #define LE_R GPIO_BSRR_BR1 #define DATA_S GPIO_BSRR_BS2 //[DATA] --- PA2 #define DATA_R GPIO_BSRR_BR2 #define DMA_CH DMA1_Channel5 #define BUF_LEN 7U uint32_t buf[BUF_LEN]; uint8_t i; void PWM_init(void){ SET_BIT(RFDA_TIM->BDTR,TIM_BDTR_MOE);//OUTPUT ENABLE SET_BIT(RFDA_TIM->CCER, TIM_CCER_CC1E); //Capture/Compare 1 output enable } void PWM(uint8_t ar,uint8_t cc){ //TIM CFG CLEAR_BIT(RFDA_TIM->CR1, TIM_CR1_CEN); //turn off counter CLEAR_BIT(RFDA_TIM->CCER, TIM_CCER_CC1E); //disable data OUTPUT WRITE_REG(RFDA_TIM->ARR,ar); //SET autoreload value WRITE_REG(RFDA_TIM->CCR1,cc);//SET capture-compare value WRITE_REG(RFDA_TIM->CNT,0U); //Set TIM counter to zero SET_BIT(RFDA_TIM->CCER, TIM_CCER_CC1E); //enable data OUTPUT SET_BIT(RFDA_TIM->EGR, TIM_EGR_UG); //update gen SET_BIT(RFDA_TIM->CR1,TIM_CR1_CEN); //enable counter } /** * @brief This function handles DMA1 channel2 global interrupt. */ void DMA1_Channel5_IRQHandler(void) { /* USER CODE BEGIN DMA1_Channel2_IRQn 0 */ // CLEAR_BIT(RFDA_TIM->CR1, TIM_CR1_CEN); //turn off counter // CLEAR_BIT(RFDA_TIM->CCER, TIM_CCER_CC1E); //disable data channel // WRITE_REG(LE_AND_DATA_PORT->BSRR,LE_S|DATA_R); //LE SET and DATA RESET at the END of transfer // SET_BIT(DMA1->IFCR, DMA_IFCR_CTCIF5); //CTCIFx: Channel x transfer complete flag clear (x = 1 ..7) /* USER CODE END DMA1_Channel2_IRQn 0 */ /* USER CODE BEGIN DMA1_Channel2_IRQn 1 */ /* USER CODE END DMA1_Channel2_IRQn 1 */ }