/**
* @brief Set the specified data holding register value for DAC channel1.
* @param DAC_Align: Specifies the data alignment for DAC channel1.
* This parameter can be one of the following values:
* @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
* @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
* @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
* @param Data: Data to be loaded in the selected data holding register.
* @retval None
*/
void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data)
{
__IO uint32_t temp = 0;
temp = (uint32_t)DAC_BASE;
temp += DHR12R_OFFSET + DAC_Align;
/* Set the DAC channel1 selected data holding register */
*(__IO uint32_t *) temp = Data;
}
今天正好在调dac,我调用左对齐,数值会把低4位的数据干掉,dac输出的值很小,我仔细看了一下这个函数和相关的寄存器,如果左对齐的话要数据要左移4位,算不算这个函数的一个小漏洞
void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data)
{
__IO uint32_t temp = 0;
temp = (uint32_t)DAC_BASE;
temp += DHR12R_OFFSET + DAC_Align;
if(DAC_Align == DAC_ALIGN_12B_L)
*(__IO uint32_t *) temp = (Data << 4);
else
/* Set the DAC channel1 selected data holding register */
*(__IO uint32_t *) temp = Data;
}
|