这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » FPGA » 5409的McBSP配置成SPI口的小结

共2条 1/1 1 跳转至

5409的McBSP配置成SPI口的小结

工程师
2015-01-09 14:46:10     打赏

5409的McBSP配置成SPI口的小结


终于把5409的McBSP的配置搞清楚了!现在就把我做的写出来,也好让后来人在这方面少走弯路。
我的目标是将MCBSP配置成SPI兼容接口。 我采用MCBSP0。  
下面我把我用汇编写的McBSP的初始化程序给出来。已经调试通过了,但是可能还有不对的地方,请大家看了以后指正!
                            .include        "cpu_reg.inc"
                            .def            McBsp0Init
            McBsp0Init:                     
                            stm             #spcr10,spsa0   ;接收复位
                            stm             #0000h,spsd0    
                            
                            stm     #spcr20,spsa0   
                            stm     #0000h,spsd0    ;发送复位
                            rpt             #9
                            nop
                            STM             #spcr10,spsa0
                            STM             #1800h,spsd0    ;clkstp=11b
            *---------------------------PCR0------------------------------------ 
                       
                            stm             #pcr0,spsa0      
            ;CLKXP=0,CLKXM=1,FSXM=1,FSXP=1
                                            ;xx..............;RESERVED
                                            
            ;..0.............;XIOEN=0时,DS,FSX,CLKX配置为串行接口
                                            
            ;...0............;RIOEN=0时,DR,FSR,CLKR,CLKS配置为串行接口引脚
                                            
            ;....1...........;FSXM=1时,采样率发生器的帧同步模式位(SRGR2的FSGM位)决定帧同步信号
                                            
            ;.....0..........;FSRM=1,片内采样率发生器产生帧同步信号,FSR为输出引脚(除非SRGR的GSYNC=1)
                                            
            ;......1.........;在SPI模式下,CLKXM=1时,McBSP为主设备,并产生时钟(CLKX)
                                                                                 
               ;去驱动它的接收时钟(CLKR)和系统的SPI从设备的SCLK时钟
                                            ;.......1........;DLB=0时,
                                                                                 
               ;CLKRM=0,接收时钟由外部时钟驱动
                                                                                 
               ;CLKRM=1,接收时钟由内部采样率发生器驱动
                                                                             
            ;DLB=1时,
                                                                                 
               ;CLKRM=0,接收时钟由发送时钟驱动,CLKX的特性由PCR的CLKXM位
                                                                                 
               ;设定。CLKR引脚为高阻态
                                                                                 
               ;CLKRM=1,CLKR为由发送时钟(CLKX)驱动的输出引脚。CLKX的特性由PCR的CLKXM位
                                                                                 
               ;设定。
                                            ;........x.......;RESERVED,
                                            
            ;.........x......;CLKS引脚状态位。当CLKS被选作通用输入时,该位反映了CLKX引脚的值
                                            ;..........x.....;DX引脚状态位
                                            ;...........x....;DR引脚状态位
                                            ;............1...;帧同步脉冲FSX低电平有效
                                            ;.............0..;帧同步脉冲FSR低电平有效
                                            
            ;..............0.;发送时钟极性,CLKXP=0时,在CLKX的上升沿采样发送数据
                                            
            ;...............0;接收时钟极性,CLKRP=0时,在CLKR的上升沿采样发送数据
                            stm             #0b08h,spsd0
            *-------------------SRGR20-----------------------------------        
               
                            stm             #srgr20,spsa0
                                            
            ;0...............;GSYNC=0,采样率发生寄存器时钟(CLKG)自由运行
                                            
            ;.0..............;CLKSP=0,在CLKS的上升沿产生CLKG和FSG
                                            
            ;..1.............;CLKSM=1,采样率发生器时钟由CPU时钟驱动
                                            
            ;...0............;FSGM=0,当DXR复制到XSR而产生发送帧同步信号(FSX)
                                                                                 
               ;FSGM=0时,FPER和FWID均被忽略
                                            ;....xxxxxxxxxxxx;FPER,帧周期
                            stm             #2000h,spsd0    ;clksm=1,fsgm=0
            *--------------------SRGR10----------------------------------        
               
                            stm             #srgr10,spsa0   
            ;DSP时钟为60MHz,MBF200为12MHz
                                            ;xxxxxxxx........;FWID,帧宽度
                                            
