cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F373

jogerh
Associate II
Posted on November 05, 2015 at 11:33

Dear Community,

I want to use all the 3 DACs of a stm32f373 device. All of them need to be feed by DMA and triggered by the same external trigger impulse. Unfortunately none of the DACs is outputting anything. I use the following initialization code. I would be very if someone could review the code and if possible point me into the right direction

void DAC123_Init() { 
/* Preconfiguration before using DAC----------------------------------------*/ 
//DAC_Config
GPIO_InitTypeDef GPIO_InitStructure; 
DAC_InitTypeDef DAC_InitStructure; 
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure; //DMA Interupt 
//Enable GPIOA (PA4,5 & 6) as DAC output 
// GPIOA clock enable 
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); 
// Configure PA.04 (DAC_OUT1) as analog 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; 
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; 
GPIO_Init(GPIOA, &GPIO_InitStructure); 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; 
GPIO_Init(GPIOA, &GPIO_InitStructure); 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; 
GPIO_Init(GPIOA, &GPIO_InitStructure); 
//************************************************************************* 
// DMA1 clock enable (to be used with DAC) 
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); 
// DAC Periph clock enable RCC_APB1Periph_DAC1 
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC1, ENABLE); 
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC2, ENABLE); 
DAC_DeInit(DAC1); 
DAC_DeInit(DAC2); 
// DAC1 channel1 and channel2 
// DAC2 channel 
DAC_InitStructure.DAC_Trigger = DAC_Trigger_Ext_IT9; 
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; 
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; 
DMA_DeInit(DMA1_Channel3); 
DMA_DeInit(DMA1_Channel4); 
DMA_DeInit(DMA1_Channel5); 
DMA_InitStructure.DMA_MemoryBaseAddr = 
 (uint32_t)&(DAC_BufferX);
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; 
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord
DMA_InitStructure.DMA_PeripheralBaseAddr = 
 (uint32_t)&DAC1->DHR12R1; 
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; 
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; 
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_BufferSize = 201; 
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; 
DMA_InitStructure.DMA_Priority = DMA_Priority_High; 
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; 
DMA_Init(DMA1_Channel3, &DMA_InitStructure); 
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(DAC_BufferY); 
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&DAC1->DHR12R2;

DMA_Init(DMA1_Channel4, &DMA_InitStructure); 
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(DAC_BufferZ); 
DMA_InitStructure.DMA_PeripheralBaseAddr = 
 (uint32_t)&DAC2->DHR12R1; 
DMA_Init(DMA1_Channel5, &DMA_InitStructure); 
 //Interupts 
//DMA_IT_TC: Transfer complete interrupt mask 
//DMA_IT_HT: Half transfer interrupt mask 
//DMA_IT_TE: Transfer error interrupt mask 
// Enable DMA1 channel3 IRQ Channel 
// Enable DMA1 channel4 IRQ Channel 
// Enable DMA1 channel5 IRQ Channel 
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel3_IRQn; 
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; 
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; 
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn; 
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; 
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel5_IRQn; 
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; 
NVIC_Init(&NVIC_InitStructure); 
// DMA CONFIG 
DMA_ITConfig(DMA1_Channel3, DMA_IT_TC | DMA_IT_HT, ENABLE); 
DMA_Cmd(DMA1_Channel3, ENABLE); 
DMA_ITConfig(DMA1_Channel4, DMA_IT_TC | DMA_IT_HT, ENABLE); 
DMA_Cmd(DMA1_Channel3, ENABLE); 
DMA_ITConfig(DMA1_Channel5, DMA_IT_TC | DMA_IT_HT, ENABLE); 
DMA_Cmd(DMA1_Channel3, ENABLE); 
//DAC INIT 
DAC_Init(DAC1, DAC_Channel_1, &DAC_InitStructure); 
DAC_Init(DAC1, DAC_Channel_2, &DAC_InitStructure); 
DAC_Init(DAC2, DAC_Channel_1, &DAC_InitStructure); 
//DAC ENABLE 
DAC_Cmd(DAC1,DAC_Channel_1, ENABLE); 
DAC_Cmd(DAC1,DAC_Channel_2, ENABLE); 
DAC_Cmd(DAC2,DAC_Channel_1, ENABLE); 
// Enable DMA for DAC Channels 
DAC_DMACmd(DAC1, DAC_Channel_1, ENABLE); 
DAC_DMACmd(DAC1, DAC_Channel_2, ENABLE); 
DAC_DMACmd(DAC2, DAC_Channel_1, ENABLE); 
} 

1 REPLY 1
Posted on November 05, 2015 at 14:10

I'm not using this part, but there's an issue with enabling the DMA

DMA_ITConfig(DMA1_Channel3, DMA_IT_TC | DMA_IT_HT, ENABLE);
DMA_Cmd(DMA1_Channel3, ENABLE);
DMA_ITConfig(DMA1_Channel4, DMA_IT_TC | DMA_IT_HT, ENABLE);
DMA_Cmd(DMA1_Channel3, ENABLE); // ????
DMA_ITConfig(DMA1_Channel5, DMA_IT_TC | DMA_IT_HT, ENABLE);
DMA_Cmd(DMA1_Channel3, ENABLE); // ????

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..