void Usart_Init ( void ) { AT91PS_USART COM0 = AT91C_BASE_US0; AT91PS_USART COM1 = AT91C_BASE_US1;
//* Configure PIO controllers to periph mode AT91F_PIO_CfgPeriph( AT91C_BASE_PIOA, ((unsigned int) AT91C_PA21_RXD1 ) | ((unsigned int) AT91C_PA22_TXD1 ) | ((unsigned int) AT91C_PA5_RXD0 ) | ((unsigned int) AT91C_PA6_TXD0 ) , // Peripheral A 0); // Peripheral B
// First, enable the clock of the PIOB AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_US1 ) ; AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_US0 ) ; // Usart Configure AT91F_US_Configure (COM1, MCK, AT91C_US_ASYNC_MODE, SciBaudRate, 0); AT91F_US_Configure (COM0, MCK, AT91C_US_ASYNC_MODE, SciBaudRate, 0);
// Enable usart COM1->US_CR = AT91C_US_RXEN | AT91C_US_TXEN; COM0->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;
//* Enable USART IT error and RXRDY AT91F_US_EnableIt(COM1,AT91C_US_TIMEOUT | AT91C_US_FRAME | AT91C_US_OVRE |AT91C_US_RXRDY); AT91F_US_EnableIt(COM0,AT91C_US_TIMEOUT | AT91C_US_FRAME | AT91C_US_OVRE |AT91C_US_RXRDY); //AT91F_US_EnableIt(COM1,AT91C_US_RXRDY);
//* open Usart interrupt AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC, AT91C_ID_US1, USART_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, Usart_232_irq_handler); //AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC, AT91C_ID_US0, USART_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, Usart_485_irq_handler); AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_US1); AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_US0);
COM1->US_RTOR = 20; //超时时间设定为20个字符时间 COM0->US_RTOR = 20; //超时时间设定为20个字符时间 } |