cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 DAC

boris239955_stm1_st
Associate II
Posted on February 29, 2016 at 09:05

Hello,

I have a problem with DAC of stm32f4 discovery board. I want to increase amplitude of the signal. The signal is defined by array. The problem is that when I press the button I enter to the function which send the signal but never get out of this function when I press the button again

static
void EXTILine
0
_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIOA clock */
__HAL_RCC_GPIOA_CLK_ENABLE();
/* Configure PA0 pin as input floating */
GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Pin = B
1
_Pin;
HAL_GPIO_Init(B
1
_GPIO_Port, &GPIO_InitStructure);
/* Enable and set EXTI Line0 Interrupt to the lowest priority */
HAL_NVIC_SetPriority(EXTI
0
_IRQn, 
0
, 
0
);
HAL_NVIC_EnableIRQ(EXTI
0
_IRQn);
}
void HAL_GPIO_EXTI_Callback(uint
16
_t GPIO_Pin)
{
if(GPIO_Pin == B
1
_Pin)
{
HAL_GPIO_TogglePin(LED_CONTROL,LED
3
); // toggle the led to see if I'm in the interrupt
if(Multiplier_RISE<
2
)
{
Multiplier = Multiplier_RISE;
Multiplier_RISE = Multiplier+
0.05
;
 SINE_SIGNAL();
}}}
void SINE_SIGNAL(void)
{
uint
32
_t i;
/*##-1- Initialize the DAC peripheral ######################################*/
if(HAL_DAC_Init(&hdac) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-1- DAC channel1 Configuration #########################################*/
sConfig.DAC_Trigger = DAC_TRIGGER_T
6
_TRGO;
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; 
if(HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_
1
) != HAL_OK)
{
/* Channel configuration Error */
Error_Handler();
}
/*##-2- Enable DAC Channel1 and associated DMA #############################*/
for(i=
0
;i<
255
;i++) SINE_SIGNAL_ARRAY[i] = (uint
32
_t)(((float)(SINE_SIGNAL_ARRAY[i])) * (float)(Multiplier_RISE)); // multiply every element of the array to get the amplitude that I want
if(HAL_DAC_Start_DMA(&hdac, DAC_CHANNEL_
1
, (uint
32
_t*)SINE_SIGNAL_ARRAY,sizeof(SINE_SIGNAL_ARRAY), DAC_ALIGN_
8
B_R)!=HAL_OK)
{
Error_Handler();
}
}
void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
{
GPIO_InitTypeDef GPIO_InitStruct;
static
DMA_HandleTypeDef hdma_dac
1
;
/*##-1- Enable peripherals and GPIO Clocks #################################*/
/* DAC Periph clock enable */
__HAL_RCC_DAC_CLK_ENABLE();
/* Enable GPIO clock ****************************************/
//DACx_CHANNEL
1
_GPIO_CLK_ENABLE();
/* DMA1 clock enable */
__HAL_RCC_DMA
1
_CLK_ENABLE();
__DAC_CLK_ENABLE();
/*##-2- Configure peripheral GPIO ##########################################*/
/* DAC Channel1 GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_
4
;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*##-3- Configure the DMA streams ##########################################*/
/* Set the parameters to be configured for Channel1*/
hdma_dac
1
.Instance = DMA
1
_Stream
5
;
hdma_dac
1
.Init.Channel = DMA_CHANNEL_
7
;
hdma_dac
1
.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_dac
1
.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_dac
1
.Init.MemInc = DMA_MINC_ENABLE;
hdma_dac
1
.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_dac
1
.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_dac
1
.Init.Mode = DMA_CIRCULAR; //DMA_NORMAL, DMA_PFCTRL, DMA_CIRCULAR
hdma_dac
1
.Init.Priority = DMA_PRIORITY_HIGH;
hdma_dac
1
.Init.FIFOMode = DMA_FIFOMODE_DISABLE; 
hdma_dac
1
.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL;
hdma_dac
1
.Init.MemBurst = DMA_MBURST_SINGLE;
hdma_dac
1
.Init.PeriphBurst = DMA_PBURST_SINGLE;
HAL_DMA_Init(&hdma_dac
1
);
/* Associate the initialized DMA handle to the the DAC handle */
__HAL_LINKDMA(hdac, DMA_Handle
1
, hdma_dac
1
);
/*##-4- Configure the NVIC for DMA #########################################*/
/* Enable the DMA1 Stream5 IRQ Channel */
//HAL_NVIC_SetPriority(DACx_DMA_IRQn
1
, 
2
, 
0
);
HAL_NVIC_SetPriority(DMA
1
_Stream
5
_IRQn,
2
,
2
);
HAL_NVIC_EnableIRQ(DMA
1
_Stream
5
_IRQn);
}

#stm32f4discovery-dma
0 REPLIES 0