//usart.c #include "AT91SAM7S256.h" #include "usart.h" AT91PS_PIO u_pPioA = AT91C_BASE_PIOA; AT91PS_PMC u_pPMC = AT91C_BASE_PMC; AT91PS_USART u_pUSART0 = AT91C_BASE_US0; AT91PS_USART u_pUSART1 = AT91C_BASE_US1; AT91PS_PDC u_pPDC0 = AT91C_BASE_PDC_US0; AT91PS_PDC u_pPDC1 = AT91C_BASE_PDC_US1; AT91PS_MC u_pMC = AT91C_BASE_MC; void InitUSART0(void) { u_pPioA->PIO_PDR = BIT0 | BIT1; //Disables the PIO from controlling the corresponding pin (enables peripheral control of the pin). u_pPioA->PIO_ASR = BIT0 | BIT1; //Assigns the I/O line to the peripheral A function. u_pPioA->PIO_BSR = 0; // peripheral B function set to "no effect" //enable the clock of USART u_pPMC->PMC_PCER = 1<US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS ; //set baud rate divisor register u_pUSART0->US_BRGR = 78; //((47923200)/38400x16) //write the Timeguard Register u_pUSART0->US_TTGR = 0; //Set the USART mode u_pUSART0->US_MR = 0x08c0; //Enable the RX and TX PDC transfer requests // u_pPDC0->PDC_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTEN; //Enable usart - enable RX receiver and TX transmiter u_pUSART0->US_CR = 0x50; } void InitUSART1(void) { u_pPioA->PIO_PDR = BIT5 | BIT6; //Disables the PIO from controlling the corresponding pin (enables peripheral control of the pin). u_pPioA->PIO_ASR = BIT5 | BIT6; //Assigns the I/O line to the peripheral A function. u_pPioA->PIO_BSR = 0; // peripheral B function set to "no effect" //enable the clock of USART u_pPMC->PMC_PCER = 1<US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS ; //set baud rate divisor register u_pUSART1->US_BRGR = 78; //((47923200)/38400x16) //write the Timeguard Register u_pUSART1->US_TTGR = 0; //Set the USART mode u_pUSART1->US_MR = 0x08c0; //Enable the RX and TX PDC transfer requests //u_pPDC1->PDC_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTEN; //Enable usart:enable Transmitter und Receiver, if both are disabled. u_pUSART1->US_CR = 0x50; } void read_write_ch(char* ch){ int i=0; while((u_pUSART1->US_CSR & AT91C_US_RXRDY)==1){ ch[i]= u_pUSART1->US_RHR; if(ch[i] != '\0' ){ while (!(u_pUSART0->US_CSR&AT91C_US_TXRDY)); u_pUSART0->US_THR = ch[i]; } i++; } } int main (void) { char* nmea_data = 0x0; InitUSART0(); InitUSART1(); while (1){ read_write_ch(nmea_data); } }