/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
/// \dir "Basic USART Hardware Handshaking Project"
///
/// !!!Purpose
///
/// This example demonstrates the hardware handshaking mode (i.e. RTS/CTS)
/// provided by the USART peripherals on AT91 microcontrollers. The practical
/// use of hardware handshaking is that it allows to stop transfer on the USART
/// without losing any data in the process. This is very useful for applications
/// that need to program slow memories for example.
///
/// !!!Requirements
///
/// This example can be used on any AT91 evaluation kit, except when they do
/// not provide an USART serial port (i.e. on AT91SAM9261-EK, AT91SAM7L-EK and
/// AT91SAM7L-STK).
///
/// !!!Description
///
/// The provided program uses hardware handshaking mode to regulate the data
/// rate of an incoming file transfer. A terminal application, such as
/// hyperterminal, is used to send a text file to the device (without any
/// protocol such as X-modem). The device will enforce the configured
/// bytes per second (bps) rate with its Request To Send (RTS) line.
///
/// Whenever the data rate meet or exceed the configurable threshold, the device
/// stops receiving data on the USART. Since no buffer is provided to the PDC,
/// this will set the RTS line, telling the computer to stop sending data. Each
/// second, the current data rate and total number of bytes received are
/// displayed; the transfer is also restarted.
///
/// Note that the device may receive slightly less bytes than the actual file
/// size, depending on the nature of the file. This does NOT mean that bytes
/// have been lost: this is simply an issue with how line breaks are transmitted
/// by the terminal. It is therefore better to use binary files, as they most
/// often do not contain line breaks. For example, send one of the object files
/// generated by the compiler.
///
/// !!!Usage
///
/// -# Build the program and download it inside the evaluation board. Please
/// refer to the <a href="http://www.atmel.com/dyn/resources/prod_documents/doc6224.pdf">SAM-BA User Guide</a>,
/// the <a href="http://www.atmel.com/dyn/resources/prod_documents/doc6310.pdf">GNU-Based Software Development</a>
/// application note or to the <a href="ftp://ftp.iar.se/WWWfiles/arm/Guides/EWARM_UserGuide.ENU.pdf">IAR EWARM User Guide</a>,
/// depending on your chosen solution.
/// -# Connect a serial cable to the USART0 port on the evaluation kit. It will
/// most often be labeled "RS232 COM port".
/// -# On the computer, open and configure a terminal application (e.g.
/// HyperTerminal on Microsoft Windows) with these settings:
/// - 115200 bauds
/// - 8 data bits
/// - No parity
/// - 1 stop bit
/// - Hardware flow control (RTS/CTS)
/// -# Start the application. The following traces shall appear on the terminal:
/// \code
/// -- Basic USART Hardware Handshaking Project xxx --
/// -- AT91xxxxxx-xx
/// -- Compiled: xxx xx xxxx xx:xx:xx --
/// Bps: 0; Tot: 0
/// \endcode
/// -# Send a file in text format to the device. On HyperTerminal, this is done
/// by selecting "Transfer -> Send Text File" (this does not prevent you from
/// sending binary files). The transfer will start and the device will update
/// the bps and total counts on the terminal.
/// -# Whenever the transfer is complete, the total number of bytes received
/// should match the size of the sent file (unless it is a text file, see
/// explanation in description section).
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------
#include <board.h>
#include <pio/pio.h>
#include <usart/usart.h>
#include <tc/tc.h>
#include <aic/aic.h>
#include <pmc/pmc.h>
#include <utility/led.h>
#include <utility/trace.h>
#include <stdio.h>
//------------------------------------------------------------------------------
// Local definition
//------------------------------------------------------------------------------
#ifndef AT91C_ID_TC0
#if defined(AT91C_ID_TC012)
#define AT91C_ID_TC0 AT91C_ID_TC012
#elif defined(AT91C_ID_TC)
#define AT91C_ID_TC0 AT91C_ID_TC
#else
#error Pb define ID_TC
#endif
#endif
/// Maximum Bytes Per Second (BPS) rate that will be forced using the CTS pin.
#define MAX_BPS 500
/// Size of the receive buffer used by the PDC, in bytes.
#define BUFFER_SIZE 1
//------------------------------------------------------------------------------
// Local variables
//------------------------------------------------------------------------------
/// Pins to configure for the application.
const Pin pins[] = {
PINS_DBGU, //debug pin 定义
PIN_USART0_RXD,
PIN_USART0_TXD,
// PIN_USART0_CTS,
// PIN_USART0_RTS
PIN_USART1_RXD,
PIN_USART1_TXD
};
/// Number of bytes received between two timer ticks.
volatile unsigned int bytesReceived = 0;
/// Receive buffer.
unsigned char pBuffer[BUFFER_SIZE];
/// String buffer.
char pString[24];
//------------------------------------------------------------------------------
/// Configures LEDs \#1 and \#2 (cleared by default).
//------------------------------------------------------------------------------
void ConfigureLeds(void)
{
LED_Configure(0);
LED_Configure(1);
LED_Configure(2);
LED_Configure(3);
}
//------------------------------------------------------------------------------
// Local functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// Interrupt handler for USART0. Increments the number of bytes received in the
/// current second and starts another transfer if the desired bps has not been
/// met yet.
//------------------------------------------------------------------------------
void ISR_Usart0(void)
{
unsigned int status;
// LED_Toggle(3);
unsigned char ch ;
// Read USART status
// Receive buffer is full
// if ((status & AT91C_US_RXBUFF) == AT91C_US_RXBUF
没有合适的资源?快使用搜索试试~ 我知道了~
usart-iar.rar_ATMEL USART_IAR的USART查看_at91sam7x512_couragehyf
共156个文件
mac:52个
h:29个
lst:23个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 49 浏览量
2022-09-24
23:41:55
上传
评论 1
收藏 503KB RAR 举报
温馨提示
atmel单片机串口IAR程序,以实验效果非常好,可以移植到项目
资源推荐
资源详情
资源评论
收起资源包目录
usart-iar.rar_ATMEL USART_IAR的USART查看_at91sam7x512_couragehyf (156个子文件)
at91sam7x-ek.cspy.bat 3KB
main.c 14KB
main.c 12KB
pio.c 12KB
pio.c 12KB
usart.c 10KB
usart.c 9KB
cp15.c 9KB
cp15.c 9KB
pmc.c 7KB
pmc.c 7KB
board_lowlevel.c 7KB
board_lowlevel.c 7KB
dbgu.c 6KB
tc.c 5KB
tc.c 5KB
led.c 5KB
printf_usart.c 4KB
printf_usart.c 4KB
aic.c 4KB
aic.c 4KB
board_memories.c 4KB
board_memories.c 4KB
at91sam7x-ek.dbgdt 5KB
at91sam7x-ek.dep 18KB
at91sam7x-ek.dni 548B
at91sam7x-ek.ewd 103KB
at91sam7x-ek.ewd 103KB
at91sam7x-ek.ewp 134KB
at91sam7x-ek.ewp 115KB
basic-usart-hw-handshaking-project.eww 915B
basic-usart-hw-handshaking-project.eww 915B
AT91SAM7X512.h 213KB
AT91SAM7X512.h 213KB
AT91SAM7X256.h 208KB
AT91SAM7X256.h 208KB
AT91SAM7X128.h 208KB
AT91SAM7X128.h 208KB
board.h 21KB
board.h 21KB
trace.h 9KB
trace.h 9KB
pio.h 7KB
pio.h 7KB
usart.h 5KB
usart.h 5KB
assert.h 4KB
assert.h 4KB
cp15.h 3KB
cp15.h 3KB
dbgu.h 3KB
dbgu.h 3KB
aic.h 3KB
aic.h 3KB
led.h 3KB
tc.h 3KB
tc.h 3KB
pmc.h 2KB
pmc.h 2KB
board_memories.h 2KB
board_memories.h 2KB
flash.icf 2KB
flash.icf 2KB
flash.icf 2KB
flash.icf 2KB
flash.icf 2KB
flash.icf 2KB
sram.icf 2KB
sram.icf 2KB
sram.icf 2KB
sram.icf 2KB
sram.icf 2KB
sram.icf 2KB
at91sam7x-ek_at91sam7x256_sram.jlink 205B
main.lst 45KB
main.lst 45KB
pio.lst 33KB
pio.lst 33KB
pmc.lst 32KB
pmc.lst 32KB
usart.lst 31KB
usart.lst 31KB
board_lowlevel.lst 22KB
board_lowlevel.lst 22KB
dbgu.lst 22KB
dbgu.lst 22KB
led.lst 19KB
led.lst 19KB
cp15.lst 18KB
cp15.lst 18KB
tc.lst 17KB
tc.lst 17KB
printf_usart.lst 15KB
aic.lst 13KB
aic.lst 13KB
board_memories.lst 13KB
board_memories.lst 13KB
at91sam9m10-ek-ddram.mac 11KB
at91sam9m10-ek-ddram.mac 11KB
at91sam9263-ek-sdram.mac 10KB
共 156 条
- 1
- 2
资源评论
- m0_688086372023-10-03资源是宝藏资源,实用也是真的实用,感谢大佬分享~
我虽横行却不霸道
- 粉丝: 75
- 资源: 1万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功