#include /* AT91RM9200 definitions */ #include /* Library function definitions */ #define LED_NUM 3 /* Number of LEDs */ #define MCK 60000000 #define BAUDRATE 115200 #define US1_ID 7 const int led_mask[] = { AT91C_PIO_PB0, AT91C_PIO_PB1, AT91C_PIO_PB2 }; volatile int i = 0, length = 0, my_flag = 0, y = 0; char transmit_buffer[20]; char receive_buffer[20]; //------------------------------------------------------------------------------- __irq void UART_Handler (void) { if(AT91C_BASE_US1-> US_CSR & AT91C_US_RXRDY) // Receive Complete { if(y++ == 0xff){y=0;} receive_buffer[y] = AT91F_US_GetChar ((AT91PS_USART)AT91C_BASE_US1); switch(my_flag) { case 1 : // clear LED's { AT91F_PIO_SetOutput((AT91PS_PIO) AT91C_BASE_PIOB, AT91C_PIO_PB0 | AT91C_PIO_PB1 | AT91C_PIO_PB2); my_flag = 0; break; } case 0 : // set LED's { AT91F_PIO_ClearOutput((AT91PS_PIO) AT91C_BASE_PIOB, AT91C_PIO_PB0 | AT91C_PIO_PB1 | AT91C_PIO_PB2); my_flag = 1; break; } } } if(AT91C_BASE_US1->US_CSR & AT91C_US_TXRDY) // Transmit Complete { //... } *AT91C_AIC_EOICR = *AT91C_US1_CSR; } //------------------------------------------------------------------------------- int main (void) { //*************** IO LED's ************************************************* // Configure the PIO Lines corresponding to USER LED1 .. USER LED3 as Outputs AT91C_BASE_PIOB->PIO_OER = AT91C_PIO_PB0 | AT91C_PIO_PB1 | AT91C_PIO_PB2; // Enable the Clock of the PIO for LEDs AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB; // Clear the LED's. On the Board we must apply a "1" to turn off LEDs AT91C_BASE_PIOB->PIO_SODR = AT91C_PIO_PB0 | AT91C_PIO_PB1 | AT91C_PIO_PB2; //-------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------- //********************* UART 1 *********************************************** // UART IO_Pin Config AT91F_PIO_CfgPeriph(AT91C_BASE_PIOB,(unsigned int) AT91C_PB20_TXD1 |(unsigned int) AT91C_PB21_RXD1, 0); // UART setting Config AT91F_US_Configure ((AT91PS_USART) AT91C_BASE_US1, MCK, AT91C_US_ASYNC_MODE, BAUDRATE , 0); // Enable Per.Clock for UART_1 AT91F_US1_CfgPMC (); //Disable all Interrupts AT91C_BASE_US1->US_IDR = 0xffff; // AIC Enable UART_1 INT AT91C_BASE_AIC->AIC_SVR[US1_ID] = (unsigned int) UART_Handler; AT91C_BASE_AIC->AIC_IECR |= (1<AIC_SMR[US1_ID] = AT91C_AIC_SRCTYPE_INT_EDGE_TRIGGERED; // Reset UART AT91C_BASE_US1->US_CR |= AT91C_US_RSTSTA; // Enable Transmitter AT91F_US_EnableTx((AT91PS_USART) AT91C_BASE_US1); //Reset Transmitter and re-enable it AT91F_US_ResetTx ((AT91PS_USART)AT91C_BASE_US1); // Enable Receiver AT91F_US_EnableRx((AT91PS_USART) AT91C_BASE_US1); //Reset Receiver and re-enable it AT91F_US_ResetRx ((AT91PS_USART)AT91C_BASE_US1); //Enable US_1 Interrupt AT91C_BASE_US1->US_IER = AT91C_US_RXRDY |AT91C_US_TXRDY; while(1) {}; }