下面是参考用户代码。代码在手机模式下可左右滑动。
/* USER CODE BEGIN PD */
#define ARR1 (10000U)
#define ARR2 (20000U)
#define ARR3 (40000U)
#define Count (18) //3 * 6
uint16_t PulseData1[]={
ARR1,0,ARR1*0.5,
ARR1,0,ARR1*0.5,
ARR1,0,ARR1*0.5,
ARR1,0,ARR1*0.5,
ARR1,0,ARR1*0.5,//
ARR1,0,0};
uint16_t PulseData2[]={
ARR2,0,ARR2*0.5,
ARR2,0,ARR2*0.5,
ARR2,0,ARR2*0.5,
ARR2,0,ARR2*0.5,
ARR2,0,ARR2*0.5,//
ARR2,0,0,
};
uint16_t PulseData3[]={
ARR3,0,ARR3*0.5,
ARR3,0,ARR3*0.5,
ARR3,0,ARR3*0.5,
ARR3,0,ARR3*0.5,
ARR3,0,ARR3*0.5,//5
ARR3,0,0,
};
/* USER CODE END PD */
主循环测试代码如下:
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_TIM3_Init();
/* USER CODE BEGIN 2 */
__HAL_TIM_CLEAR_FLAG(&htim3,TIM_FLAG_UPDATE);
TIM_CCxChannelCmd(TIM3,TIM_CHANNEL_1,TIM_CCx_ENABLE);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
htim3.DMABurstState = HAL_DMA_BURST_STATE_READY;
hdma_tim3_up.State = HAL_DMA_STATE_READY ;
__HAL_TIM_CLEAR_FLAG(&htim3,TIM_FLAG_UPDATE);
HAL_TIM_DMABurst_MultiWriteStart(&htim3, TIM_DMABASE_ARR,TIM_DMA_UPDATE,(uint32_t *)PulseData1,\\
TIM_DMABURSTLENGTH_3TRANSFERS,Count);
TIM3- >EGR = TIM_EGR_UG;
__HAL_TIM_ENABLE(&htim3);
HAL_Delay(150); //Prepared for the next 5 Pulses
__HAL_TIM_DISABLE(&htim3);
// HAL_DMA_Abort(&hdma_tim3_up);
htim3.DMABurstState = HAL_DMA_BURST_STATE_READY;
hdma_tim3_up.State = HAL_DMA_STATE_READY ;
__HAL_TIM_CLEAR_FLAG(&htim3,TIM_FLAG_UPDATE);
HAL_TIM_DMABurst_MultiWriteStart(&htim3, TIM_DMABASE_ARR,TIM_DMA_UPDATE,(uint32_t *)PulseData2,\\
TIM_DMABURSTLENGTH_3TRANSFERS,Count);
TIM3- >EGR = TIM_EGR_UG;
__HAL_TIM_ENABLE(&htim3);
HAL_Delay(150);//Prepared for the next 5 Pulses
__HAL_TIM_DISABLE(&htim3);
// HAL_DMA_Abort(&hdma_tim3_up);
htim3.DMABurstState = HAL_DMA_BURST_STATE_READY;
hdma_tim3_up.State = HAL_DMA_STATE_READY ;
__HAL_TIM_CLEAR_FLAG(&htim3,TIM_FLAG_UPDATE);
HAL_TIM_DMABurst_MultiWriteStart(&htim3, TIM_DMABASE_ARR,TIM_DMA_UPDATE,(uint32_t *)PulseData3,
TIM_DMABURSTLENGTH_3TRANSFERS,Count);
TIM3- >EGR = TIM_EGR_UG;
__HAL_TIM_ENABLE(&htim3);
HAL_Delay(150);//Prepared for the next 5 Pulses
__HAL_TIM_DISABLE(&htim3);
// HAL_DMA_Abort(&hdma_tim3_up);
}
/* USER CODE END 3 */
}