// ---------------------------------------------------------------------------- // ARM - EVLUATION FOR AT91SAM7X256 // ---------------------------------------------------------------------------- // File Name : USART_TEST.c // Object : main application written in C // Creation : 18-Sep-2007 // ----------------------------------------------------------------------------
//USART.C文件
//**************** USART串口测试程序:USART1 *********************
#include "main.h"
#define USART_INTERRUPT_LEVEL 7 #define AT91_BAUD_RATE 115200 static const char atmel_header[]= { "\n\r *** ATMEL Usart IRQ ***\n\r" "Copyright (C) 2005 ATMEL Corporations Version: 1.0\n\r" };
char rbuf[64];
AT91PS_USART COM0 = AT91C_BASE_US1;
#define AT91C_US_ASYNC_MODE ( AT91C_US_USMODE_NORMAL + \ AT91C_US_NBSTOP_1_BIT + \ AT91C_US_PAR_NONE + \ AT91C_US_CHRL_8_BITS + \ AT91C_US_CLKS_CLOCK )
//*------------------------- Internal Function --------------------------------
//*---------------------------------------------------------------------------- //* Function Name : Usart_c_irq_handler //* Object : C handler interrupt function calAT91B_LED by the interrupts //* assembling routine //* Input Parameters : <RTC_pt> time rtc descriptor //* Output Parameters : increment count_timer0_interrupt //*---------------------------------------------------------------------------- void Usart_c_irq_handler(void) { AT91PS_USART USART_pt = AT91C_BASE_US1; unsigned int status; //* get Usart status register status = USART_pt->US_CSR; if ( status & AT91C_US_RXRDY){ //* Get byte and send //AT91F_US_PutChar (USART_pt, AT91F_US_GetChar(USART_pt)); }
if ( status & AT91C_US_OVRE) { //* clear US_RXRDY AT91F_US_ReceiveFrame(USART_pt,(char *)rbuf,sizeof(rbuf),0,0); AT91F_US_PutChar (USART_pt, 'O'); }
//* Check error if ( status & AT91C_US_PARE) { AT91F_US_PutChar (USART_pt, 'P'); }
if ( status & AT91C_US_FRAME) { AT91F_US_PutChar (USART_pt, 'F'); }
if ( status & AT91C_US_TIMEOUT){ USART_pt->US_CR = AT91C_US_STTTO; AT91F_US_PutChar (USART_pt, 'T'); }
//* Reset the satus bit USART_pt->US_CR = AT91C_US_RSTSTA; } //*-------------------------- External Function -------------------------------
//*---------------------------------------------------------------------------- //* Function Name : Usart_init //* Object : USART initialization //* Input Parameters : none //* Output Parameters : TRUE //*---------------------------------------------------------------------------- void Usart_init ( void ) //* Begin { //* Configure PIO controllers to periph mode AT91F_PIO_CfgPeriph( AT91C_BASE_PIOA, ((unsigned int) AT91C_PA5_RXD1 ) | ((unsigned int) AT91C_PA6_TXD1 ) | ((unsigned int) AT91C_PA8_RTS1 ) | ((unsigned int) AT91C_PA9_CTS1 ), // Peripheral A 0); // Peripheral B
// First, enable the clock of the USART AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_US1 ) ; // Usart Configure AT91F_US_Configure (COM0, AT91C_MASTER_CLOCK, AT91C_US_ASYNC_MODE, AT91_BAUD_RATE, 0);
// Enable usart COM0->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;
//* open Usart 1 interrupt AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC, AT91C_ID_US1, USART_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, Usart_c_irq_handler); AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_US1); //* Enable USART IT error and RXRDY AT91F_US_EnableIt(COM0,AT91C_US_ENDRX);
AT91F_US_Put('X');
AT91F_US_SendFrame(COM0,(char *)atmel_header,sizeof(atmel_header),0,0); AT91F_US_ReceiveFrame(COM0,(char *)rbuf,sizeof(rbuf),0,0); //* End }
///////////////////////////////////////////////////////////////////////////////////
//MAIN,C文件
// ---------------------------------------------------------------------------- // ARM - EVLUATION FOR AT91SAM7X256 // ---------------------------------------------------------------------------- // File Name : main.c // Object : main application written in C // Creation : 18-Sep-2007 // ----------------------------------------------------------------------------
#include "main.h" #include "mii.h" #include "emac.h"
extern void Usart_init (void);
//*------------------------------------------------------------------------- //* Function Name : Main //* Object : Software entry point //*-------------------------------------------------------------------------- void main(void) { /************************ 初始化 *************************/ unsigned int loop_count ; AT91PS_AIC pAic; //* Load System pAic Base address pAic = AT91C_BASE_AIC;
//* Enable User Reset and set its minimal assertion to 960 us AT91C_BASE_RSTC->RSTC_RMR = AT91C_RSTC_URSTEN | (0x4<<8) | (unsigned int)(0xA5<<24);
//* Init loop_count = 0 ; PIO_Init(); //* Init Usart Usart_init();
//* generate software interrupt AT91F_AIC_Trig (pAic,AT91C_ID_SYS) ;
while(1) {} }
为什么数据能收到,也能发出,就是死活进不了中断,IMR,CSR都有相应的屏蔽
|