2017-05-30 04:45 AM
Hi. I have STM32F746G-Disco board and problem with its analog out without DMA.
I am using STM32Cube_FW_F7_V1.6.0 withSW4STM32 toolchain and test it with simple LED.
I am a newcomer in STM, I am sure that i am missing something, this is my code:
// Scheme:
// LED R160 // +---|<|-----[==]------[ ] STM32F746G - arduino port A4 // | // | // +---------------------[ ] STM32F746G - arduino port GND #include 'stm32f7xx.h'
#include 'stm32746g_discovery.h'
#include 'stm32746g_discovery_lcd.h'
#include <string.h>
static void SystemClock_Config(void);
static void LCD_Config(void);
static void CPU_CACHE_Enable(void);
DAC_HandleTypeDef DacHandle; ///////////////////////////////////////////////////////////////////////////////
void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
{
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_DAC_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
{
__HAL_RCC_DAC_FORCE_RESET();
__HAL_RCC_DAC_RELEASE_RESET();
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4);
}
///////////////////////////////////////////////////////////////////////////////
int main(void)
{
unsigned int dac1Value = 0xF0FU, dac2Value;
uint8_t outText[32];
DAC_ChannelConfTypeDef sConfig;
CPU_CACHE_Enable();
HAL_Init();
SystemClock_Config();
LCD_Config();
DacHandle.Instance = DAC;
if (HAL_DAC_Init(&DacHandle) != HAL_OK) while(1){}
sConfig.DAC_Trigger = DAC_TRIGGER_NONE;
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
if (HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_1) != HAL_OK) while(1){}
if (HAL_DAC_Start(&DacHandle, DAC_CHANNEL_1) != HAL_OK) while(1){}
while(1)
{
dac1Value+=0x10U;
if (dac1Value >= 0xFFF) dac1Value = 0U;
if (HAL_DAC_SetValue(&DacHandle, DAC_CHANNEL_1, DAC_ALIGN_12B_R, dac1Value) != HAL_OK) while(1){}
dac2Value = HAL_DAC_GetValue(&DacHandle, DAC_CHANNEL_1);
sprintf((char*)outText, '%u %u', dac1Value, dac2Value);
BSP_LCD_Clear(LCD_COLOR_WHITE);
BSP_LCD_DisplayStringAt(10, 10, outText, LEFT_MODE);
HAL_Delay(50U);
}
}
///////////////////////////////////////////////////////////////////////////////
void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
HAL_StatusTypeDef ret = HAL_OK;
/* Enable HSE Oscillator and activate PLL with HSE as source */
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.PLLM = 25;
RCC_OscInitStruct.PLL.PLLN = 400;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 8;
ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
if(ret != HAL_OK) { while(1) { ; } }
/* Activate the OverDrive to reach the 200 MHz Frequency */
ret = HAL_PWREx_EnableOverDrive();
if(ret != HAL_OK) { while(1) { ; } }
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6);
if(ret != HAL_OK) { while(1) { ; } }
}
void LCD_Config(void)
{
BSP_LCD_Init();
BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);
BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS+(BSP_LCD_GetXSize() * BSP_LCD_GetYSize()*4));
BSP_LCD_DisplayOn();
BSP_LCD_SelectLayer(0);
BSP_LCD_Clear(LCD_COLOR_WHITE);
BSP_LCD_SelectLayer(1);
BSP_LCD_Clear(LCD_COLOR_WHITE);
BSP_LCD_SetTransparency(0, 0);
BSP_LCD_SetTransparency(1, 200);
BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
BSP_LCD_SetFont(&Font24);
}
void CPU_CACHE_Enable(void) { SCB_EnableICache(); SCB_EnableDCache(); }
#stm32f746g-discovery
2017-05-30 04:53 AM
What exactly is your problem ?
If you want to drive a LED with the onboard DAC, better check the datasheet (DAC characteristics).
There is a small load/impedance issue ...