cancel
Showing results for 
Search instead for 
Did you mean: 

Hello! I purchased the STM32G431RBT-Nucleo board. When trying to write code to control the DAC, I ran into a problem - regardless of the code change, the result is 0v, there is a straight line on the oscilloscope. The code itself runs on STM32F407. Do you

DTorn.1
Associate II

One of the variint 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();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_DMA_Init();

 MX_DAC1_Init();

 MX_TIM6_Init();

 /* USER CODE BEGIN 2 */

 HAL_DAC_Start(&hdac1, DAC_CHANNEL_1);

 HAL_DAC_Start(&hdac1, DAC_CHANNEL_2);

 uint16_t sinewave[60];

 uint16_t i;

 for(i=0;i<60;i++){

  sinewave[i]=sin(i/60.0*2*3.1415926)*500+1000;

 }

 HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_1,(uint32_t *)sinewave,60,DAC_ALIGN_12B_R);

 HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_2,(uint32_t *)sinewave,60,DAC_ALIGN_12B_R);

 if (HAL_TIM_Base_Start(&htim6) != HAL_OK){

  Error_Handler();

 }

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}

ants of the code in HAL:

17 REPLIES 17
DTorn.1
Associate II

Pin P4 without DAC reproduces the signal in OUTPUT mode

> RCC->AHB1ENR  |= (RCC_AHB1ENR_DMA1EN | RCC_APB1ENR1_TIM6EN );

This does not enable TIM6 clock.

Whenever in doubts, read out and check the involved peripheral registers content.

Proceed step by step. Try a simple implementation first, using DAC without trigger (DAC_CR.TENx=0), writing various values into DAC_DHRx, maybe even manually in debugger.

JW

Yes! Of course, PA4 is connected directly to A2. Excuse me!

And it works in high/low mode! But there is no DAC signal.

DTorn.1
Associate II

There are no jumpers! Have I answered all the questions?

Please note that as soon as the thread is longer than 10 posts, there is a "More answers" at the 10th post and you have to click on it.

Sometimes, this link is not displayed, because the software ST uses here is crap, and you have to reload the thread.

JW

@Laura C.​ 

Please note that as soon as the thread is longer than 10 posts, there is a "More answers" at the 10th post and you have to click on it.

Sometimes, this link is not displayed, because the software ST uses here is crap, and you have to reload the thread.

JW

Thanks for the support! I have solved the problem! The code is correct, the payment is in order.