STM32-AD5621-DAC-main.c

by Marwen Maghrebi
/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include<AD5621.h>
/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/
SPI_HandleTypeDef hspi1;

/* USER CODE BEGIN PV */

const uint16_t SINE_POINTS = 360;
uint16_t sine_table[360];

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI1_Init(void);

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_SPI1_Init();
  /* USER CODE BEGIN 2 */

  // Initialize AD5601 with SPI handle, CS pin, and CS GPIO port
  ad5621_Init(&hspi1, GPIO_PIN_4, GPIOA);
  // Generate the sine table
  ad5621_GenerateSineTable(sine_table, SINE_POINTS);

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
    /* USER CODE BEGIN 3 */
  for (int i = 0; i < SINE_POINTS; i++)
  {
      ad5621_SendToDAC(sine_table[i]);
      HAL_Delay(1);  // Adjust delay if needed
  }

  }
  /* USER CODE END 3 */
}
Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00