반응형
1. 부품 구입 및 연결도
http://item.gmarket.co.kr/detailview/item.asp?goodscode=1640866563
http://item.gmarket.co.kr/detailview/item.asp?goodscode=1637061530
모터 에는 12V를 넣어주고 보드 구동 전압은 STM32F429 에 보면 3V를 줄수 있는 핀이 있습니다.
그것과 연결 하였습니다.
2. CUBE 설정
LCD 및 터치 스크린 설정
https://hnydiy.tistory.com/216
모터 설정
주파수 계산
90000000 / 3 / 40000 = 750 hz
입니다.
PE8 번은 DIR을 위해서 output으로 빼놓습니다.
3. 코드
일단 저처럼 V7이신분은
https://hnydiy.tistory.com/217
이 오류 부터 해결하세요
main.c 입니다.
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2020 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 */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
DMA2D_HandleTypeDef hdma2d;
I2C_HandleTypeDef hi2c3;
LTDC_HandleTypeDef hltdc;
SPI_HandleTypeDef hspi5;
TIM_HandleTypeDef htim1;
UART_HandleTypeDef huart1;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA2D_Init(void);
static void MX_I2C3_Init(void);
static void MX_LTDC_Init(void);
static void MX_SPI5_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_TIM1_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
int fputc(int ch, FILE *f)
{
uint8_t temp[1]={ch};
HAL_UART_Transmit(&huart1, temp, 1, 2);
return(ch);
}
uint16_t frame_buffer[76800];
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
TS_StateTypeDef TS_State;
static uint32_t x = 0, y = 0;
uint8_t buffer_str[50]={0,};
/* 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_DMA2D_Init();
MX_I2C3_Init();
MX_LTDC_Init();
MX_SPI5_Init();
MX_USART1_UART_Init();
MX_TIM1_Init();
/* USER CODE BEGIN 2 */
printf("test\r\n");
BSP_LCD_Init();
BSP_LCD_LayerDefaultInit(LCD_BACKGROUND_LAYER, (uint32_t)frame_buffer);
BSP_LCD_SelectLayer(LCD_BACKGROUND_LAYER);
BSP_LCD_DisplayOn();
BSP_LCD_Clear(LCD_COLOR_WHITE);
BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
HAL_TIM_OC_Start(&htim1,TIM_CHANNEL_1);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
test_lcd();
}
/* USER CODE END 3 */
}
user_data.c
#include "user_data.h"
TS_StateTypeDef TS_State;
extern TIM_HandleTypeDef htim1;
void test_lcd(void)
{
uint8_t buffer_str[50]={0,};
uint32_t freq=0;
int32_t x=0;
int32_t y=0;
BSP_LCD_Clear(LCD_COLOR_WHITE);
BSP_LCD_SetBackColor(RGB_LCD_COLOR_WHITE);
BSP_LCD_SetTextColor(RGB_LCD_COLOR_BLACK);
BSP_LCD_SetFont(&LCD_20_FONT);
BSP_LCD_DisplayStringAt(0,0, (uint8_t*)"Periode", LEFT_MODE);
BSP_LCD_DisplayStringAt(0,50, (uint8_t*)"Frequency", LEFT_MODE);
BSP_LCD_DrawRect(10, 100, 100, 50);
BSP_LCD_DrawRect(10, 160, 100, 50);
BSP_LCD_DrawRect(10, 220, 100, 50);
BSP_LCD_DrawRect(10, 280, 100, 50);
BSP_LCD_DisplayStringAt(20,120, (uint8_t*)"UP", LEFT_MODE);
BSP_LCD_DisplayStringAt(20,180, (uint8_t*)"DOWN", LEFT_MODE);
BSP_LCD_DisplayStringAt(20,240, (uint8_t*)"STOP", LEFT_MODE);
BSP_LCD_DisplayStringAt(20,300, (uint8_t*)"START", LEFT_MODE);
while(1){
BSP_TS_GetState(&TS_State);
sprintf(buffer_str,"%d ",htim1.Init.Period);
BSP_LCD_DisplayStringAt(0,20, (uint8_t*)buffer_str, LEFT_MODE);
memset(buffer_str,0,50);
freq = 90000000/(htim1.Init.Prescaler+1)/(htim1.Init.Period+1);
sprintf(buffer_str,"%d hz ",freq);
BSP_LCD_DisplayStringAt(0,70, (uint8_t*)buffer_str, LEFT_MODE);
memset(buffer_str,0,50);
if ((TS_State.TouchDetected)){
x = TS_State.X;
y = TS_State.Y;
if((x>=10)&&(x<=100)&&(y>=100)&&(y<=150)){
htim1.Init.Period += 10;
HAL_TIM_OC_Init(&htim1);
printf("upcheck\r\n");
}
else if((x>=10)&&(x<=100)&&(y>=160)&&(y<=210)){
htim1.Init.Period -= 10;
HAL_TIM_OC_Init(&htim1);
printf("dwcheck\r\n");
}
else if((x>=10)&&(x<=100)&&(y>=220)&&(y<=270)){
HAL_TIM_OC_Stop(&htim1,TIM_CHANNEL_1);
printf("stop\r\n");
}
else if((x>=10)&&(x<=100)&&(y>=300)&&(y<=320)){
HAL_TIM_OC_Start(&htim1,TIM_CHANNEL_1);
}
}
HAL_Delay(10);
}
}
user_data.h
#ifndef __USER_DATA_H
#define __USER_DATA_H
#ifdef __cplusplus
extern "C" {
#endif
///////////////code start///////////////////////
#include "stm32f429i_discovery_lcd.h"
#include "stm32f429i_discovery_ts.h"
#define up_point
void test_lcd(void);
//////////////code end///////////////////////////
#ifdef __cplusplus
}
#endif
#endif
결과
반응형
'공부 > STM32F4' 카테고리의 다른 글
18. [STM32F429] SPI Master 와 Slave (0) | 2021.09.08 |
---|---|
stm32cubeIDE (0) | 2020.10.05 |
mpu_arm7.h 에서 에러 (0) | 2020.05.22 |
16. [STM32F429] LCD + 터치 스크린 사용 방법 (6) | 2020.05.22 |
[오류]stm32f429i-disc1 외부전원 사용 시 문제점 (0) | 2020.01.29 |