Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: AT91SAM7S-EK UART -> PC com0 communication
PostPosted: Sat Feb 02, 2008 7:36 pm 
Offline

Joined: Sat Feb 02, 2008 7:22 pm
Posts: 4
Hello!

In my current project I'm trying to communicate with my PC using
the UART port on an AT91SAM7S-EK board. I haven't been able
to get it to work, so I'm wondering if any of you guys could help me
out. This is the code I'm using to set the whole thing up:

Code:
int   main (void)
{
   
   // Initialize the clock
   init();
   // enable the USART peripheral clock
   volatile AT91PS_PMC   pPMC = AT91C_BASE_PMC;         // pointer to PMC data structure
   pPMC->PMC_PCER = (1<<AT91C_ID_US0);
    USART_init();

   // send loop
   while (1)
    {       
        transmit(hello);
        // Delay
        volatile long int i = 0;
        for(; i < 10000000; ++i);
   }
}

void init(void)
{
   AT91PS_PMC     pPMC = AT91C_BASE_PMC;

    //* Set Flash Wait sate
   AT91C_BASE_MC->MC_FMR = ((AT91C_MC_FMCN)&(47 <<16)) | AT91C_MC_FWS_1FWS;

    //* Watchdog Disable
   AT91C_BASE_WDTC->WDTC_WDMR= AT91C_WDTC_WDDIS;

    // 1 Enabling the Main Oscillator:
   pPMC->PMC_MOR = (( AT91C_CKGR_OSCOUNT & (0x06 <<8) | AT91C_CKGR_MOSCEN ));
   
   // Wait the startup time
   while(!(pPMC->PMC_SR & AT91C_PMC_MOSCS));
   
   // Main Clock (MAINCK from crystal oscillator) = 18432000 hz (see AT91SAM7-EK schematic)
   // PLLCK = 1228800 * (MUL + 1) = 1228800 * (74 + 1) = 1228800 * 75 = 92160000 hz
   pPMC->PMC_PLLR = ((AT91C_CKGR_DIV & 15) |
                      (AT91C_CKGR_PLLCOUNT & (10<<8)) |
                      (AT91C_CKGR_MUL & (74<<16)));

   // Wait the startup time (until PMC Status register LOCK bit is set)
   while(!(pPMC->PMC_SR & AT91C_PMC_LOCK));
   
   // PMC Master Clock (MCK) Register setup
   // Note: Master Clock  MCK = 46080000 hz  (this is the CPU clock speed)
   // result:  AT91C_PMC_MCKR = 0x00000007  (Master Clock Register)
   pPMC->PMC_MCKR = AT91C_PMC_CSS_PLL_CLK | AT91C_PMC_PRES_CLK_2;

}

void USART_init(void)
{
    AT91PS_USART usart = AT91C_BASE_US0;

    // Disable PIOA control over pin, enabling USART control
    *AT91C_PIOA_PDR = (AT91C_PA0_RXD0 |        /* Enable RxD0 Pin */
                       AT91C_PA1_TXD0);        /* Enalbe TxD0 Pin */

    *AT91C_PIOA_ASR = (AT91C_PA0_RXD0 |        /* Enable RxD0 Pin */
                       AT91C_PA1_TXD0);        /* Enalbe TxD0 Pin */

    *AT91C_PIOA_PPUER = (AT91C_PA0_RXD0 |        /* Enable pull-up */
                         AT91C_PA1_TXD0);
   
    usart->US_CR = (AT91C_US_RSTRX |          /* Reset Receiver      */
                    AT91C_US_RSTTX |          /* Reset Transmitter   */
                    AT91C_US_RXDIS |          /* Receiver Disable    */
                    AT91C_US_TXDIS);

    usart->US_MR = (AT91C_US_CHRL_8_BITS |
                    AT91C_US_USMODE_NORMAL |
                    AT91C_US_SYNC |
                    4 << 9); // No parity

    usart->US_BRGR = MCK/115200; /* = 115200 baud */
   
    usart->US_CR = (AT91C_US_RXEN  |          /* Receiver Enable     */
                    AT91C_US_TXEN);           /* Transmitter Enable  */
}


void transmit(char *str)
{
    AT91PS_USART usart = AT91C_BASE_US0;

    int i = 0;
    do
    {
        while(usart->US_CSR & AT91C_US_TXRDY == 0);

        usart->US_THR = str[i];

    } while(str[i++]);

    return;
}



Am I doing anything wrong here?

I've got my board hooked up to the serial port of a Linux computer through a null modem cable. The serial port is configured as follows:

Code:
> stty -aF /dev/ttyS0
speed 115200 baud; rows 0; columns 0; line = 0;
intr = M-^C; quit = M-$; erase = G; kill = <undef>; eof = <undef>; eol = <undef>; eol2 = M-z; swtch = M-t; start = +; stop = ^D;
susp = <undef>; rprnt = <undef>; werase = <undef>; lnext = p; flush = <undef>; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon -iexten -echo echoe echok -echonl noflsh xcase tostop echoprt echoctl echoke


Is this configuration correct?

Anyways, any help with this would be greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 05, 2008 5:55 pm 
Offline

Joined: Sat Feb 02, 2008 7:22 pm
Posts: 4
Nevermind, I solved it. The problem was that I was using a mischevious AT91SAM7X256 header masquerading as an AT91SAM7S256 one. Notoriously difficult to discover.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: