Stm32f7-Disco Analog Digital Convert (with DMA )

Stm32f7-Disco Analog Digital Convert (with DMA ). 今回, Stm32f7-Disco board を使って, potentionmeter の値を読みって LCDに表示をやってみます.
1. Clock Setting
RCCのHigh speed Clock -> Enable
System clock ->216Mhz up

 2. Peripherals Setting
ACD1-IN0 Check

(Without DmA)
3. Source generation and edit program
Add source

#include “stm32f7xx_hal.h”
#include “stm32f7xx_hal.h”
#include “stm32f7xx_hal_uart.h”
#include “stm32f7xx_hal_sdram.h”
#include “stm32f7xx_hal_ltdc.h”
#include “stm32746g_discovery.h”
#include “stm32746g_discovery_lcd.h”
#include “stm32746g_discovery_sdram.h”
#include “stm32f7xx_ll_fmc.h”

————————————————- 

int main(void)
{
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC1_Init();

  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_BLACK);
 
  BSP_LCD_SelectLayer(1);
  BSP_LCD_Clear(LCD_COLOR_BLACK);
  BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
  BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);

 
 HAL_ADC_Start(&hadc1);
 int  ADCValue; 

 char buffer[15]; 
  while (1)
  {
        BSP_LCD_Clear(LCD_COLOR_WHITE);
       HAL_ADC_Start(&hadc1);
       ADCValue = HAL_ADC_GetValue(&hadc1);
      
       sprintf(buffer,”ADC_Convert=%d”, ADCValue );
       BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)buffer, CENTER_MODE);
       HAL_Delay(100);

  }
}

(With DMA)

3. DMA configuration
In ADC1 configuration add DMA2 Stream 4

4.Source generation and edit program
In Src/main.c add source

#include “stm32f7xx_hal.h”
#include “stm32f7xx_hal_uart.h”
#include “stm32f7xx_hal_sdram.h”
#include “stm32f7xx_hal_ltdc.h”
#include “stm32746g_discovery.h”
#include “stm32746g_discovery_lcd.h”
#include “stm32746g_discovery_sdram.h”
#include “stm32f7xx_ll_fmc.h”

——————————————————————————————–
int main(void)
{
  HAL_Init();
  /* Configure the system clock */
  SystemClock_Config();
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_ADC1_Init();
  int ADCValue;
  if(HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&ADCValue, 1) !=   HAL_OK)
  {
    Error_Handler();
  }
  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_BLACK);
  BSP_LCD_SelectLayer(1);
  BSP_LCD_Clear(LCD_COLOR_BLACK);
  BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
  BSP_LCD_SetBackColor(LCD_COLOR_WHITE); 

  char buffer[15];
  while (1)
  {
       BSP_LCD_Clear(LCD_COLOR_WHITE);
       sprintf(buffer,”ADC_Convert=%d”, ADCValue );
       BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)buffer, CENTER_MODE);
       HAL_Delay(100);

  }
}
——————————————————————————————————–
 sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
->
 sConfig.SamplingTime = ADC_SAMPLETIME_144CYCLES;

 

Sponsored Links: