zoukankan      html  css  js  c++  java
  • stm32L011F3——串口实例

      /* STM32L0xx HAL library initialization:
           - Configure the Flash prefetch, Flash preread and Buffer caches
           - Systick timer is configured by default as source of time base, but user 
                 can eventually implement his proper time base source (a general purpose 
                 timer for example or other time source), keeping in mind that Time base 
                 duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
                 handled in milliseconds basis.
           - Low Level Initialization
         */
      HAL_Init();
    
      /* Configure the system clock to 2 MHz */
      SystemClock_Config();
    
      /* Initialize BSP Led for LED3 */
      BSP_LED_Init(LED3);
    
      /*##-1- Configure the UART peripheral ######################################*/
      /* Put the USART peripheral in the Asynchronous mode (UART Mode) */
      /* UART configured as follows:
          - Word Length = 8 Bits (7 data bit + 1 parity bit) : 
                          BE CAREFUL : Program 7 data bits + 1 parity bit in PC HyperTerminal
          - Stop Bit    = One Stop bit
          - Parity      = ODD parity
          - BaudRate    = 9600 baud
          - Hardware flow control disabled (RTS and CTS signals) */
      UartHandle.Instance        = USARTx;
    
      UartHandle.Init.BaudRate   = 9600;
      UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
      UartHandle.Init.StopBits   = UART_STOPBITS_1;
      UartHandle.Init.Parity     = UART_PARITY_ODD;
      UartHandle.Init.HwFlowCtl  = UART_HWCONTROL_NONE;
      UartHandle.Init.Mode       = UART_MODE_TX_RX;
      if (HAL_UART_Init(&UartHandle) != HAL_OK)
      {
        /* Initialization Error */
        Error_Handler();
      }
    
      /* Output a message on Hyperterminal using printf function */
      printf("
    
     UART Printf Example: retarget the C library printf function to the UART
    
    ");
      printf("** Test finished successfully. ** 
    
    ");
    
      /* Infinite loop */
      while (1)
      {
      }

    上述代码中,将串口设置为奇校验,因此串口助手应该设置如下,注意数据位为7

    如果设置为UART_PARITY_NONE,则:

    一般情况下,通常都是UART_PARITY_NONE的。

  • 相关阅读:
    P1474 货币系统 Money Systems(完全背包求填充方案数)
    Codeforces 877C Slava and tanks(思维)
    883H
    Codeforces 873B
    POJ 1733 Parity game(带权并查集)
    POJ 2387 Til the Cows Come Home(dijkstra裸题)
    POJ 1984 Navigation Nightmare(二维带权并查集)
    POJ 2912 Rochambeau(种类并查集+枚举)
    POJ 1456 Supermarket(贪心+并查集)
    POJ 2492 A Bug's Life(带权并查集)
  • 原文地址:https://www.cnblogs.com/CodeWorkerLiMing/p/10438728.html
Copyright © 2011-2022 走看看