DAC驱动
void bsp_dac_init(uint16_t dac_val)
{
bsp_dac_rcc_config(); //开启DAC时钟
bsp_dac_io_config(); //配置io
bsp_dac_config(dac_val); //配置dac数值
}
static void bsp_dac_rcc_config()
{
RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_DAC, ENABLE);
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
}
static void bsp_dac_io_config(void)
{
GPIO_InitType GPIO_InitStructure = {0}; //创建结构体,并置0;
GPIO_InitStruct(&GPIO_InitStructure); //初始化结构体,配置为默认数值;
/* Once the DAC channel is enabled, the corresponding GPIO pin is automatically connected to the DAC converter. In order to avoid parasitic consumption, the GPIO pin should be configured in analog */
GPIO_InitStructure.Pin = GPIO_PIN_4 ; //选择引脚4
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Analog;//
GPIO_InitStructure.GPIO_Pull = GPIO_No_Pull; //
GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);//写入以上GPIO配置参数
}
static void bsp_dac_config(uint16_t dac_val)
{
DAC_InitType DAC_InitStructure;
/* DAC channel1 Configuration */
DAC_InitStructure.Trigger = DAC_TRG_SOFTWARE; //DAC通过软件方式触发
DAC_InitStructure.WaveGen = DAC_WAVEGEN_NONE; //禁用噪声和三角波
DAC_InitStructure.LfsrUnMaskTriAmp = DAC_UNMASK_LFSRBIT0; //WaveGen设置为DAC_WAVEGEN_NONE后设置LfsrUnMaskTriAmp任意值始终为无效状态
DAC_InitStructure.BufferOutput = DAC_BUFFOUTPUT_DISABLE;//禁用 DAC 通道输出缓存
DAC_Init(&DAC_InitStructure);
/* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is automatically connected to the DAC converter. */
DAC_Enable(ENABLE);
bsp_delay_ms(10); //等待DAC完全打开 tWAKEUP时间
/* Set DAC channel DR12DCH register */
DAC_SetChData(DAC_ALIGN_R_12BIT, dac_val); //1.0V 241mv
DAC_SoftTrgEnable(ENABLE); //此步骤不能省略,开启软件触发DAC
}
————————————————
版权声明:本文为CSDN博主「Super__Kun」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/FLY__Kun/article/details/151328353
|
|