cancel
Showing results for 
Search instead for 
Did you mean: 

DMA A/D on STM32WB55 Nucleo board

SWenn.1
Senior III

Hello....

I am trying to do a DMA of 32 samples every second. The A/D sequence is CH1, CH2. (so 16 samples of each). I have attached a picture trying to depict what I am doing. I am starting the DMA but I never get into the Transfer Complete interrupt. The TCIE and EN bit are set as seen in the debugger. Addresses all look correct and the transfer size looks correct (0x20). My timer is going off as expected every 1 second so trigger is there. I have attached MX settings for the A/D converter. Can someone point me as to what I seem to be doing wrong?

Thank you.
_legacyfs_online_stmicro_images_0693W00000bidKaQAI.png

3 REPLIES 3
WQ
Associate III

I did enable the Continuous Conversion Mode and disable the DMA Continuous Requests. -wq

SWenn.1
Senior III

So I did per the above request but to no avail....I have included scope picture along with code along with setup in MX with respect to Timer1 and A/D....DMA is set up as circular buffer, periph to memory. The scope shows the GPIO that powers ch1 temperature sensors VCC pin.

Based on values in MX (A/D clock at 32MHz with a prescaler of 2) I would expect both channels to take about 1.56us for sample and hold. If we do this 32x ie 16 for ch1 and 16 for ch2, I would expect the GPIO to be high for about 5us total. The first pulse on the scope pic is about 50us wide and then one second later you can see the GPIO is now 1 second wide. Can someone please tell me what I am doing wrong here?? My initial dwg shows what I would like to do.

CODE: This is pretty simple....I turn on compare output one 3ms before the update event rollover. (I used the LD1 pin to test that every 1 second I have a 3ms pulse so I believe timer is working fine) At this interrupt I turn on power to the sensors. The update event then occurs and I collect my 32 samples....The ultimate question is why isn't the power on (blue scope trace) 5us every one second??

int main(void)
{
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
/* Configure the peripherals common clocks */
  PeriphCommonClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_TIM1_Init();
  MX_ADC1_Init();
  MX_LPUART1_UART_Init();
  /* USER CODE BEGIN 2 */
  HAL_TIM_OC_Start_IT(&htim1, TIM_CHANNEL_1); //does NOT set CEN bit!
  htim1.Instance->DIER |= TIM_DIER_UIE;
 
  /* calibrate converter, wait for flag */
  HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);
 
  asm("NOP");
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	  if (ISR.timer_turnOnSensors)
	  {
		  ISR.timer_turnOnSensors = F;
		  HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_SET); //test LED
		  /*
		   * enable power to temperature sensors
		   */
		  HAL_GPIO_WritePin(Tsink_VCC_GPIO_Port, Tsink_VCC_Pin, GPIO_PIN_SET);
		  HAL_GPIO_WritePin(Tsrc_VCC_GPIO_Port, Tsrc_VCC_Pin, GPIO_PIN_SET);
		  /*
		   * enable A/D converter
		   */
		  hadc1.Instance->CR |= ADC_CR_ADEN;
	  }
 
	  if (ISR.timer_takeADSample)
	  {
		  ISR.timer_takeADSample = F;
 
		  /*
		   * start DMA for A/D
		   */
		  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_buf, 32);
 
	  }
 
	  if (ISR.dma_AD_Done)
	  {
		  HAL_ADC_Stop_DMA(&hadc1);
		  HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_RESET); //test LED
 
		  /*
		   * disable power to temperature sensors
		   */
		  HAL_GPIO_WritePin(Tsink_VCC_GPIO_Port, Tsink_VCC_Pin, GPIO_PIN_RESET);
		  HAL_GPIO_WritePin(Tsrc_VCC_GPIO_Port, Tsrc_VCC_Pin, GPIO_PIN_RESET);
		  /*
		   * disable A/D converter
		   */
		  hadc1.Instance->CR &= ~ADC_CR_ADEN;
 
//		  average(adc_buf, stream);
/*
		  for (uint8_t k = 0; k < NO_ADC_CH; k++)
		  {
			  static char string[8];
			  ISR.usart_txToPC = F;
			  HAL_UART_Transmit_IT(&hlpuart1, (uint8_t*)string, sprintf(string, "%04X\r\n", (unsigned int)stream[k]));
			  while(!ISR.usart_txToPC);
		  }
*/
		  ISR.dma_AD_Done = F;
	  }
 
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}
 
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
	ISR.timer_takeADSample = T;
}
 
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
{
	ISR.timer_turnOnSensors = T;
}
 
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
{
	ISR.dma_AD_Done = T;
}

Thank you

SWenn.1
Senior III

cube mx settings on A/D and TIM1