当器件复位完成(RS=0)之后,串口初始化过程如下:(1)使SRCR[1,2]中的XRST=RRST=0(若由器件产生复位,则不需要该步);(2)编程McBSP配置寄存器(不编程数据寄存器);(3)等待2个位时钟,这样保证正确地内部同步;(4)根据需要时间遏制数据获取,如写DXR;(5)设置XRST=RRST=1使能串口(注意:这时写入SPCR[1,2]的值只能使复位位变成1,其他位域必须与第(2)步具有相同的值;(6)若需要内部产生帧同步,已知值FRST=1;(7)等待2个位时钟,接收器和发送器变有效。现以McBSP为例介绍串口的初始化过程,代码如下:
54x_init: ;CPU 初始化
STM #0b,CLKMD
TstStatu: LDM CLKMD,A
AND #01b,A
BC TstStatu,ANEQ
STM #9FF7h,CLKMD ;CPU 时钟频率.:100MHz
STM #00A0h,PMST
STM #8FFh,SWWSR ;IO 等待 7 个时钟
STM #8802h,BSCR ;输出时钟=50MHz
LD #0h,DP
LD #0h,A
LD #0h,B
RET
ser1_start:
STM SPCR11_SUBADDR,SPSA1
STM #0021h,SPSD1 ;串口接收使能
STM SPCR21_SUBADDR,SPSA1
STM #0201h,SPSD1 ;串口发送使能
STM RCR11_SUBADDR,SPSA1
STM #0040h,SPSD1 ;两字一帧和16位一字
STM RCR21_SUBADDR,SPSA1
STM #0000h,SPSD1 ;两字一帧和16位一字 STM XRC11_SUBADDR,SPSA1
STM #0040h,SPSD1 ;两字一帧和16位一字 STM XRC21_SUBADDR,SPSA1
STM #0000h,SPSD1 ;两字一帧和16位一字 STM SRGR11_SUBADDR,SPSA1
STM #0000h,SPSD1
STM SRGR21_SUBADDR,SPSA1
STM #0000h,SPSD1
STM MCR11_SUBADDR,SPSA1
STM #0000h,SPSD1 ;接收使用0—15
STM MCR21_SUBADDR,SPSA1
STM #0000h,SPSD1 ;发送使用0—15
STM PCR1_SUBADDR,SPSA1
STM #000Ch,SPSD1 ;串口接收时钟
RET
|