static void CLK_Config(void)
{
/* Select HSE as system clock source */
CLK_SYSCLKSourceSwitchCmd(ENABLE);
CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE);
/* system clock prescaler: 1*/
CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
while (CLK_GetSYSCLKSource() != CLK_SYSCLKSource_HSE)
{}
/* Enable Clocks of DAC, TIM4 and DMA1 */
CLK_PeripheralClockConfig(CLK_Peripheral_DAC, ENABLE);
CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, ENABLE);
CLK_PeripheralClockConfig(CLK_Peripheral_DMA1, ENABLE);
CLK_CCOConfig(CLK_CCOSource_HSE,CLK_CCODiv_8);//时钟输出
CLK_PeripheralClockConfig(CLK_Peripheral_COMP,ENABLE); //因为DAC 用到比较器,所以要打开比较器时钟
}
/**
* @brief Configure DMA peripheral
* @param None
* @retval None
*/
static void DMA_Config(void)
{
/* DMA channel3 Config -----------------------------------------------------*/
DMA_GlobalDeInit();
DMA_DeInit(DMA1_Channel3);
DMA_Init(DMA1_Channel3, (uint16_t)&Sine12bit, DAC_DR_ADDRESS, //Sine12bit 是要DMA 传达输到DAC 中的数组首址 DAC_DR_ADDRESS 是DAC 数据寄存器首址
250, DMA_DIR_MemoryToPeripheral, DMA_Mode_Circular, //250 是数组大小
DMA_MemoryIncMode_Inc, DMA_Priority_High, DMA_MemoryDataSize_HalfWord);
/* DMA1 Channel 3 enable */
DMA_Cmd(DMA1_Channel3, ENABLE);
DMA_GlobalCmd(ENABLE);
}
/**
* @brief Configure DAC peripheral
* @param None
* @retval None
*/
static void DAC_Config(void)
{
/* DAC Channel1 Config: 12bit right ----------------------------------------*/
/* DAC deinitialize */
SYSCFG_RIIOSwitchConfig (RI_IOSwitch_15, ENABLE); //打开PB4 DAC
DAC_DeInit();
/* Fill DAC Init param DAC_Trigger_T4_TRGO and DAC Channel1 Init */
DAC_Init(DAC_Channel_1, DAC_Trigger_T4_TRGO, DAC_OutputBuffer_Enable);
//DAC_SetChannel1Data(DAC_Align_12b_R,0x0FFF); //DMA 模式可以不用
/* Enable DAC Channel1 */
DAC_Cmd(DAC_Channel_1, ENABLE);
/* Enable DMA for DAC Channel1 */
DAC_DMACmd(DAC_Channel_1, ENABLE);
}
/**
* @brief Configure TIM4 peripheral
* @param None
* @retval None
*/
static void TIM4_Config(void)// 用做DAC更新
{
TIM4_DeInit();
/* Time base configuration */
TIM4_TimeBaseInit(TIM4_Prescaler_32, 0x01);//UP 计数器 从0 上升到 ARR寄存器中的值时溢出, 时钟不能太快,否则有问题
/* TIM4 TRGO selection */
TIM4_SelectOutputTrigger(TIM4_TRGOSource_Update);
/* TIM4 enable counter */
TIM4_Cmd(ENABLE);
} |