stm32L011F3——串口实例

本文详细介绍了STM32L0微控制器的串口初始化过程,包括HAL库的使用、系统时钟配置、LED初始化及串口参数设置。特别强调了奇校验的配置方法,并提供了代码示例。
  /* 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("\n\r UART Printf Example: retarget the C library printf function to the UART\n\r");
  printf("** Test finished successfully. ** \n\r");

  /* Infinite loop */
  while (1)
  {
  }

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

如果设置为UART_PARITY_NONE,则:

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

转载于:https://www.cnblogs.com/CodeWorkerLiMing/p/10438728.html

STM32L011D4P6仅仅14个引脚,本评估板有2颗用户LED,1个用户按键,1个复位按键,引出全部IO,板载TI开关电源芯片tps563200,输入电压范围4.5V——17V,设计输出电压5V,最大输出电流3A,另外板载TI电平转换芯片TXB0104,以拓展4个5VGPIO。可用于驱动5V逻辑器件,例如RGB5050 WS2812B。 以下是STM32L011D4P6的官网介绍: The access line ultra-low-power STM32L011xx family incorporates the high-performance ARM:registered: Cortex:registered:-M0+ 32-bit RISC core operating at a 32 MHz frequency, high-speed embedded memories (up to 16 Kbytes of Flash program memory, 512 bytes of data EEPROM and 2 Kbytes of RAM) plus an extensive range of enhanced I/Os and peripherals. The STM32L011xx devices provide high power efficiency for a wide range of performance. It is achieved with a large choice of internal and external clock sources, an internal voltage adaptation and several low-power modes. The STM32L011xx devices offer several analog features, one 12-bit ADC with hardware oversampling, two ultra-low-power comparators, several timers, one low-power timer (LPTIM), three general-purpose 16-bit timers, one RTC and one SysTick which can be used as timebases. They also feature two watchdogs, one watchdog with independent clock and window capability and one window watchdog based on bus clock. Moreover, the STM32L011xx devices embed standard and advanced communication interfaces: one I2C, one SPI, one USART, and a low-power UART (LPUART). The STM32L011xx also include a real-time clock and a set of backup registers that remain powered in Standby mode. The ultra-low-power STM32L011xx devices operate from a 1.8 to 3.6 V power supply (down to 1.65 V at power down) with BOR and from a 1.65 to 3.6 V power supply without BOR option. They are available in the -40 to +125 °C temperature range. A comprehensive set of power-saving modes allows the design of low-power applications. Key Features Ultra-low-power platform1.65 V to 3.6 V power supply -40 to 125 °C temperature range 0.23 μA Standby mode (2 wakeup pins) 0.29 μA Stop mode (16 wakeup lines) 0.54 μA Stop mode + RTC + 2 KB RAM retention Down to 76 μA/MHz in Run m
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值