at91r40008,配置UART,发送数据正常,接收数据出现异常,详细见内
我用的是at91r40008,配置UART,发送数据正常,从超级终端向cpu写值的时候,在US_RHR寄存器有值,但是单步走的下一步的时候,程序就会进入异常中断,是
Undefhandler,死循环。我在写程序的时候将中断屏蔽掉,想着此cpu有PDC可以自己进行工作。不知道这样写是否正确,还有就是接收数据是不是一定得用到中断处理程序来做。谢谢,不吝赐教。
//* Define RXD and TXD as peripheral
//* Define PIOs to be controlled by peripherals
pio_pt-> pio_base-> PIO_PDR=0x600000; //配置PIO 寄存器使的TXD1 RXD1为串口
//* Reset receiver and transmitter 复位uart的Control Register
usart_pt-> usart_base-> US_CR = US_RSTRX | US_RSTTX | US_RXDIS |US_TXDIS ;
//* Clear Transmit and Receive Counters
usart_pt-> usart_base-> US_RCR = 0 ;
usart_pt-> usart_base-> US_TCR = 0 ;
//* Define the baud rate divisor register
usart_pt-> usart_base-> US_BRGR = speed ; 设置波特率cd的值
//* Define the USART mode
usart_pt-> usart_base-> US_MR = mode 设串口模式,8bits 1个wait 无奇偶校验位 异步 NORMAL模式
//* Write the Timeguard Register
usart_pt-> usart_base-> US_TTGR = timeguard ; 在这里设为0
usart_pt-> usart_base-> US_CR = US_RXEN | US_TXEN ; 使RX TX使能
// *发送数据
while(((usart_pt-> usart_base-> US_CSR)& US_TXRDY)==0) {}
usart_pt-> usart_base-> US_TPR=相应的地址;
usart_pt-> usart_base-> US_TCR=10;发送十个数
//这时候可以看到超级中终端上有正确的值
//*接收数据
while(((usart_pt-> usart_base-> US_CSR)&US_RXRDY)==0){}
usart_pt-> usart_base-> US_RPR=相应的地址;
usart_pt-> usart_base-> US_RCR=10;接收从超级终端来的十个数
在这个时候输入十个数,能看到US_RHR中和相应的地址空间有值,但是
在单步执行下面的操作的时候就会进入异常中断
不知道是不是需要在接收的时候需要中断来进行处理。本人刚开始工作,一些问题可能很弱。还请大侠帮忙看一下。
如果有例程,还希望能贴出来交流一下。
联系方式zhang2972@sohu.com
发表时间:2003年5月23日20:50:45