使用遇到的问题:
1.adc使用DAM弹性映射,不能采集到adc数据
adc例程正常采集,调整为弹性映射之后,一样不能采集
2.dac使用DMA弹性映射,不能输出dac数据
dac例程正常输出,调整为弹性映射之后,一样不能输出
void dac_init(void)
{
GPIO_InitType 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.GPIO_Pins = GPIO_Pins_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_ANALOG;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pins = GPIO_Pins_0|GPIO_Pins_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT_PP;
GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
DAC_InitType DAC_InitStructure;
DMA_InitType DMA_InitStructure;
TMR_TimerBaseInitType TMR_TimeBaseStructure;
/* TIM4 Configuration */
/* Time base configuration */
TMR_TimeBaseStructInit(&TMR_TimeBaseStructure);
TMR_TimeBaseStructure.TMR_Period = 0x19;
TMR_TimeBaseStructure.TMR_DIV = 0x0;
TMR_TimeBaseStructure.TMR_ClockDivision = 0x0;
TMR_TimeBaseStructure.TMR_CounterMode = TMR_CounterDIR_Up;
TMR_TimeBaseInit(TMR4, &TMR_TimeBaseStructure);
/* TIM4 TRGO selection */
TMR_SelectOutputTrigger(TMR4, TMR_TRGOSource_Update);
/* DAC channel1 Configuration */
DAC_StructInit(&DAC_InitStructure);
DAC_InitStructure.DAC_Trigger = DAC_Trigger_TMR4_TRGO;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
/* DAC channel2 Configuration */
DAC_Init(DAC_Channel_2, &DAC_InitStructure);
/* Fill Sine32bit table */
for (Idx = 0; Idx < 32; Idx++)
{
DualSine12bit[Idx] = (Sine12bit[Idx] << 16) + (Sine12bit[Idx]);
}
/* DMA2 channel4 configuration */
DMA_Reset(DMA2_Channel4);
DMA_DefaultInitParaConfig(&DMA_InitStructure);
DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&DualSine12bit;
DMA_InitStructure.DMA_Direction = DMA_DIR_PERIPHERALDST;
DMA_InitStructure.DMA_BufferSize = 32;
DMA_InitStructure.DMA_PeripheralInc = DMA_PERIPHERALINC_DISABLE;
DMA_InitStructure.DMA_MemoryInc = DMA_MEMORYINC_ENABLE;
DMA_InitStructure.DMA_PeripheralDataWidth = DMA_PERIPHERALDATAWIDTH_WORD;
DMA_InitStructure.DMA_MemoryDataWidth = DMA_MEMORYDATAWIDTH_WORD;
DMA_InitStructure.DMA_Mode = DMA_MODE_CIRCULAR;
DMA_InitStructure.DMA_Priority = DMA_PRIORITY_HIGH;
DMA_InitStructure.DMA_MTOM = DMA_MEMTOMEM_DISABLE;
DMA_Init(DMA2_Channel4, &DMA_InitStructure);
// DMA_Flexible_Config(DMA2, Flex_Channel4, DMA_FLEXIBLE_DAC1);//开启DMA弹性映射,弹性映射必须要加上这个配置!
/* Enable DMA2 Channel4 */
DMA_ChannelEnable(DMA2_Channel4, ENABLE);
/* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is
automatically connected to the DAC converter. */
DAC_Ctrl(DAC_Channel_1, ENABLE);
/* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is
automatically connected to the DAC converter. */
DAC_Ctrl(DAC_Channel_2, ENABLE);
/* Enable DMA for DAC Channel2 */
DAC_DMACtrl(DAC_Channel_2, ENABLE);
/* TIM2 enable counter */
TMR_Cmd(TMR4, ENABLE);
}
|
代码67行为DMA弹性映射设置的代码,例程默认是没有这一行的,是可以正常使用,输出正弦波;加了弹性映射之后,无输出。