Hello. I am very new in ARM7. I am trying to enable dual UART for AT91SAM7X256 MCU. I have already simulate the Hello example code for simple LED Blink and UART0 Data Send. Its working fine.
Can any one suggest me how can I send and receive data from UART1 of AT91SAM7X256 MCU?
I know that AT91SAM7X-EK have single UART only, but I am trying to enable dual UART with external connection.
Thank you. Waiting for your reply.
Regards. Sakibnaz.
Did you read the datasheets for the processor and any documentation from the chip manufacturer?
If you do find people who knows how to use that second UART, they most probably know because they _did_read the available documentation.
So, what information have you read?
Hello. Thanks for you reply. I checked the SAM7X256 Data-sheet carefully and able to enable UART1. My Serial.C is below presented for Both UART0 and UART1:
****************************************************************************************** #include <AT91SAM7X256.H>
#define BR 115200 #define AT91B_MCK ((18432000*73/14)/2) #define BRD (AT91B_MCK/16/BR)
AT91S_USART * pUSART0 = AT91C_BASE_US0; AT91S_USART * pUSART1 = AT91C_BASE_US1;
void init_UART0 (void) {
*AT91C_PMC_PCER = (1 << AT91C_ID_PIOA) | (1 << AT91C_ID_US0);
*AT91C_PIOA_PDR = AT91C_PA0_RXD0 | AT91C_PA1_TXD0;
pUSART0->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS;
pUSART0->US_MR = AT91C_US_USMODE_NORMAL | AT91C_US_CLKS_CLOCK | AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE | AT91C_US_NBSTOP_1_BIT;
pUSART0->US_BRGR = BRD;
pUSART0->US_CR = AT91C_US_RXEN | AT91C_US_TXEN; }
int sendchar_UART0 (int ch) {
if (ch == '\n') { while (!(pUSART0->US_CSR & AT91C_US_TXRDY)); pUSART0->US_THR = '\r'; } while (!(pUSART0->US_CSR & AT91C_US_TXRDY)); return (pUSART0->US_THR = ch); }
int getkey_UART0 (void) {
while (!(pUSART0->US_CSR & AT91C_US_RXRDY)); return (pUSART0->US_RHR); }
void init_UART1 (void) {
*AT91C_PMC_PCER = (1 << AT91C_ID_PIOA) | (1 << AT91C_ID_US1);
*AT91C_PIOA_PDR = AT91C_PA5_RXD1 | AT91C_PA6_TXD1;
pUSART1->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS;
pUSART1->US_MR = AT91C_US_USMODE_NORMAL | AT91C_US_CLKS_CLOCK | AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE | AT91C_US_NBSTOP_1_BIT;
pUSART1->US_BRGR = BRD;
pUSART1->US_CR = AT91C_US_RXEN | AT91C_US_TXEN; }
int sendchar_UART1 (int ch) {
if (ch == '\n') { while (!(pUSART1->US_CSR & AT91C_US_TXRDY)); pUSART1->US_THR = '\r'; } while (!(pUSART1->US_CSR & AT91C_US_TXRDY)); return (pUSART1->US_THR = ch); }
int getkey_UART1 (void) {
while (!(pUSART1->US_CSR & AT91C_US_RXRDY)); return (pUSART1->US_RHR); } ******************************************************************************************
I can send data ether UART0 or UART1 by using init_UART0() or init_UART1(). But can not able to enable both UART's together. Also I am confused about the printf function which is using by the Hello.C to send Serial Data. So how can I define this data transmitting function individual for UART0 and UART1 (like printf_UART0 and printf_UART1)? Or how can I use the sednchar function? I am very new in ARM7. Need suggestion please.