본문 바로가기

공부/STM32F4

12.[STM32F429] Usart1

반응형

stm32f429 usart1 을 사용해서 printf 로 출력하는 방법 까지 해보겠습니다.

 

PA9 PA10 회로도

PA9 PA10 을 보면 SB11 SB15 를 연결하면 USB 포트를 사용하여 쉽게 USART1을 사용할 수 있다.

보통 초기 상태에서는 연결되어 있으므로 따로 납땜은 안해도 될거 같지만 STM32F429 보드의 아래 면을 확인해주세요.

 

SB11 SB15

 

 

#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 ---------------------------------------------------------*/
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_USART1_UART_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);
}
/* 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_USART1_UART_Init();
  /* USER CODE BEGIN 2 */
  
  printf("https://hnydiy.tistory.com\r\n");
  
  /* USER CODE END 2 */

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

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

결과 화면

 

반응형

'공부 > STM32F4' 카테고리의 다른 글

15.[STM32F429] Timer CH1N CH2N CH3N 사용하기  (0) 2019.08.02
13.[STM32F429] eeprom  (0) 2019.07.17
11.[STM32F429] 터치 스크린 STMPE811QTR  (1) 2019.07.10
10.[STM32F429] LCD  (0) 2019.07.10
9.[STM32F429] LTDC 용어 정리  (0) 2019.07.02