stm32l053r8t6的串口收发送例程分析源码下载

关于stm32l0 nucleo开发板上串口的例程只给了三个例程,这三个例程名字文件如下

UART_TwoBoards_ComDMA,UART_TwoBoards_ComIT,UART_TwoBoards_ComPolling

大概就是第一个利用DMA进行发送接收的,第二个就是中断发送接收的,第三个就是用轮训的方式实现的,由于三个例程的并没有完全投入大部分精力去搞,所以说明显得很浅显,如果之前用过stm32f103系列的,那么这点浅显的提示也可以提供一定的提示的,在这里我用了类似stm32f103的经常用的串口方式,就是串口发送不用中断,中断接收模式。

官方例程原文

@par Example Description 例程描述

This Example shows a UART transmission (transmit/receive) between 2 
STM32L053R8-Nucleo boards in interrupt mode.这个例子展示了串口的中断收发模式。

At the beginning of the main program the HAL_Init() function is called to reset 
all the peripherals, initialize the Flash interface and the systick.
Then the SystemClock_Config() function is used to configure the system
clock (SYSCLK) to run at 32 MHz.

一开始的主程序通过这个函数来复位所有外设,初始化flash系统滴答接口,为了滴答用可能跟flash有关。

Then 1st board is waiting for user button key to be pressed. Once done, data 
are transmitted through uart2 in IT mode. 2nd board has configured Uart2 
to receive data in IT mode. Once data received is completed, 2nd board also 
transmit same characters on uart1 which will be received by 1st board.
Both boards compare transmitted data to received ones. If they are same, green 
led2 is turn on, else led2 is turn Off.
第一块板子等待按键按下后,数据发送给第二个板子,这里是IT模式,第二块板子通过串口中断接收到数据后,再将该数据发送给第一块板子。如果数据

一样绿灯亮。


Warning: As both boards do not behave same way, "TRANSMITTER_BOARD" switch 
compilation exists to determine either software is for 1st transmitter board or 
2nd receiver (then transmitter) board. In other words, 1st board has to be 
flashed with software compiled with switch enable, 2nd board has to be flashed 
with software compiled with switch disable.

LED2 can be used to monitor the transfer status:
 - LED2 turns ON on master board waiting user button to be pressed.
 - LED2 turns OFF on master board waiting the transmission process is complete.
 - LED2 turns ON when the transmission/reception process is correct.    

The UART is configured as follow:
    - BaudRate = 9600 baud  
    - Word Length = 8 Bits (7 data bit + 1 parity bit)
    - One Stop Bit
    - None parity
    - Hardware flow control disabled (RTS and CTS signals)
    - Reception and transmission are enabled in the time

@note USARTx/UARTx instance used and associated resources can be updated in "main.h"
file depending hardware configuration used.

@note When the parity is enabled, the computed parity is inserted at the MSB
position of the transmitted data.

@note Care must be taken when using HAL_Delay(), this function provides accurate
      delay (in milliseconds) based on variable incremented in SysTick ISR. This
      implies that if HAL_Delay() is called from a peripheral ISR process, then 
      the SysTick interrupt must have higher priority (numerically lower)
      than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
      To change the SysTick interrupt priority you have to use HAL_NVIC_SetPriority() function.
      
@note The application need to ensure that the SysTick time base is always set to 1 millisecond
      to have correct HAL operation.

@par Directory contents 

  - UART/UART_TwoBoards_ComIT/Inc/stm32l0xx_hal_conf.h    HAL configuration file
  - UART/UART_TwoBoards_ComIT/Inc/stm32l0xx_it.h          IT interrupt handlers header file
  - UART/UART_TwoBoards_ComIT/Inc/main.h                  Header for main.c module  
  - UART/UART_TwoBoards_ComIT/Src/stm32l0xx_it.c          IT interrupt handlers
  - UART/UART_TwoBoards_ComIT/Src/main.c                  Main program
  - UART/UART_TwoBoards_ComIT/Src/stm32l0xx_hal_msp.c     HAL MSP module
  - UART/UART_TwoBoards_ComIT/Src/system_stm32l0xx.c      STM32L0xx system source file


@par Hardware and Software environment 

  - This example runs on STM32L051xx, STM32L052xx, STM32L053xx STM32L062xx and 
    STM32L063xx device lines RevZ
    
  - This example has been tested with STM32L053R8-Nucleo RevC and can be
    easily tailored to any other supported device and development board.

  - STM32L053R8-Nucleo RevC Set-up
    - Connect a wire between 1st board PA9 (pin 21 in CN10 connector) pin (Uart Tx) 
      to 2nd board PA10 (pin 33 in CN10 connector) pin (Uart Rx)
    - Connect a wire between 1st board PA10 (pin 33 in CN10 connector) pin (Uart Rx)
      to 2nd board PA9 (pin 21 in CN10 connector) pin (Uart Tx)
 
  
@par How to use it ? 

In order to make the program work, you must do the following :
 - Open your preferred toolchain 
 - Rebuild all files and load your image into target memory
 - Run the example
       
 * <h3><center>&copy; COPYRIGHT STMicroelectronics</center></h3>
 */
实际上用官方的例程对于我这个用惯了stm32f103的库函数的人来说,感觉很别扭,stm32l0的库函数使用HAL 库函数的很麻烦。

在自己的配置中

要将这个函数放到main循环中。

HAL_UART_Receive_IT(&UartHandle, (uint8_t *)aRxBuffer1, 10);


下载地址 链接:http://pan.baidu.com/s/1mhbXTcG 密码:4p9x

sitemap