找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 7370|回復(fù): 1
收起左側(cè)

stm32l053r8t6的串口收發(fā)送例程分析源碼下載

[復(fù)制鏈接]
ID:98924 發(fā)表于 2015-12-9 01:17 | 顯示全部樓層 |閱讀模式
  關(guān)于stm32l0 nucleo開(kāi)發(fā)板上串口的例程只給了三個(gè)例程,這三個(gè)例程名字文件如下
        UART_TwoBoards_ComDMA,UART_TwoBoards_ComIT,UART_TwoBoards_ComPolling
        大概就是第一個(gè)利用DMA進(jìn)行發(fā)送接收的,第二個(gè)就是中斷發(fā)送接收的,第三個(gè)就是用輪訓(xùn)的方式實(shí)現(xiàn)的,由于三個(gè)例程的并沒(méi)有完全投入大部分精力去搞,所以說(shuō)明顯得很淺顯,如果之前用過(guò)stm32f103系列的,那么這點(diǎn)淺顯的提示也可以提供一定的提示的,在這里我用了類(lèi)似stm32f103的經(jīng)常用的串口方式,就是串口發(fā)送不用中斷,中斷接收模式。
        官方例程原文
        @par Example Description 例程描述

This Example shows a UART transmission (transmit/receive) between 2
STM32L053R8-Nucleo boards in interrupt mode.這個(gè)例子展示了串口的中斷收發(fā)模式。

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.
        一開(kāi)始的主程序通過(guò)這個(gè)函數(shù)來(lái)復(fù)位所有外設(shè),初始化flash系統(tǒng)滴答接口,為了滴答用可能跟flash有關(guān)。

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.
第一塊板子等待按鍵按下后,數(shù)據(jù)發(fā)送給第二個(gè)板子,這里是IT模式,第二塊板子通過(guò)串口中斷接收到數(shù)據(jù)后,再將該數(shù)據(jù)發(fā)送給第一塊板子。如果數(shù)據(jù)
        一樣綠燈亮。
       
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>
*/
實(shí)際上用官方的例程對(duì)于我這個(gè)用慣了stm32f103的庫(kù)函數(shù)的人來(lái)說(shuō),感覺(jué)很別扭,stm32l0的庫(kù)函數(shù)使用HAL 庫(kù)函數(shù)的很麻煩。
        在自己的配置中
        要將這個(gè)函數(shù)放到main循環(huán)中。
        HAL_UART_Receive_IT(&UartHandle, (uint8_t *)aRxBuffer1, 10);

stm32cubel0.zip:下載地址 鏈接:http://pan.baidu.com/s/1mhbXTcG 密碼:4p9x
回復(fù)

使用道具 舉報(bào)

ID:171157 發(fā)表于 2017-3-16 10:47 | 顯示全部樓層
感謝樓主好文
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表