STM32-MCP4921-main.c

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

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "MCP492X.h"        // Include the MCP492X header


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

UART_HandleTypeDef huart1;

/* USER CODE BEGIN PV */
DAC_MCP49x1_HandleTypeDef hdac;

#define CS_ADC_PIN GPIO_PIN_4
#define CS_ADC_PORT GPIOA
#define CS_DAC_PIN GPIO_PIN_9
#define CS_DAC_PORT GPIOA
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI1_Init(void);
static void MX_USART1_UART_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();
  MX_USART1_UART_Init();
  /* USER CODE BEGIN 2 */
  // Initialize the MCP492X
  DAC_MCP49x1_Init(&hdac, MCP4921, &hspi1, GPIOA, GPIO_PIN_4, NULL, 0);
   /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
    DAC_MCP49x1_Output(&hdac, 0);
    HAL_Delay(100);
    DAC_MCP49x1_Output(&hdac, 4095);
    HAL_Delay(100);
  }
  /* 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