AnsweredAssumed Answered

STM32F4 DAC

Question asked by s.boris on Feb 29, 2016
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 EXTILine0_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 = B1_Pin;
  HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStructure);
 
  /* Enable and set EXTI Line0 Interrupt to the lowest priority */
  HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI0_IRQn);
}
 
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  if(GPIO_Pin == B1_Pin)
  {
 
     HAL_GPIO_TogglePin(LED_CONTROL,LED3); // 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)
{
uint32_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_T6_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] = (uint32_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, (uint32_t*)SINE_SIGNAL_ARRAY,sizeof(SINE_SIGNAL_ARRAY), DAC_ALIGN_8B_R)!=HAL_OK)
    {
     
    Error_Handler();
  }
 }
 
void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
{
  GPIO_InitTypeDef          GPIO_InitStruct;
  static DMA_HandleTypeDef  hdma_dac1;
   
  /*##-1- Enable peripherals and GPIO Clocks #################################*/
  /* DAC Periph clock enable */
  __HAL_RCC_DAC_CLK_ENABLE();
  /* Enable GPIO clock ****************************************/
  //DACx_CHANNEL1_GPIO_CLK_ENABLE();
 /* DMA1 clock enable */
  __HAL_RCC_DMA1_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_dac1.Instance = DMA1_Stream5;
   
  hdma_dac1.Init.Channel  = DMA_CHANNEL_7;
  hdma_dac1.Init.Direction = DMA_MEMORY_TO_PERIPH;
  hdma_dac1.Init.PeriphInc = DMA_PINC_DISABLE;
  hdma_dac1.Init.MemInc = DMA_MINC_ENABLE;
  hdma_dac1.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  hdma_dac1.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  hdma_dac1.Init.Mode = DMA_CIRCULAR; //DMA_NORMAL, DMA_PFCTRL, DMA_CIRCULAR
  hdma_dac1.Init.Priority = DMA_PRIORITY_HIGH;
  hdma_dac1.Init.FIFOMode = DMA_FIFOMODE_DISABLE;        
  hdma_dac1.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL;
  hdma_dac1.Init.MemBurst = DMA_MBURST_SINGLE;
  hdma_dac1.Init.PeriphBurst = DMA_PBURST_SINGLE;
 
  HAL_DMA_Init(&hdma_dac1);
     
  /* Associate the initialized DMA handle to the the DAC handle */
  __HAL_LINKDMA(hdac, DMA_Handle1, hdma_dac1);
 
  /*##-4- Configure the NVIC for DMA #########################################*/
  /* Enable the DMA1 Stream5 IRQ Channel */
  //HAL_NVIC_SetPriority(DACx_DMA_IRQn1, 2, 0);
  HAL_NVIC_SetPriority(DMA1_Stream5_IRQn,2,2);
    HAL_NVIC_EnableIRQ(DMA1_Stream5_IRQn);
}

Outcomes