All, after getting OpenOCD to support the flash in the AT91SAM7SE I’ve been piddling around with some code. I’m able to toggle LEDs and use the GPIO with ease. However, I am having some serious problems with the USART in the chip. I’m using the AT91SAM7SE-EK board. I’m attempting to use the follow code. I’m expecting that I will get a continuous stream of data coming out of the TXD0 pin. I get no data in HyperTerminal. When I have an oscilloscope hooked up to the pin signal is held high. I’m using the following code:
#include "AT91SAM7SE512.h"
int main()
{
// Setup the waitstates of the flash at 48MHz
AT91C_BASE_MC->MC0_FMR = AT91C_MC_FWS_2FWS;
AT91C_BASE_MC->MC1_FMR = AT91C_MC_FWS_2FWS;
// Enable the main oscillator (18.432 MHz)
AT91C_BASE_PMC->PMC_MOR = (AT91C_CKGR_OSCOUNT & (0x40 << 8)) | AT91C_CKGR_MOSCEN;
// Wait for the startup time of the oscilator to ellapse
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS))
;
AT91C_BASE_PMC->PMC_PLLR = AT91C_CKGR_USBDIV_1 |
AT91C_CKGR_OUT_0 |
(16 << 8) |
(AT91C_CKGR_MUL & (72 << 16)) |
(AT91C_CKGR_DIV & 14);
// Wait for the PLL startup time to ellapse
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK))
;
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY))
;
// Set the clock divider to 2
AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
// Wait for the prescaler to take effect
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY))
;
// Select the PLL as the clock source
AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK;
// Wait for the clock to switch
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY))
;
/* Enable the USART now... */
// Enable the clock for US0
AT91C_BASE_PMC->PMC_PCER = (1<<AT91C_ID_US0);
// Disable the PIO on pins 5 and 6 of PIOA
AT91C_BASE_PIOA->PIO_PDR = AT91C_PIO_PA5 | AT91C_PIO_PA6;
// Select pins 5 and 6 for use by the periph
AT91C_BASE_PIOA->PIO_ASR = AT91C_PA5_RXD0 |
AT91C_PA6_TXD0;
// Disable and reset the transmitter and reciever
AT91C_BASE_US0->US_CR = AT91C_US_RSTTX |
AT91C_US_RSTRX |
AT91C_US_TXDIS |
AT91C_US_RXDIS;
// Set us up for normal mode 8, N, 1 using MCK
AT91C_BASE_US0->US_MR = AT91C_US_USMODE_NORMAL |
AT91C_US_CLKS_CLOCK |
AT91C_US_CHRL_8_BITS |
AT91C_US_PAR_NONE |
AT91C_US_NBSTOP_1_BIT;
// Set the divider to 313 this is approximately 9600
// with a ~48 MHz clock
AT91C_BASE_US0->US_BRGR = 313;
// Enable the transmitter nad reciever
AT91C_BASE_US0->US_CR = AT91C_US_TXEN |
AT91C_US_RXEN;
/* Send some data on the USART now */
while(1)
{
// Wait until TXRDY is set
while (!(AT91C_BASE_US0->US_CSR & AT91C_US_TXRDY))
{
}
// Set teh byte in THR
AT91C_BASE_US0->US_THR = 'A';
}
return 0;
}
Does anything look absolutely incorrect with that code?
Thanks for the assistance.
-Jerry.