;........00110000;CLKDV=48,采样率发生时钟除法器
                            stm             #0030h,spsd0    
            ;clkgdv=30h,SPI的时钟=DSP时钟/48
                                                                            
            ;=1MHz
                            nop
                            nop
            *----------------------RCR10----------------------------------       
               
                            stm             #rcr10,spsa0    
                                            ;x...............;RESERVED
                                            ;.0000000........;RFLEN1=0000000,每帧1字
                                            
;........100.....;RWDLEN1=100,每字24bit
                                            ;...........xxxxx;RESERVED
                            stm             #0080h,spsd0    
            *---------------------RCR20------------------------------------      
               
                            stm             #rcr20,spsa0
                                            ;0...............;RPHASE=0,单相帧
                                            ;.0000000........;RFLEN2=0000000,每帧1字
                                            
            ;........100.....;RWDLEN2=100,每个字24bit
                                            
            ;...........00...;RCOMPAND=00,无扩展,数据传送从最高位(msb)开始
                                            
            ;.............0..;RFIG=0,第一个后的接收帧同步脉冲重新启动数据传送
                                            ;..............01;RDATDLY=01,延迟一位数据
                            stm             #0081h,spsd0    ;rdatdly=01
            *-------------------------XCR10----------------------------------    
                       
                            stm             #xcr10,spsa0            ;发送
                                            ;x...............;reserved
                                            ;.0000000........;XFRLEN1=0000000,每帧1字
                                            
;........100.....;XWDLEN1=100,每字24bit
                                            ;...........XXXXX;RESERVED
                            stm             #0080h,spsd0    ;
            *-------------------------XCR20----------------------------------    
                       
                            stm             #xcr20,spsa0            ;发送
                                            ;0...............;XPHASE=0,单相帧
                                            ;.0000000........;XFLEN2=0000000,每帧1字
                                            
;........100.....;XWDLEN2=100,每字24bit
                                            
            ;...........00...;XCOMPAND=00,无扩展,数据传输从最高位(MSB)开始
                                            
            ;.............0..;SFIG=0,第一个后的发送帧同步脉冲重新启动数据传送
                                            ;..............01;XDATDLY=01,延迟一位数据
                            stm             #0081h,spsd0    
            *-----------------------SPCR20----------------------------------------
                            STM             #spcr20,spsa0
                            STM             #0040h,spsd0    ;grst=1         
                            rpt             #9
                            nop                                     ;等待
            *---------------------------SPCR10---------------------------------------
                            stm             #spcr10,spsa0   ;RINTM=10
                                            ;0...............;DLB=0,禁止循环返回
                                            
            ;.00.............;RJUST=00,DRR靠右对齐,高位补0
                                            
;...11...........;CLSTP=11,时钟停止模式,有延时
                                            ;.....xxx........;RESERVED
                                            ;........0.......;DXENA=0,DX使能关
                                            ;.........0......;ABIS=0,禁止ABIS模式
                                            
            ;..........10....;RINTM=10,接收中断RINT由一个新的帧同步信号产生
                                            ;............0...;RSYNCERR=0,无接收同步错误
                                            ;.............0..;RFULL=0,RBR没有出现上溢
                                            ;..............0.;RRDY=0,接收器没有准备好
                                            ;...............1;RRST=1,打开串口接收
                            stm     #9821h, spsd0   
                            rpt             #9
                            nop
            *----------------------------SPCR20----------------------------------
                            stm     #spcr20,spsa0   
                                            ;xxxxxx..........;RESERVED
                                            ;......0.........;FREE=1,时钟自由运行
                                            ;.......0........;SOFT=0,禁止SOFT模式
                                            
            ;........0.......;FRST=0,帧同步逻辑电路复位。采样率发生器不会产生帧同步信号FSG
                                            
            ;.........1......;GRST=1,采样率发生器从复位中退出。CLKG按照采样率发生寄存器
                                                                             
            ;(SRGR)中的编程值产生时钟信号
                                            
            ;..........10....;XINTM=10,发送中断XINT由一个新的帧同步信号产生
                                            
            ;............0...;XSYNCERR=0,无发送帧帧同步错误
                                            ;.............0..;XEMPTY=0,XSR为空
                                            ;..............0.;XRDY=0,发送器未准备好
                                            ;...............1;XRST=1,打开串口发送
                            stm     #0061h,spsd0    
                            rpt             #9
                            nop
                            stm             #spcr20,spsa0   ;FRST=1
                            orm             #0080h,spsd0
                            rpt             #6
                            nop
                            ret


高工
2015-01-28 23:10:22     打赏
2楼

赞一个,小经验就得多做小结,现在发现之前的很多成果都遗忘了,再次用到还是从零开始。


共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]