小弟出现这个问题已经很久了,一直都没有解决还请各位高手帮我一下。 #include "RF.h" short unsigned int txbuff[158]; short unsigned int rxbuff[5]={0xf802,0xf810,0xf806,0xf80c,0xf838}; short unsigned int dsbuff[2]={0xf880,0xfa31};
int main(void) {//初始化DB uint i=0,k=0; short unsigned int *index; unsigned int *in; unsigned int rxb[1]; for(;i<=78;i++) { txbuff=0xf880+((i/2)); ++i; txbuff=0xfa20; } for(i=79;i<=158;i++) { txbuff=0xf8c0+(((i-79)/2)); ++i; txbuff=0xfa20; } AT91F_DBGU_CfgPIO();//DBGU管脚分配 //AT91C_BASE_PMC->PMC_PCER = 0x000000C0; *AT91C_CKGR_MOR=0x701; //使能主振荡器和设置起振时间 *AT91C_PMC_SCER=AT91C_CKGR_MOSCEN;//使能系统时钟寄存器的处理时钟 *AT91C_PMC_PCER=(1<<AT91C_ID_PIOA)|(1<<AT91C_ID_SPI)|(1<<AT91C_ID_US0); AT91C_BASE_DBGU->DBGU_BRGR =0x00000001; AT91F_US_Configure((AT91PS_USART)AT91C_BASE_DBGU,main_clock,AT91C_US_ASYNC_MODE,baud_rate,time_guard); *AT91C_US0_CR=0x1ac; *AT91C_US0_MR=0x8c0; *AT91C_US0_BRGR=30; *AT91C_US0_CR=0x50; //初始化串口0, AT91F_US_EnableTx((AT91PS_USART)AT91C_BASE_DBGU); AT91F_US_EnableRx((AT91PS_USART)AT91C_BASE_DBGU); AT91F_Printk((AT91PS_USART)AT91C_BASE_DBGU,"serior 0 is ok
"); //以上都是串口设置作为调试用的
*AT91C_PIOA_PDR=(AT91C_PA12_MISO|AT91C_PA13_MOSI|AT91C_PA14_SPCK|AT91C_PA11_NPCS0|US_RXD_PIN|US_TXD_PIN);
*AT91C_PIOA_ASR=(AT91C_PA12_MISO|AT91C_PA13_MOSI|AT91C_PA14_SPCK|AT91C_PA11_NPCS0|US_RXD_PIN|US_TXD_PIN);
*AT91C_SPI_CR=AT91C_SPI_SPIEN|AT91C_SPI_LASTXFER; *AT91C_SPI_IDR=0x3ff; *AT91C_SPI_MR=(AT91C_SPI_MSTR|AT91C_SPI_PS_FIXED|0xe<<16|AT91C_SPI_FDIV|(127<<24)|AT91C_SPI_MODFDIS); //主机模式,不分频,固定片选0,禁止错误检测 *AT91C_SPI_CSR=(AT91C_SPI_NCPHA|AT91C_SPI_BITS_16|(255<<8)|AT91C_SPI_DLYBS|AT91C_SPI_DLYBCT); //16位数据,传输完成后片选保持,48M/12分频,传输前延时255,连续传输延时255 *AT91C_SPI_PTCR=AT91C_PDC_TXTEN|AT91C_PDC_RXTEN;//使能PDC方式
index=&txbuff[0];//给地址 in=&rxb[0]; for(k=0;k<158;k++) { *AT91C_SPI_TPR=(unsigned int)(index); *AT91C_SPI_TCR = 1; *AT91C_SPI_RPR = (unsigned int)in; *AT91C_SPI_RCR = 1; index++; while(!((*AT91C_SPI_SR)&0x00000030));//判断发送是否成功 *AT91C_SPI_CR |= AT91C_SPI_LASTXFER;;//片选置高 }//将TX全发送出去 AT91F_Printk((AT91PS_USART)AT91C_BASE_DBGU,"ok1"); index=&rxbuff[0]; for(k=0;k<5;k++) { *AT91C_SPI_TPR=(unsigned int)(index); *AT91C_SPI_TCR=1; *AT91C_SPI_RPR = (unsigned int)in; *AT91C_SPI_RCR = 1; index++; while(!((*AT91C_SPI_SR)&0x00000030)); *AT91C_SPI_CR |= AT91C_SPI_LASTXFER;;//片选置高 }//将RX全发送出去 AT91F_Printk((AT91PS_USART)AT91C_BASE_DBGU,"ok2"); index=&dsbuff[0]; for(k=0;k<2;k++) { *AT91C_SPI_TPR=(unsigned int)(index); *AT91C_SPI_TCR=1; *AT91C_SPI_RPR = (unsigned int)in; *AT91C_SPI_RCR = 1; index++; while(!((*AT91C_SPI_SR)&0x00000030)); *AT91C_SPI_CR |= AT91C_SPI_LASTXFER;//片选置高 }//将DS全发送出去 AT91F_Printk((AT91PS_USART)AT91C_BASE_DBGU,"ok3"); while(1); }
这是我用PDC方式写的程序,没有成功,但是我不用PDC方式,直接用SPI却可以
int main(void) {//初始化DB
uint i=0x80; AT91F_DBGU_CfgPIO();
*AT91C_CKGR_MOR=0x701; //使能主振荡器和设置起振时间 *AT91C_PMC_SCER=AT91C_CKGR_MOSCEN;//使能系统时钟寄存器的处理时钟 *AT91C_PMC_PCER=(1<<AT91C_ID_PIOA)|(1<<AT91C_ID_SPI); AT91C_BASE_DBGU->DBGU_BRGR =0x00000001; AT91F_US_Configure((AT91PS_USART)AT91C_BASE_DBGU,main_clock,AT91C_US_ASYNC_MODE,baud_rate,time_guard); //初始化串口0, AT91F_US_EnableTx((AT91PS_USART)AT91C_BASE_DBGU); AT91F_US_EnableRx((AT91PS_USART)AT91C_BASE_DBGU); AT91F_Printk((AT91PS_USART)AT91C_BASE_DBGU,"serior 0 is ok
"); //以上都是初始化串口做调试之用
*AT91C_PIOA_PDR=(AT91C_PA12_MISO|AT91C_PA13_MOSI|AT91C_PA14_SPCK|AT91C_PA11_NPCS0); //PIO使能引脚的外设功能 *AT91C_PIOA_ASR=(AT91C_PA12_MISO|AT91C_PA13_MOSI|AT91C_PA14_SPCK|AT91C_PA11_NPCS0); //外设A分配给SPI外设A功能 *AT91C_SPI_CR=AT91C_SPI_SPIEN|AT91C_SPI_LASTXFER; *AT91C_SPI_IDR=0x3ff;//允许SPI口 *AT91C_SPI_MR=(AT91C_SPI_MSTR|AT91C_SPI_PS_FIXED|0xe<<16|AT91C_SPI_FDIV|(127<<24)||AT91C_SPI_MODFDIS); //主机模式,不分频,固定片选0,禁止错误检测 *AT91C_SPI_CSR=(AT91C_SPI_NCPHA|AT91C_SPI_BITS_16|(255<<8)|AT91C_SPI_DLYBS|AT91C_SPI_DLYBCT); //16位数据,传输完成后片选保持,48M/12分频,传输前延时255,连续传输延时255 intdisplay1(); while(1) { send1(0xf880); send1(0xfa32); AT91F_Printk((AT91PS_USART)AT91C_BASE_DBGU,"ok000"); while(1); } } void send1(uint dat) {int a; while((*AT91C_SPI_SR&AT91C_SPI_TDRE)==0); *AT91C_SPI_TDR=dat&0xffff; while((*AT91C_SPI_SR&AT91C_SPI_TDRE)==0) {;} //等待数据发送完成 AT91F_Printk((AT91PS_USART)AT91C_BASE_DBGU,"0 is ok
"); a=*AT91C_SPI_RDR; *AT91C_SPI_CR |= AT91C_SPI_LASTXFER; } void intdisplay1(void) { uint i=0xf880,j=0xf8c0; for(;i<=0xf8a7;i++) { send1(i); AT91F_Printk((AT91PS_USART)AT91C_BASE_DBGU,"ok2"); send1(0xfa20); AT91F_Printk((AT91PS_USART)AT91C_BASE_DBGU,"ok4");
}
for(;j<=0xf8e7;j++) { send1(j); AT91F_Printk((AT91PS_USART)AT91C_BASE_DBGU,"ok5"); send1(0xfa20); AT91F_Printk((AT91PS_USART)AT91C_BASE_DBGU,"ok7"); } send1(0xf802);//将光标设置到DDRAM的00H地址 send1(0xf810); send1(0xf806);//输入模式设置,计数器的增加随DDRAM,移动禁止 send1(0xf80c);//显示关,光标关,闪烁关。 send1(0xf838);//显示设置2层,设置亮度大小100% } 同样的两个程序,只是用不用PDC的区别,但是我的LED在没有用PDC方式下显示出了想要的结果,而前个程序用PDC方式却没有出来结果,但是根据串口显示结果数据好象是发出去了。请各位帮个忙,这个困扰我好久了谢谢了,我用的芯片是at91sam7s128 |