-->

  • CubeMX & STM32F051C8T6 DAC Kodları


    /* USER CODE BEGIN Header */
    /**
    ******************************************************************************
    * @file : main.c
    * @brief : Main program body
    ******************************************************************************
    * @attention
    *
    * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
    * All rights reserved.</center></h2>
    *
    * This software component is licensed by ST under BSD 3-Clause license,
    * the "License"; You may not use this file except in compliance with the
    * License. You may obtain a copy of the License at:
    * opensource.org/licenses/BSD-3-Clause
    *
    ******************************************************************************
    */
    /* USER CODE END Header */

    /* Includes ------------------------------------------------------------------*/
    #include "main.h"

    /* Private includes ----------------------------------------------------------*/
    /* USER CODE BEGIN Includes */

    /* USER CODE END Includes */

    /* Private typedef -----------------------------------------------------------*/
    /* USER CODE BEGIN PTD */

    /* USER CODE END PTD */

    /* Private define ------------------------------------------------------------*/
    /* USER CODE BEGIN PD */

    const uint16_t _sineWave12bit[90] = {2048,2190,2332,2473,2612,2748,2880,3009,
    3133,3251,3364,3470,3569,3661,3745,3821,
    3888,3946,3995,4034,4064,4084,4094,4094,
    4084,4064,4034,3995,3946,3888,3821,3745,
    3661,3569,3470,3364,3251,3133,3009,2880,
    2748,2612,2473,2332,2190,2048,1905,1763,
    1622,1483,1347,1215,1086,962,844,731,
    625,526,434,350,274,207,149,100,
    61,31,11,1,1,11,31,61,
    100,149,207,274,350,434,526,625,
    731,844,962,1086,1215,1347,1483,1622,
    1763,1905};

    const uint16_t tooth[90] = {91,182,273,364,455,546,637,728,
    819,910,1001,1092,1183,1274,1365,1456,
    1547,1638,1729,1820,1911,2002,2093,2184,
    2275,2366,2457,2548,2639,2730,2821,2912,
    3003,3094,3185,3276,3367,3458,3549,3640,
    3731,3822,3913,4004,4095,4004,3913,3822,
    3731,3640,3549,3458,3367,3276,3185,3094,
    3003,2912,2821,2730,2639,2548,2457,2366,
    2275,2184,2093,2002,1911,1820,1729,1638,
    1547,1456,1365,1274,1183,1092,1001,910,
    819,728,637,546,455,364,273,182,
    91,0};

    /* USER CODE END PD */

    /* Private macro -------------------------------------------------------------*/
    /* USER CODE BEGIN PM */

    /* USER CODE END PM */

    /* Private variables ---------------------------------------------------------*/
    DAC_HandleTypeDef hdac1;

    /* USER CODE BEGIN PV */

    /* USER CODE END PV */

    /* Private function prototypes -----------------------------------------------*/
    void SystemClock_Config(void);
    static void MX_GPIO_Init(void);
    static void MX_DAC1_Init(void);
    /* USER CODE BEGIN PFP */

    /* USER CODE END PFP */

    /* Private user code ---------------------------------------------------------*/
    /* USER CODE BEGIN 0 */

    void sinus()
    {
    for(int i=0;i<90;i++)
    {
    //HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1,DAC_ALIGN_12B_R , Sine12bit[i]);
    HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1,DAC_ALIGN_12B_R , _sineWave12bit[i]);
    }
    }
    void triangle()
    {
    for(int i=0;i<90;i++)
    {
    HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1,DAC_ALIGN_12B_R , tooth[i]);

    }
    }
    void testere()
    {
    for(int i=0;i<=4090;i++)
    {
    HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1,DAC_ALIGN_12B_R , i);
    }
    }


    /* USER CODE END 0 */

    /**
    * @brief The application entry point.
    * @retval int
    */
    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();

    /* USER CODE BEGIN SysInit */

    /* USER CODE END SysInit */

    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_DAC1_Init();
    /* USER CODE BEGIN 2 */
    HAL_DAC_Start(&hdac1, DAC_CHANNEL_1);

    /* USER CODE END 2 */

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


    /* USER CODE BEGIN 3 */
     //  sinus();
    // triangle();
    testere();
    } /* USER CODE END 3 */} /** * @brief System Clock Configuration * @retval None */void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6; RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB busses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) { Error_Handler(); } } /** * @brief DAC1 Initialization Function * @param None * @retval None */static void MX_DAC1_Init(void) { /* USER CODE BEGIN DAC1_Init 0 */ /* USER CODE END DAC1_Init 0 */ DAC_ChannelConfTypeDef sConfig = {0}; /* USER CODE BEGIN DAC1_Init 1 */ /* USER CODE END DAC1_Init 1 */ /** DAC Initialization */ hdac1.Instance = DAC; if (HAL_DAC_Init(&hdac1) != HAL_OK) { Error_Handler(); } /** DAC channel OUT1 config */ sConfig.DAC_Trigger = DAC_TRIGGER_NONE; sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN DAC1_Init 2 */ /* USER CODE END DAC1_Init 2 */ } /** * @brief GPIO Initialization Function * @param None * @retval None */static void MX_GPIO_Init(void) { /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); } /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ /* USER CODE END Error_Handler_Debug */} #ifdef USE_FULL_ASSERT/** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */void assert_failed(char *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */} #endif /* USE_FULL_ASSERT */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  • YOUTUBE KANALIMI ZİYARET EDİN

    Youtube'da seslendirdiğim şiirleri paylaşıyorum. Youtube kanalıma da abone olursanız sevirim.

    Video Of Day

    ADRES

    Kağıthane/İstanbul

    EMAIL

    omersalihgul@gmail.com
    omersalihgul@hotmail.com