我用的是at91sam7x256芯片,怎么调串口也调不通,不知道哪里出问题了。不过要是把以前我写的一个可以正常运行的程序(包括串口驱动)下载到板子上以后就可以正常运行了,如果把板子清空,就又不能运行了,可能是初始化时错了,但又找不出来,大家帮帮啊,谢谢了啊。 源代码如下:
#include "/include/at91sam7S64/at91sam7s64.h" #include "/include/at91sam7s64/lib_at91sam7s64.h"
void AT91F_LowLevelInit(void); void usart0_init(void); void usart0_write(char * tx_buffer, unsigned int tx_counter);
#define MCLK 48000000 #define BAUD 19200
int CMain(void) { int index = 500000; AT91F_LowLevelInit(); usart0_init(); while(1) { usart0_write("Hello, World!
", 14); while(index--); index = 500000; } return 0; }
void AT91F_LowLevelInit(void) { //Disables the Watchdog Timer AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS; //Enabling the Main Oscillator AT91C_BASE_PMC->PMC_MOR = 0x01 | 0x07 << 8; while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS)) //Setting PLL and divider AT91C_BASE_PMC->PMC_PLLR = 24 | (0x28 << 8) | (124 << 16) | AT91C_CKGR_USBDIV_1; while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK)); while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY)); //Selection of Processor Clock AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2; while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY)); //Selection of Master Clock AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK; while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY)); }
void usart0_init(void) { AT91F_US0_CfgPMC(); AT91F_US0_CfgPIO(); AT91F_US_Configure( AT91C_BASE_US0, MCLK, AT91C_US_ASYNC_MODE, BAUD, 0); AT91C_BASE_US0->US_CR = AT91C_US_RXEN | AT91C_US_TXEN | AT91C_US_STTTO; }
void usart0_write(char * tx_buffer, unsigned int tx_counter) { AT91C_BASE_PDC_US0->PDC_TPR = (unsigned int)tx_buffer; AT91C_BASE_PDC_US0->PDC_TCR = tx_counter; AT91F_PDC_EnableTx (AT91C_BASE_PDC_US0); //while (AT91C_BASE_PDC_US0->PDC_TCR & 0xFFFF); }
|